From 3eba71e7a0e736b1da93f390d861c51daff18f6b Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Wed, 11 Sep 2024 10:56:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/Editor.go | 15 ++++++--------- utils/replace.go | 4 ++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/api/controller/Editor.go b/api/controller/Editor.go index 31f1ab9..c01308b 100644 --- a/api/controller/Editor.go +++ b/api/controller/Editor.go @@ -80,15 +80,12 @@ func (b *Editor) EditorUpload(c *gin.Context) { return } - fileType := c.PostForm("type") - if fileType == "" { - responses.FailWithMessage("缺少参数", c) - return - } - - fileType = utils.GetExtension(fileType) - if fileType == "" { - fileType = "jpg" + fileType := "jpg" + if file.Filename != "" { + fileType = utils.GetExtension(fileType) + if fileType == "" { + fileType = "jpg" + } } now := time.Now() diff --git a/utils/replace.go b/utils/replace.go index ee4acd3..60c7d98 100644 --- a/utils/replace.go +++ b/utils/replace.go @@ -21,10 +21,10 @@ func AddOssDomain(url string) string { return config.C.Oss.OssCustomDomainName + url } -// GetExtension 解析并返回字符串中 `/` 后面的部分 +// GetExtension 解析并返回字符串中 `.` 后面的部分 func GetExtension(s string) string { // 使用 strings.Split 分割字符串 - parts := strings.Split(s, "/") + parts := strings.Split(s, ".") if len(parts) > 1 { return parts[1] // 返回第二部分 }