|
@@ -8,6 +8,8 @@ import (
|
|
|
"file_upload/simple_zap"
|
|
|
"github.com/bytedance/sonic"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
+ "github.com/go-playground/validator/v10"
|
|
|
+ "go.uber.org/zap"
|
|
|
)
|
|
|
|
|
|
type Body struct {
|
|
@@ -159,6 +161,8 @@ func GetTemplate(c *gin.Context) {
|
|
|
}
|
|
|
e.ResponseSuccess(c, result)
|
|
|
}
|
|
|
+
|
|
|
+// DeleteTemplate 删除模板
|
|
|
func DeleteTemplate(c *gin.Context) {
|
|
|
name := c.Query("name")
|
|
|
if name == "" {
|
|
@@ -173,33 +177,34 @@ func DeleteTemplate(c *gin.Context) {
|
|
|
}
|
|
|
e.ResponseSuccess(c, e.SUCCESS)
|
|
|
}
|
|
|
-
|
|
|
-//// SaveUsernameToLocalStorage 保存用户名到本地
|
|
|
-//func SaveUsernameToLocalStorage(c *gin.Context) {
|
|
|
-// usernam := c.PostForm("username")
|
|
|
-// simple_zap.WithCtx(context.Background()).Sugar().Info(usernam)
|
|
|
-// global.Rdb.Set(context.Background(), "username", usernam, 0)
|
|
|
-// e.ResponseSuccess(c, e.SUCCESS)
|
|
|
-//}
|
|
|
-//
|
|
|
-//// SerializedItems 保存素材到redis数据库
|
|
|
-//func SerializedItems(c *gin.Context) {
|
|
|
-// type Params struct {
|
|
|
-// Params string
|
|
|
-// }
|
|
|
-// serializedItem := Params{}
|
|
|
-// err := c.BindJSON(&serializedItem)
|
|
|
-// if err != nil {
|
|
|
-// simple_zap.WithCtx(context.Background()).Sugar().Warn("获取参数失败")
|
|
|
-// }
|
|
|
-// fmt.Println("serializedItems:", serializedItem.Params)
|
|
|
-// global.Rdb.Set(context.Background(), "serializedItems", serializedItem.Params, 0)
|
|
|
-// e.ResponseSuccess(c, e.SUCCESS)
|
|
|
-//}
|
|
|
-
|
|
|
-//// GetSerializedItems 从redis数据库获取素材信息
|
|
|
-//func GetSerializedItems(c *gin.Context) {
|
|
|
-// get := global.Rdb.Get(context.Background(), "serializedItems")
|
|
|
-// fmt.Println("GetserializedItems:", get.Val())
|
|
|
-// e.ResponseSuccess(c, get.Val())
|
|
|
-//}
|
|
|
+func SearchTemplate(c *gin.Context) {
|
|
|
+ query := c.Query("name")
|
|
|
+ validate := validator.New()
|
|
|
+ validate.Var("name", "required")
|
|
|
+ if query == "" {
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "参数错误")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ result, err := global.Rdb.Keys(context.Background(), "*"+query+"*").Result()
|
|
|
+ if err != nil {
|
|
|
+ simple_zap.Logger.Error("查询失败", zap.Error(err))
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "查询失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if len(result) == 0 {
|
|
|
+ simple_zap.Logger.Info("查询失败")
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "未找到文件")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m := make(map[string]any)
|
|
|
+ for _, v := range result {
|
|
|
+ re, err := global.Rdb.Get(context.Background(), v).Result()
|
|
|
+ if err != nil {
|
|
|
+ simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "获取文件失败")
|
|
|
+ e.ResponseWithMsg(c, e.ERROR, "获取文件失败")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ m[v] = re
|
|
|
+ }
|
|
|
+ e.ResponseSuccess(c, m)
|
|
|
+}
|