mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 /资源 支持搜索未索引的文件 https://github.com/siyuan-note/siyuan/issues/5416
This commit is contained in:
parent
6e02c3e930
commit
4a64f5592f
7 changed files with 96 additions and 33 deletions
59
kernel/cache/asset.go
vendored
Normal file
59
kernel/cache/asset.go
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
// SiYuan - Build Your Eternal Digital Garden
|
||||
// Copyright (c) 2020-present, b3log.org
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package cache
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
type Asset struct {
|
||||
HName string `json:"hName"`
|
||||
Path string `json:"path"`
|
||||
Updated int64 `json:"updated"`
|
||||
}
|
||||
|
||||
var Assets = sync.Map{}
|
||||
|
||||
func LoadAssets() {
|
||||
Assets = sync.Map{}
|
||||
assets := filepath.Join(util.DataDir, "assets")
|
||||
filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
if strings.HasPrefix(info.Name(), ".") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if strings.HasSuffix(info.Name(), ".sya") {
|
||||
return nil
|
||||
}
|
||||
|
||||
hName := util.RemoveID(info.Name())
|
||||
path = filepath.ToSlash(strings.TrimPrefix(path, util.DataDir))[1:]
|
||||
Assets.Store(path, &Asset{
|
||||
HName: hName,
|
||||
Path: path,
|
||||
Updated: info.ModTime().UnixMilli(),
|
||||
})
|
||||
return nil
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue