mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-02 05:31:47 +01:00
🎨 Remove the check for !TesseractEnabled when saving OCR recognition results (#11708)
* 去除保存ocr识别结果时对 !TesseractEnabled 的检测 * 🐛 https://github.com/siyuan-note/siyuan/issues/11709 * https://github.com/siyuan-note/siyuan/pull/11708 修改ocr相关接口 * https://github.com/siyuan-note/siyuan/pull/11708 修改前端相关代码 * Update router.go * Update router.go --------- Co-authored-by: Vanessa <lly219@gmail.com>
This commit is contained in:
parent
6efa948859
commit
b590091c9e
5 changed files with 38 additions and 18 deletions
|
|
@ -107,13 +107,9 @@ func getImageOCRText(c *gin.Context) {
|
|||
}
|
||||
|
||||
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),
|
||||
"text": util.GetAssetText(path),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -131,6 +127,26 @@ func setImageOCRText(c *gin.Context) {
|
|||
util.SetAssetText(path, text)
|
||||
}
|
||||
|
||||
func ocr(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.OcrAsset(path, force),
|
||||
}
|
||||
}
|
||||
|
||||
func renameAsset(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -266,6 +266,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/asset/renameAsset", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, renameAsset)
|
||||
ginServer.Handle("POST", "/api/asset/getImageOCRText", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, getImageOCRText)
|
||||
ginServer.Handle("POST", "/api/asset/setImageOCRText", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setImageOCRText)
|
||||
ginServer.Handle("POST", "/api/asset/ocr", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, ocr)
|
||||
ginServer.Handle("POST", "/api/asset/fullReindexAssetContent", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, fullReindexAssetContent)
|
||||
ginServer.Handle("POST", "/api/asset/statAsset", model.CheckAuth, model.CheckAdminRole, statAsset)
|
||||
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ func nodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi
|
|||
var linkDestStr, ocrText string
|
||||
if nil != linkDest {
|
||||
linkDestStr = linkDest.TokensStr()
|
||||
ocrText = util.GetAssetText(linkDestStr, false)
|
||||
ocrText = util.OcrAsset(linkDestStr, false)
|
||||
}
|
||||
|
||||
linkText := n.ChildByType(ast.NodeLinkText)
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ func LoadAssetsTexts() {
|
|||
}
|
||||
|
||||
func SaveAssetsTexts() {
|
||||
if !assetsTextsChanged.Load() || !TesseractEnabled {
|
||||
if !assetsTextsChanged.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ func ExistsAssetText(asset string) (ret bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func GetAssetText(asset string, force bool) (ret string) {
|
||||
func OcrAsset(asset string, force bool) (ret string) {
|
||||
if !force {
|
||||
assetsTextsLock.Lock()
|
||||
ret = assetsTexts[asset]
|
||||
|
|
@ -170,6 +170,12 @@ func GetAssetText(asset string, force bool) (ret string) {
|
|||
return
|
||||
}
|
||||
|
||||
// https://github.com/siyuan-note/siyuan/pull/11708
|
||||
func GetAssetText(asset string) (ret string) {
|
||||
ret = assetsTexts[asset]
|
||||
return
|
||||
}
|
||||
|
||||
func IsTesseractExtractable(p string) bool {
|
||||
lowerName := strings.ToLower(p)
|
||||
return strings.HasSuffix(lowerName, ".png") || strings.HasSuffix(lowerName, ".jpg") || strings.HasSuffix(lowerName, ".jpeg")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue