mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 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:
parent
920f7e4623
commit
2567526672
3 changed files with 75 additions and 9 deletions
50
kernel/cache/asset.go
vendored
50
kernel/cache/asset.go
vendored
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue