diff --git a/apps/system/router/upload.go b/apps/system/router/upload.go index 1c81880..5fb146b 100644 --- a/apps/system/router/upload.go +++ b/apps/system/router/upload.go @@ -14,11 +14,12 @@ func InitUploadRouter(container *restful.Container) { ws.Path("/upload").Produces(restful.MIME_JSON) tags := []string{"system", "文件"} - ws.Route(ws.POST("/up").To(func(request *restful.Request, response *restful.Response) { + ws.Route(ws.POST("/up/{path}").To(func(request *restful.Request, response *restful.Response) { restfulx.NewReqCtx(request, response).WithLog("上传图片").Handle(s.UploadImage) }). Doc("上传图片"). Param(ws.FormParameter("imagefile", "文件")). + Param(ws.PathParameter("path", "文件类型")). Metadata(restfulspec.KeyOpenAPITags, tags). Returns(200, "OK", map[string]string{})) @@ -30,7 +31,7 @@ func InitUploadRouter(container *restful.Container) { Metadata(restfulspec.KeyOpenAPITags, tags). Returns(200, "OK", map[string]string{})) - ws.Route(ws.GET("/get/{subpath}").To(func(request *restful.Request, response *restful.Response) { + ws.Route(ws.GET("/down/{path}/{subpath:*}").To(func(request *restful.Request, response *restful.Response) { restfulx.NewReqCtx(request, response).WithNeedToken(false).WithNeedCasbin(false).WithLog("获取文件").Handle(s.GetImage) }). Doc("获取文件"). diff --git a/pkg/rule_engine.zip b/pkg/rule_engine.zip new file mode 100644 index 0000000..6200afc Binary files /dev/null and b/pkg/rule_engine.zip differ diff --git a/pkg/tool/file.go b/pkg/tool/file.go index 9d21964..f2e1ee9 100644 --- a/pkg/tool/file.go +++ b/pkg/tool/file.go @@ -11,6 +11,7 @@ import ( "os" "pandax/pkg/global" "path" + "regexp" "strings" "time" ) @@ -94,12 +95,20 @@ func (local *Local) UploadFile(file *multipart.FileHeader) (string, string, erro } func (local *Local) Base64ToFile(name, base64Str string) (path string, fileName string, err error) { + fileType := "jpg" if strings.Contains(base64Str, "data:image") { - base64Str = strings.TrimPrefix(base64Str, "data:image/png;base64,") + re := regexp.MustCompile(`^data:image/(\w+);base64,?`) + matchedString := re.FindStringSubmatch(base64Str) + global.Log.Info("re", matchedString) + if len(matchedString) <= 1 { + return "", "", errors.New("文件Base64格式错误") + } + base64Str = strings.TrimPrefix(base64Str, matchedString[0]) + fileType = matchedString[1] } imgData, err := base64.StdEncoding.DecodeString(base64Str) - filename := name + ".png" + filename := name + "." + fileType path = local.Path + "/" + filename _, err = os.Stat(path) if err == nil {