03396a9d18
- 后端新增批量删除提示词接口和实现 - 前端管理页面添加多选和批量删除功能 - 添加定时同步GitHub远程提示词源功能 - 新增系统设置中的提示词同步配置选项 - 更新文档说明新的批量操作和定时同步功能 - 添加相关的测试用例和依赖库
75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
|
|
"github.com/basketikun/infinite-canvas/model"
|
|
"github.com/basketikun/infinite-canvas/service"
|
|
)
|
|
|
|
type adminSyncRequest struct {
|
|
Category string `json:"category"`
|
|
}
|
|
|
|
type adminBatchDeleteRequest struct {
|
|
IDs []string `json:"ids"`
|
|
}
|
|
|
|
func AdminPromptCategories(w http.ResponseWriter, r *http.Request) {
|
|
OK(w, service.ListPromptCategories())
|
|
}
|
|
|
|
func AdminPrompts(w http.ResponseWriter, r *http.Request) {
|
|
result, err := service.ListPrompts(parseQuery(r))
|
|
if err != nil {
|
|
FailError(w, err)
|
|
return
|
|
}
|
|
OK(w, result)
|
|
}
|
|
|
|
func AdminSavePrompt(w http.ResponseWriter, r *http.Request) {
|
|
var item model.Prompt
|
|
_ = json.NewDecoder(r.Body).Decode(&item)
|
|
result, err := service.SavePrompt(item)
|
|
if err != nil {
|
|
FailError(w, err)
|
|
return
|
|
}
|
|
OK(w, result)
|
|
}
|
|
|
|
func AdminDeletePrompt(w http.ResponseWriter, r *http.Request, id string) {
|
|
if err := service.DeletePrompt(id); err != nil {
|
|
FailError(w, err)
|
|
return
|
|
}
|
|
OK(w, true)
|
|
}
|
|
|
|
func AdminDeletePrompts(w http.ResponseWriter, r *http.Request) {
|
|
var request adminBatchDeleteRequest
|
|
_ = json.NewDecoder(r.Body).Decode(&request)
|
|
if err := service.DeletePrompts(request.IDs); err != nil {
|
|
FailError(w, err)
|
|
return
|
|
}
|
|
OK(w, true)
|
|
}
|
|
|
|
func AdminSyncPromptCategories(w http.ResponseWriter, r *http.Request) {
|
|
var request adminSyncRequest
|
|
_ = json.NewDecoder(r.Body).Decode(&request)
|
|
log.Printf("sync prompt category start category=%s", request.Category)
|
|
categories, err := service.SyncPromptCategory(request.Category)
|
|
if err != nil {
|
|
log.Printf("sync prompt category failed category=%s err=%v", request.Category, err)
|
|
FailError(w, err)
|
|
return
|
|
}
|
|
log.Printf("sync prompt category done category=%s", request.Category)
|
|
OK(w, categories)
|
|
}
|