🎨 改进浏览器剪藏扩展转换本地图片后缀 Fix https://github.com/siyuan-note/siyuan/issues/7467
This commit is contained in:
parent
2c4b38e24c
commit
1069d245af
1 changed files with 12 additions and 2 deletions
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/88250/lute"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
|
@ -80,7 +81,7 @@ func extensionCopy(c *gin.Context) {
|
|||
continue
|
||||
}
|
||||
fName := path.Base(u.Path)
|
||||
fName = util.FilterUploadFileName(fName)
|
||||
|
||||
f, err := file[0].Open()
|
||||
if nil != err {
|
||||
ret.Code = -1
|
||||
|
@ -96,10 +97,19 @@ func extensionCopy(c *gin.Context) {
|
|||
}
|
||||
|
||||
ext := path.Ext(fName)
|
||||
fName = fName[0 : len(fName)-len(ext)]
|
||||
originalExt := ext
|
||||
if "" == ext || strings.Contains(ext, "!") {
|
||||
// 改进浏览器剪藏扩展转换本地图片后缀 https://github.com/siyuan-note/siyuan/issues/7467
|
||||
if mtype := mimetype.Detect(data); nil != mtype {
|
||||
ext = mtype.Extension()
|
||||
}
|
||||
}
|
||||
if "" == ext && bytes.HasPrefix(data, []byte("<svg ")) && bytes.HasSuffix(data, []byte("</svg>")) {
|
||||
ext = ".svg"
|
||||
}
|
||||
|
||||
fName = fName[0 : len(fName)-len(originalExt)]
|
||||
fName = util.FilterUploadFileName(fName)
|
||||
fName = fName + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(assets, fName)
|
||||
if err = filelock.WriteFile(writePath, data); nil != err {
|
||||
|
|
Loading…
Add table
Reference in a new issue