mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +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"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
|
@ -317,10 +318,23 @@ var (
|
|||
SiYuanAssetsVideo = []string{".mov", ".weba", ".mkv", ".mp4", ".webm"}
|
||||
)
|
||||
|
||||
func IsAssetsImage(p string) bool {
|
||||
ext := strings.ToLower(filepath.Ext(p))
|
||||
func IsAssetsImage(assetPath string) bool {
|
||||
ext := strings.ToLower(filepath.Ext(assetPath))
|
||||
if "" == ext {
|
||||
return false
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue