114 lines
3.0 KiB
Java
114 lines
3.0 KiB
Java
package tech.easyflow.manuagent.skill;
|
|
|
|
import java.security.Principal;
|
|
import java.util.List;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
/**
|
|
* 提供 Skill 导入、查看和启停接口。
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/api/skills")
|
|
public class SkillController {
|
|
|
|
private final SkillService skillService;
|
|
|
|
/**
|
|
* 创建 Skill 控制器。
|
|
*
|
|
* @param skillService Skill 服务
|
|
*/
|
|
public SkillController(SkillService skillService) {
|
|
this.skillService = skillService;
|
|
}
|
|
|
|
/**
|
|
* 列出 Skill。
|
|
*
|
|
* @return Skill 列表
|
|
*/
|
|
@GetMapping
|
|
public List<SkillService.SkillView> list() {
|
|
return skillService.list();
|
|
}
|
|
|
|
/**
|
|
* 读取 Skill 详情。
|
|
*
|
|
* @param name Skill 名称
|
|
* @return Skill 详情
|
|
*/
|
|
@GetMapping("/{name}")
|
|
public SkillService.SkillDetail get(@PathVariable String name) {
|
|
return skillService.require(name);
|
|
}
|
|
|
|
/**
|
|
* 读取一个文本资源。
|
|
*
|
|
* @param name Skill 名称
|
|
* @param path 资源路径
|
|
* @return 资源正文
|
|
*/
|
|
@GetMapping("/{name}/resource")
|
|
public String resource(@PathVariable String name, @RequestParam String path) {
|
|
return skillService.resource(name, path);
|
|
}
|
|
|
|
/**
|
|
* 导入 Skill ZIP。
|
|
*
|
|
* @param file ZIP 文件
|
|
* @param principal 当前用户
|
|
* @return 导入后的 Skill
|
|
*/
|
|
@PostMapping(path = "/import", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
@ResponseStatus(HttpStatus.CREATED)
|
|
public SkillService.SkillView importZip(@RequestParam MultipartFile file, Principal principal) {
|
|
return skillService.importZip(file, principal);
|
|
}
|
|
|
|
/**
|
|
* 启用 Skill。
|
|
*
|
|
* @param name Skill 名称
|
|
*/
|
|
@PostMapping("/{name}/enable")
|
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
public void enable(@PathVariable String name) {
|
|
skillService.setEnabled(name, true);
|
|
}
|
|
|
|
/**
|
|
* 停用 Skill。
|
|
*
|
|
* @param name Skill 名称
|
|
*/
|
|
@PostMapping("/{name}/disable")
|
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
public void disable(@PathVariable String name) {
|
|
skillService.setEnabled(name, false);
|
|
}
|
|
|
|
/**
|
|
* 删除用户导入 Skill。
|
|
*
|
|
* @param name Skill 名称
|
|
*/
|
|
@DeleteMapping("/{name}")
|
|
@ResponseStatus(HttpStatus.NO_CONTENT)
|
|
public void delete(@PathVariable String name) {
|
|
skillService.deleteImported(name);
|
|
}
|
|
}
|