🎨 Improve detection of duplicate insertion of assets https://github.com/siyuan-note/siyuan/issues/16220

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-10-28 11:01:12 +08:00
parent 920f7e4623
commit 2567526672
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 75 additions and 9 deletions

50
kernel/cache/asset.go vendored
View file

@ -28,14 +28,60 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
type AssetHash struct {
Hash string `json:"hash"`
Path string `json:"path"`
}
var (
assetHashCache = map[string]*AssetHash{}
assetHashLock = sync.Mutex{}
)
func RemoveAssetHash(hash string) {
assetHashLock.Lock()
defer assetHashLock.Unlock()
delete(assetHashCache, hash)
}
func SetAssetHash(hash, path string) {
assetHashLock.Lock()
defer assetHashLock.Unlock()
assetHashCache[hash] = &AssetHash{
Hash: hash,
Path: path,
}
}
func GetAssetHash(hash string) *AssetHash {
assetHashLock.Lock()
defer assetHashLock.Unlock()
for _, a := range assetHashCache {
if a.Hash == hash {
if filelock.IsExist(filepath.Join(util.DataDir, a.Path)) {
return a
}
delete(assetHashCache, hash)
return nil
}
}
return nil
}
type Asset struct {
HName string `json:"hName"`
Path string `json:"path"`
Updated int64 `json:"updated"`
}
var assetsCache = map[string]*Asset{}
var assetsLock = sync.Mutex{}
var (
assetsCache = map[string]*Asset{}
assetsLock = sync.Mutex{}
)
func GetAssets() (ret map[string]*Asset) {
assetsLock.Lock()