From aab6131945075fa65c35c588830bf834940c76f4 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Wed, 30 Oct 2024 23:17:29 +0800 Subject: [PATCH] :art: Improve asset rename ocr text https://github.com/siyuan-note/siyuan/issues/12974 --- kernel/model/assets.go | 6 ++++++ kernel/util/ocr.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/kernel/model/assets.go b/kernel/model/assets.go index dc6ae71f5..879463a0e 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -655,6 +655,12 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) { } } + if ocrText := util.GetAssetText(oldPath); "" != ocrText { + // 图片重命名后 ocr-texts.json 需要更新 https://github.com/siyuan-note/siyuan/issues/12974 + util.SetAssetText(newPath, ocrText) + util.RemoveAssetText(oldPath) + } + IncSync() return } diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index 83ecd96fc..cd4327106 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -164,12 +164,21 @@ func OcrAsset(asset string) (ret []map[string]interface{}) { return } -// https://github.com/siyuan-note/siyuan/pull/11708 func GetAssetText(asset string) (ret string) { + assetsTextsLock.Lock() ret = assetsTexts[asset] + assetsTextsLock.Unlock() + assetsTextsChanged.Store(true) return } +func RemoveAssetText(asset string) { + assetsTextsLock.Lock() + delete(assetsTexts, asset) + assetsTextsLock.Unlock() + assetsTextsChanged.Store(true) +} + func IsTesseractExtractable(p string) bool { lowerName := strings.ToLower(p) return strings.HasSuffix(lowerName, ".png") || strings.HasSuffix(lowerName, ".jpg") || strings.HasSuffix(lowerName, ".jpeg")