🎨 Update av asset clean
This commit is contained in:
parent
f588996be0
commit
557ab7411f
1 changed files with 31 additions and 0 deletions
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue