An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Add OCR-related operations to the picture menu https://github.com/siyuan-note/siyuan/issues/7203
Liang Ding9461cc3f9570
diff --git a/kernel/api/asset.go b/kernel/api/asset.goindex 17ac70be75..9e1d94220e 100644--- a/kernel/api/asset.go+++ b/kernel/api/asset.go@@ -29,6 +29,40 @@ import ("github.com/siyuan-note/siyuan/kernel/util")+func getImageOCRText(c *gin.Context) {+ ret := gulu.Ret.NewResult()+ defer c.JSON(http.StatusOK, ret)++ arg, ok := util.JsonArg(c, ret)+ if !ok {+ return+ }++ path := arg["path"].(string)+ force := false+ if forceArg := arg["force"]; nil != forceArg {+ force = forceArg.(bool)+ }++ ret.Data = map[string]interface{}{+ "text": util.GetAssetText(path, force),+ }+}++func setImageOCRText(c *gin.Context) {+ ret := gulu.Ret.NewResult()+ defer c.JSON(http.StatusOK, ret)++ arg, ok := util.JsonArg(c, ret)+ if !ok {+ return+ }++ path := arg["path"].(string)+ text := arg["text"].(string)+ util.SetAssetText(path, text)+}+func renameAsset(c *gin.Context) {ret := gulu.Ret.NewResult()defer c.JSON(http.StatusOK, ret)diff --git a/kernel/api/router.go b/kernel/api/router.goindex 8d7e4cf6f3..2fc9463866 100644--- a/kernel/api/router.go+++ b/kernel/api/router.go@@ -226,6 +226,8 @@ func ServeAPI(ginServer *gin.Engine) {ginServer.Handle("POST", "/api/asset/removeUnusedAssets", model.CheckAuth, model.CheckReadonly, removeUnusedAssets)ginServer.Handle("POST", "/api/asset/getDocImageAssets", model.CheckAuth, model.CheckReadonly, getDocImageAssets)ginServer.Handle("POST", "/api/asset/renameAsset", model.CheckAuth, model.CheckReadonly, renameAsset)+ ginServer.Handle("POST", "/api/asset/getImageOCRText", model.CheckAuth, model.CheckReadonly, getImageOCRText)+ ginServer.Handle("POST", "/api/asset/setImageOCRText", model.CheckAuth, model.CheckReadonly, setImageOCRText)ginServer.Handle("POST", "/api/export/batchExportMd", model.CheckAuth, batchExportMd)ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, exportMd)diff --git a/kernel/util/tesseract.go b/kernel/util/tesseract.goindex abbe5d47c5..0e06e7bfc4 100644--- a/kernel/util/tesseract.go+++ b/kernel/util/tesseract.go@@ -44,21 +44,31 @@ var (TesseractLangs []string)-func GetAssetText(asset string) string {+func SetAssetText(asset, text string) {AssetsTextsLock.Lock()- ret, ok := AssetsTexts[asset]+ AssetsTexts[asset] = textAssetsTextsLock.Unlock()- if ok {- return ret+ AssetsTextsChanged = true+}++func GetAssetText(asset string, force bool) string {+ if !force {+ AssetsTextsLock.Lock()+ ret, ok := AssetsTexts[asset]+ AssetsTextsLock.Unlock()+ if ok {+ return ret+ }}assetsPath := GetDataAssetsAbsPath()assetAbsPath := strings.TrimPrefix(asset, "assets")assetAbsPath = filepath.Join(assetsPath, assetAbsPath)- ret = Tesseract(assetAbsPath)+ ret := Tesseract(assetAbsPath)AssetsTextsLock.Lock()AssetsTexts[asset] = retAssetsTextsLock.Unlock()+ AssetsTextsChanged = truereturn ret}