🎨 改进 网络图片转换为本地图片 文件名后缀 Fix https://github.com/siyuan-note/siyuan/issues/5053

This commit is contained in:
Liang Ding 2022-05-30 18:02:12 +08:00
parent c57014c12e
commit a43c5c5b40
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 231 additions and 9 deletions

View file

@ -34,6 +34,7 @@ import (
"github.com/88250/gulu"
"github.com/88250/lute/ast"
"github.com/88250/lute/parse"
"github.com/gabriel-vasile/mimetype"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/search"
"github.com/siyuan-note/siyuan/kernel/sql"
@ -116,6 +117,11 @@ func NetImg2LocalAssets(rootID string) (err error) {
}
name, _ = url.PathUnescape(name)
ext := path.Ext(name)
if "" == ext {
if mtype := mimetype.Detect(data); nil != mtype {
ext = mtype.Extension()
}
}
if "" == ext {
contentType := resp.Header.Get("Content-Type")
exts, _ := mime.ExtensionsByType(contentType)