mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 Add OCR-related operations to the picture menu https://github.com/siyuan-note/siyuan/issues/7203
This commit is contained in:
parent
c6b3083a24
commit
9461cc3f95
3 changed files with 51 additions and 5 deletions
|
|
@ -29,6 +29,40 @@ import (
|
||||||
"github.com/siyuan-note/siyuan/kernel/util"
|
"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) {
|
func renameAsset(c *gin.Context) {
|
||||||
ret := gulu.Ret.NewResult()
|
ret := gulu.Ret.NewResult()
|
||||||
defer c.JSON(http.StatusOK, ret)
|
defer c.JSON(http.StatusOK, ret)
|
||||||
|
|
|
||||||
|
|
@ -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/removeUnusedAssets", model.CheckAuth, model.CheckReadonly, removeUnusedAssets)
|
||||||
ginServer.Handle("POST", "/api/asset/getDocImageAssets", model.CheckAuth, model.CheckReadonly, getDocImageAssets)
|
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/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/batchExportMd", model.CheckAuth, batchExportMd)
|
||||||
ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, exportMd)
|
ginServer.Handle("POST", "/api/export/exportMd", model.CheckAuth, exportMd)
|
||||||
|
|
|
||||||
|
|
@ -44,21 +44,31 @@ var (
|
||||||
TesseractLangs []string
|
TesseractLangs []string
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetAssetText(asset string) string {
|
func SetAssetText(asset, text string) {
|
||||||
|
AssetsTextsLock.Lock()
|
||||||
|
AssetsTexts[asset] = text
|
||||||
|
AssetsTextsLock.Unlock()
|
||||||
|
AssetsTextsChanged = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAssetText(asset string, force bool) string {
|
||||||
|
if !force {
|
||||||
AssetsTextsLock.Lock()
|
AssetsTextsLock.Lock()
|
||||||
ret, ok := AssetsTexts[asset]
|
ret, ok := AssetsTexts[asset]
|
||||||
AssetsTextsLock.Unlock()
|
AssetsTextsLock.Unlock()
|
||||||
if ok {
|
if ok {
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assetsPath := GetDataAssetsAbsPath()
|
assetsPath := GetDataAssetsAbsPath()
|
||||||
assetAbsPath := strings.TrimPrefix(asset, "assets")
|
assetAbsPath := strings.TrimPrefix(asset, "assets")
|
||||||
assetAbsPath = filepath.Join(assetsPath, assetAbsPath)
|
assetAbsPath = filepath.Join(assetsPath, assetAbsPath)
|
||||||
ret = Tesseract(assetAbsPath)
|
ret := Tesseract(assetAbsPath)
|
||||||
AssetsTextsLock.Lock()
|
AssetsTextsLock.Lock()
|
||||||
AssetsTexts[asset] = ret
|
AssetsTexts[asset] = ret
|
||||||
AssetsTextsLock.Unlock()
|
AssetsTextsLock.Unlock()
|
||||||
|
AssetsTextsChanged = true
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue