mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 题头图支持资源文件搜索 https://github.com/siyuan-note/siyuan/issues/9524
This commit is contained in:
parent
ed117fd577
commit
eba283d8b2
2 changed files with 25 additions and 2 deletions
|
|
@ -101,7 +101,15 @@ func searchAsset(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
k := arg["k"].(string)
|
k := arg["k"].(string)
|
||||||
ret.Data = model.SearchAssetsByName(k)
|
|
||||||
|
var exts []string
|
||||||
|
if extsArg := arg["exts"]; nil != extsArg {
|
||||||
|
for _, ext := range extsArg.([]interface{}) {
|
||||||
|
exts = append(exts, ext.(string))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ret.Data = model.SearchAssetsByName(k, exts)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,11 +220,26 @@ func NetImg2LocalAssets(rootID, originalURL string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func SearchAssetsByName(keyword string) (ret []*cache.Asset) {
|
func SearchAssetsByName(keyword string, exts []string) (ret []*cache.Asset) {
|
||||||
ret = []*cache.Asset{}
|
ret = []*cache.Asset{}
|
||||||
|
|
||||||
count := 0
|
count := 0
|
||||||
|
filterByExt := 0 < len(exts)
|
||||||
for _, asset := range cache.GetAssets() {
|
for _, asset := range cache.GetAssets() {
|
||||||
|
if filterByExt {
|
||||||
|
ext := filepath.Ext(asset.HName)
|
||||||
|
includeExt := false
|
||||||
|
for _, e := range exts {
|
||||||
|
if strings.ToLower(ext) == strings.ToLower(e) {
|
||||||
|
includeExt = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !includeExt {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !strings.Contains(strings.ToLower(asset.HName), strings.ToLower(keyword)) {
|
if !strings.Contains(strings.ToLower(asset.HName), strings.ToLower(keyword)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue