mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-04 07:48:49 +01:00
🎨 Improve assets rename https://github.com/siyuan-note/siyuan/issues/12497
This commit is contained in:
parent
aab6131945
commit
258d55b41f
12 changed files with 45 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue