|
@@ -81,85 +81,6 @@ func SaveTemplate(c *gin.Context) {
|
|
|
e.ResponseSuccess(c, e.SUCCESS)
|
|
|
}
|
|
|
|
|
|
-//func SaveFile(c *gin.Context) {
|
|
|
-// // 解析请求体中的文件信息
|
|
|
-// file := Template{}
|
|
|
-// err := c.BindJSON(&file)
|
|
|
-// if err != nil {
|
|
|
-// // 日志记录参数解析失败
|
|
|
-// simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "获取参数失败")
|
|
|
-// // 返回参数解析失败的响应
|
|
|
-// e.ResponseWithMsg(c, e.JSONParsingFailed, e.JSONParsingFailed.GetMsg())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// // 检查文件是否已存在
|
|
|
-// filter := bson.M{"name": file.Name}
|
|
|
-// count, err := global.MongoCon.CountDocuments(context.TODO(), filter)
|
|
|
-// if err != nil {
|
|
|
-// // 日志记录查询失败
|
|
|
-// simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "查询文件是否存在失败")
|
|
|
-// // 返回错误响应
|
|
|
-// e.ResponseWithMsg(c, e.ERROR, e.ERROR.GetMsg())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// if count > 0 {
|
|
|
-// // 返回文件已存在的响应
|
|
|
-// e.ResponseWithMsg(c, e.AlreadyExists, e.AlreadyExists.GetMsg())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// var url string = "https://erp.baozhida.cn/assets/icon-91f5d92f.png"
|
|
|
-// m, ok := file.Data.(map[string]any)
|
|
|
-// if ok {
|
|
|
-// elements := m["elements"].([]any)
|
|
|
-// for _, v := range elements {
|
|
|
-// imageurl := v.(map[string]any)["url"]
|
|
|
-// if imageurl != nil {
|
|
|
-// _, data := utils.ParseBase64ImageString(imageurl.(string))
|
|
|
-// decodeString, err := base64.StdEncoding.DecodeString(data)
|
|
|
-// if err != nil {
|
|
|
-// simple_zap.WithCtx(context.TODO()).Sugar().Warn(err, "base64解码失败")
|
|
|
-// e.ResponseWithMsg(c, e.ERROR, "图片转换失败")
|
|
|
-// return
|
|
|
-// }
|
|
|
-// // 连接提取出的值
|
|
|
-// optputpath := "./upload" + "/" + file.Name + ".png"
|
|
|
-// create, err := os.Create(optputpath)
|
|
|
-// if err != nil {
|
|
|
-// simple_zap.WithCtx(context.TODO()).Sugar().Warn(err, "创建文件失败")
|
|
|
-// e.ResponseWithMsg(c, e.ERROR, "创建文件失败")
|
|
|
-// return
|
|
|
-// }
|
|
|
-// defer create.Close()
|
|
|
-// _, err = create.Write(decodeString)
|
|
|
-// if err != nil {
|
|
|
-// simple_zap.WithCtx(context.TODO()).Sugar().Warn(err, "写入文件失败")
|
|
|
-// e.ResponseWithMsg(c, e.ERROR, "写入文件失败")
|
|
|
-// return
|
|
|
-// }
|
|
|
-// // 提取所需字段值
|
|
|
-// url = "http://localhost:8080/download/" + file.Name + ".png"
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// doc := bson.M{
|
|
|
-// "name": file.Name,
|
|
|
-// "type": file.Type,
|
|
|
-// "data": file.Data,
|
|
|
-// "url": url,
|
|
|
-// }
|
|
|
-// // 保存文件到MongoDB
|
|
|
-// _, err = global.MongoCon.InsertOne(context.TODO(), doc)
|
|
|
-// if err != nil {
|
|
|
-// // 日志记录保存文件失败
|
|
|
-// simple_zap.WithCtx(context.Background()).Sugar().Warn(err, "保存文件失败")
|
|
|
-// // 返回保存文件失败的响应
|
|
|
-// e.ResponseWithMsg(c, e.ERROR, e.ERROR.GetMsg())
|
|
|
-// return
|
|
|
-// }
|
|
|
-// // 返回文件保存成功的响应
|
|
|
-// e.ResponseWithMsg(c, e.SUCCESS, url)
|
|
|
-//}
|
|
|
-
|
|
|
// TemplateItem 获取所有模板
|
|
|
func TemplateItem(c *gin.Context) {
|
|
|
type Types struct {
|
|
@@ -231,6 +152,7 @@ func DeleteTemplate(c *gin.Context) {
|
|
|
e.ResponseWithMsg(c, e.ERROR, "删除文件失败")
|
|
|
}
|
|
|
|
|
|
+// SearchTemplate 搜索模板
|
|
|
func SearchTemplate(c *gin.Context) {
|
|
|
query := c.Query("name")
|
|
|
validate := validator.New()
|
|
@@ -256,9 +178,12 @@ func SearchTemplate(c *gin.Context) {
|
|
|
err = cursor.All(context.Background(), &result)
|
|
|
e.ResponseSuccess(c, result)
|
|
|
}
|
|
|
+
|
|
|
+// GetImage 获得图片
|
|
|
func GetImage(c *gin.Context) {
|
|
|
- name := c.Query("name")
|
|
|
- if name == "" {
|
|
|
+ typs := c.Query("type")
|
|
|
+ name := c.Query("filename")
|
|
|
+ if name == "" || typs != "upload" {
|
|
|
e.ResponseWithMsg(c, e.ERROR, "参数错误")
|
|
|
return
|
|
|
}
|