diff --git a/api/handler/admin/function_handler.go b/api/handler/admin/function_handler.go new file mode 100644 index 00000000..8eff4cbd --- /dev/null +++ b/api/handler/admin/function_handler.go @@ -0,0 +1,52 @@ +package admin + +import ( + "chatplus/core" + "chatplus/core/types" + "chatplus/handler" + "chatplus/store/model" + "chatplus/store/vo" + "chatplus/utils/resp" + "github.com/gin-gonic/gin" + "gorm.io/gorm" +) + +type FunctionHandler struct { + handler.BaseHandler + db *gorm.DB +} + +func NewFunctionHandler(app *core.AppServer, db *gorm.DB) *FunctionHandler { + h := FunctionHandler{db: db} + h.App = app + return &h +} + +func (h *FunctionHandler) Save(c *gin.Context) { + var data vo.Function + if err := c.ShouldBindJSON(&data); err != nil { + resp.ERROR(c, types.InvalidArgs) + return + } + + logger.Info(data) + resp.SUCCESS(c) +} + +func (h *FunctionHandler) List(c *gin.Context) { + + resp.SUCCESS(c) +} + +func (h *FunctionHandler) Remove(c *gin.Context) { + id := h.GetInt(c, "id", 0) + + if id > 0 { + res := h.db.Delete(&model.Function{Id: uint(id)}) + if res.Error != nil { + resp.ERROR(c, "更新数据库失败!") + return + } + } + resp.SUCCESS(c) +} diff --git a/api/handler/mj_handler.go b/api/handler/mj_handler.go index db4cb5e5..7b39aeed 100644 --- a/api/handler/mj_handler.go +++ b/api/handler/mj_handler.go @@ -146,6 +146,9 @@ func (h *MidJourneyHandler) Image(c *gin.Context) { Prompt: fmt.Sprintf("%s %s", taskId, prompt), UserId: userId, }) + + // update user's img calls + h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1)) resp.SUCCESS(c) } @@ -246,6 +249,9 @@ func (h *MidJourneyHandler) Variation(c *gin.Context) { MessageId: data.MessageId, MessageHash: data.MessageHash, }) + + // update user's img calls + h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1)) resp.SUCCESS(c) } diff --git a/api/handler/sd_handler.go b/api/handler/sd_handler.go index 553dba2b..b5515f9f 100644 --- a/api/handler/sd_handler.go +++ b/api/handler/sd_handler.go @@ -133,6 +133,9 @@ func (h *SdJobHandler) Image(c *gin.Context) { UserId: userId, }) + // update user's img calls + h.db.Model(&model.User{}).Where("id = ?", job.UserId).UpdateColumn("img_calls", gorm.Expr("img_calls - ?", 1)) + resp.SUCCESS(c) } @@ -177,8 +180,8 @@ func (h *SdJobHandler) JobList(c *gin.Context) { } if item.Progress < 100 { - // 10 分钟还没完成的任务直接删除 - if time.Now().Sub(item.CreatedAt) > time.Minute*10 { + // 5 分钟还没完成的任务直接删除 + if time.Now().Sub(item.CreatedAt) > time.Minute*5 { h.db.Delete(&item) continue } diff --git a/api/main.go b/api/main.go index 69ed1e83..c6e5b6bf 100644 --- a/api/main.go +++ b/api/main.go @@ -341,6 +341,14 @@ func main() { group.POST("translate", h.Translate) }), + fx.Provide(admin.NewFunctionHandler), + fx.Invoke(func(s *core.AppServer, h *admin.FunctionHandler) { + group := s.Engine.Group("/api/admin/function/") + group.POST("save", h.Save) + group.GET("list", h.List) + group.GET("remove", h.Remove) + }), + fx.Provide(handler.NewTestHandler), fx.Invoke(func(s *core.AppServer, h *handler.TestHandler) { group := s.Engine.Group("/test/") diff --git a/api/res/sd/text2img.json b/api/res/sd/text2img.json index 375c65c3..c15cc35e 100644 --- a/api/res/sd/text2img.json +++ b/api/res/sd/text2img.json @@ -1,24 +1,16 @@ { "data": [ - "task(vpu09bi42w01k5f)", - "A beautiful Chinese girl strolls along the beach", + "task(cxvkpawy8onnfti)", + "a cute girl", "", [], - 30, - "DPM++ 2M SDE Karras", - false, - false, + 20, + "DPM++ 2M Karras", 1, 1, 7, - -1, - -1, - 0, - 0, - 0, - false, - 1024, - 1024, + 512, + 512, false, 0.7, 2, @@ -26,11 +18,24 @@ 0, 0, 0, + "Use same checkpoint", "Use same sampler", "", "", [], "None", + false, + "", + 0.8, + -1, + false, + -1, + 0, + 0, + 0, + null, + null, + null, null, false, false, @@ -54,46 +59,22 @@ false, false, 0, - "Not set", - true, - true, - "", - "", - "", - "", - "", - 1.3, - "Not set", - "Not set", - 1.3, - "Not set", - 1.3, - "Not set", - 1.3, - 1.3, - "Not set", - 1.3, - "Not set", - 1.3, - "Not set", - 1.3, - "Not set", - 1.3, - "Not set", - 1.3, - "Not set", + null, + null, false, - "None", + null, + null, + false, + null, null, false, 50, - [ - ], - "{\"prompt\": \"A beautiful Chinese girl strolls along the beach\", \"all_prompts\": [\"A beautiful Chinese girl strolls along the beach\"], \"negative_prompt\": \"\", \"all_negative_prompts\": [\"\"], \"seed\": 291934632, \"all_seeds\": [291934632], \"subseed\": 2486830045, \"all_subseeds\": [2486830045], \"subseed_strength\": 0, \"width\": 1024, \"height\": 1024, \"sampler_name\": \"DPM++ 2M SDE Karras\", \"cfg_scale\": 7, \"steps\": 30, \"batch_size\": 1, \"restore_faces\": false, \"face_restoration_model\": null, \"sd_model_hash\": \"2a4411ef93\", \"seed_resize_from_w\": 0, \"seed_resize_from_h\": 0, \"denoising_strength\": null, \"extra_generation_params\": {}, \"index_of_first_image\": 0, \"infotexts\": [\"A beautiful Chinese girl strolls along the beach\\nSteps: 30, Sampler: DPM++ 2M SDE Karras, CFG scale: 7, Seed: 291934632, Size: 1024x1024, Model hash: 2a4411ef93, Model: sdxlUnstableDiffusers_v7ElectricMind, Version: v1.5.2\"], \"styles\": [], \"job_timestamp\": \"20231215222321\", \"clip_skip\": 1, \"is_using_inpainting_conditioning\": false}", - "
A beautiful Chinese girl strolls along the beach
\nSteps: 30, Sampler: DPM++ 2M SDE Karras, CFG scale: 7, Seed: 291934632, Size: 1024x1024, Model hash: 2a4411ef93, Model: sdxlUnstableDiffusers_v7ElectricMind, Version: v1.5.2
Time taken:
A: 10.26 GB,