package ai_text_to_image_ctrl import ( "91porn-server/app/service/ai_text_to_image_ser" "91porn-server/common" "91porn-server/common/log" "91porn-server/common/stderr" "fmt" "github.com/gin-gonic/gin" ) // List doc // // @Summary 获取AI绘图列表接口 // @Description 获取AI绘图列表 // @Tags 移动端-AI绘图列表 // @Accept mpfd,json // @Produce json // @Param q query ai_text_to_image_ser.AppQueryListReq false "请求参数" // @Success 200 object ai_text_to_image_ser.AppListRes "成功" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /api/app/ai/text_to_image/list [get] func List(ctx *gin.Context) { p := &ai_text_to_image_ser.AppQueryListReq{} if err := ctx.ShouldBind(&p); err != nil { common.ServeJSON(ctx, stderr.ErrParamError, nil) return } // 获取用户当前配置 var err error p.UID, err = common.GetUID(ctx) if err != nil { common.ServeJSON(ctx, stderr.ErrNoToken, err) return } list := p.GetList() common.ServeJSON(ctx, stderr.Success, list) } // Generate doc // @Summary 生成AI绘图订单记录 // @Description 生成AI绘图订单记录 // @Tags 移动端-AI绘图列表 // @Accept json // @Produce json // @Param q body ai_text_to_image_ser.GenerateReq false "请求参数" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /api/app/ai/text_to_image/generate [post] func Generate(ctx *gin.Context) { uid, err := common.GetUID(ctx) if err != nil { common.ServeJSON(ctx, stderr.ErrNoToken, err) return } in := ai_text_to_image_ser.GenerateReq{} if err = ctx.ShouldBind(&in); err != nil { log.Error(fmt.Sprintf("ai_text_to_image Generate param err:%v\n", err)) common.ServeJSON(ctx, stderr.ErrParamError, err) return } in.UID = uid ua, _ := common.GetUA(ctx) ip := common.GetIP(ctx) code, err := in.Generate(ua, ip) if err != nil { log.Error(fmt.Sprintf("ai_text_to_image Generate err:%v\n", err)) common.ServeJSON(ctx, code, err.Error()) return } common.ServeJSON(ctx, stderr.Success, stderr.Success.Msg()) } // Hide doc // @Summary 删除AI绘图记录 // @Description 删除AI绘图记录 // @Tags 移动端-AI绘图列表 // @Accept json // @Produce json // @Param q body ai_text_to_image_ser.HideReq false "请求参数" // @Success 200 {string} json "{"msg": "操作成功"}" // @Failure 400 {string} json "{"msg": "操作失败"}" // @Router /api/app/ai/text_to_image/hide [post] func Hide(ctx *gin.Context) { uid, err := common.GetUID(ctx) if err != nil { common.ServeJSON(ctx, stderr.ErrNoToken, err) return } in := ai_text_to_image_ser.HideReq{} if err = ctx.ShouldBind(&in); err != nil { log.Error(fmt.Sprintf("ai_text_to_image hide param err:%v\n", err)) common.ServeJSON(ctx, stderr.ErrParamError, err) return } in.UID = uid err = in.Hide() if err != nil { log.Error(fmt.Sprintf("ai_text_to_image hide err:%v\n", err)) if code, ok := err.(stderr.Code); ok { common.ServeJSON(ctx, code, code.Error()) return } common.ServeJSON(ctx, stderr.Failure, err) return } common.ServeJSON(ctx, stderr.Success, stderr.Success.Msg()) }