This commit is contained in:
Daniel 2024-10-30 23:41:27 +08:00
parent aab6131945
commit 258d55b41f
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
12 changed files with 45 additions and 11 deletions

View file

@ -655,6 +655,40 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
}
}
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
}
if bytes.Contains(data, []byte(oldPath)) {
data = bytes.ReplaceAll(data, []byte(oldPath), []byte(newPath))
if writeDataErr := filelock.WriteFile(filepath.Join(util.DataDir, "storage", "av", entry.Name()), data); nil != writeDataErr {
logging.LogErrorf("write file [%s] failed: %s", entry.Name(), writeDataErr)
err = writeDataErr
return
}
}
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(entry.Name())))
}
}
if ocrText := util.GetAssetText(oldPath); "" != ocrText {
// 图片重命名后 ocr-texts.json 需要更新 https://github.com/siyuan-note/siyuan/issues/12974
util.SetAssetText(newPath, ocrText)