feat(skills): 场景预设 - 提供公开只读目录并校验内置技能引用 (#603)
This commit is contained in:
@@ -22,6 +22,7 @@ func TestRegisterCanvasAPIExposesOpenAPIAndProjects(t *testing.T) {
|
||||
"POST /api/tasks": false,
|
||||
"POST /api/tasks/:id/recover-media": false,
|
||||
"GET /api/resources": false,
|
||||
"GET /api/skills/presets": false,
|
||||
}
|
||||
for _, route := range router.Routes() {
|
||||
key := route.Method + " " + route.Path
|
||||
@@ -40,4 +41,10 @@ func TestRegisterCanvasAPIExposesOpenAPIAndProjects(t *testing.T) {
|
||||
if recorder.Code != http.StatusOK || !strings.Contains(recorder.Body.String(), "openapi: 3.0.3") || !strings.Contains(recorder.Body.String(), "url: /api") {
|
||||
t.Fatalf("openapi.yaml status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
|
||||
recorder = httptest.NewRecorder()
|
||||
router.ServeHTTP(recorder, httptest.NewRequest(http.MethodGet, "/api/skills/presets", nil))
|
||||
if recorder.Code != http.StatusOK || !strings.Contains(recorder.Body.String(), `"presets"`) {
|
||||
t.Fatalf("skills presets status=%d body=%s", recorder.Code, recorder.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,6 +114,15 @@ paths:
|
||||
"200": {description: 标准信封 data 为完整工具}
|
||||
"400": {description: 参数无效或预览资源不符合要求}
|
||||
"401": {description: 未登录}
|
||||
/skills/presets:
|
||||
get:
|
||||
tags: [canvas]
|
||||
security: []
|
||||
summary: 获取公开场景技能预设目录
|
||||
responses:
|
||||
"200":
|
||||
description: 标准信封 data 为 presets 数组;预设只引用公开且启用的种子技能
|
||||
"500": {$ref: "#/components/responses/Error"}
|
||||
/tools/{id}:
|
||||
parameters:
|
||||
- {in: path, name: id, required: true, schema: {type: integer, format: int64, minimum: 1}}
|
||||
|
||||
@@ -91,6 +91,16 @@ func RegisterSkillRoutes(r *gin.RouterGroup, svc *service.Service) {
|
||||
ok(c, result)
|
||||
})
|
||||
|
||||
r.GET("/skills/presets", func(c *gin.Context) {
|
||||
// 场景预设目录:公开只读的市场元数据(与 /openapi.yaml 同模式,无用户数据)。
|
||||
presets, err := svc.SkillPresets()
|
||||
if err != nil {
|
||||
failService(c, err)
|
||||
return
|
||||
}
|
||||
ok(c, gin.H{"presets": presets})
|
||||
})
|
||||
|
||||
r.GET("/skills/added", func(c *gin.Context) {
|
||||
user, err := currentUser(c, svc)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user