🎨 Update av asset clean

This commit is contained in:
Daniel 2023-09-26 11:16:40 +08:00
parent f588996be0
commit 557ab7411f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -663,6 +663,37 @@ func UnusedAssets() (ret []string) {
continue
}
}
// 排除数据库中引用的资源文件
storageAvDir := filepath.Join(util.DataDir, "storage", "av")
if gulu.File.IsDir(storageAvDir) {
entries, readErr := os.ReadDir(storageAvDir)
if nil != readErr {
logging.LogErrorf("read dir [%s] failed: %s", storageAvDir, readErr)
err = readErr
return
}
for _, entry := range entries {
if !strings.HasSuffix(entry.Name(), ".json") || !ast.IsNodeIDPattern(strings.TrimSuffix(entry.Name(), ".json")) {
continue
}
data, readDataErr := filelock.ReadFile(filepath.Join(util.DataDir, "storage", "av", entry.Name()))
if nil != readDataErr {
logging.LogErrorf("read file [%s] failed: %s", entry.Name(), readDataErr)
err = readDataErr
return
}
for asset, _ := range assetsPathMap {
if bytes.Contains(data, []byte(asset)) {
toRemoves = append(toRemoves, asset)
}
}
}
}
for _, toRemove := range toRemoves {
delete(assetsPathMap, toRemove)
}