mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 22:50:13 +01:00
This commit is contained in:
parent
3ffc32d089
commit
540c81995e
1 changed files with 17 additions and 3 deletions
|
|
@ -29,6 +29,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/88250/gulu"
|
"github.com/88250/gulu"
|
||||||
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/siyuan-note/filelock"
|
"github.com/siyuan-note/filelock"
|
||||||
"github.com/siyuan-note/logging"
|
"github.com/siyuan-note/logging"
|
||||||
)
|
)
|
||||||
|
|
@ -317,11 +318,24 @@ var (
|
||||||
SiYuanAssetsVideo = []string{".mov", ".weba", ".mkv", ".mp4", ".webm"}
|
SiYuanAssetsVideo = []string{".mov", ".weba", ".mkv", ".mp4", ".webm"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func IsAssetsImage(p string) bool {
|
func IsAssetsImage(assetPath string) bool {
|
||||||
ext := strings.ToLower(filepath.Ext(p))
|
ext := strings.ToLower(filepath.Ext(assetPath))
|
||||||
if "" == ext {
|
if "" == ext {
|
||||||
|
absPath := filepath.Join(DataDir, assetPath)
|
||||||
|
f, err := filelock.OpenFile(absPath, os.O_RDONLY, 0644)
|
||||||
|
if err != nil {
|
||||||
|
logging.LogErrorf("open file [%s] failed: %s", absPath, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
defer filelock.CloseFile(f)
|
||||||
|
m, err := mimetype.DetectReader(f)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogWarnf("detect file [%s] mimetype failed: %v", absPath, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
ext = m.Extension()
|
||||||
|
}
|
||||||
return gulu.Str.Contains(ext, SiYuanAssetsImage)
|
return gulu.Str.Contains(ext, SiYuanAssetsImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue