diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index e568b9174..520a7c8c1 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -52,7 +52,7 @@ Note: In the development environment, the kernel process will not be automatical ### Android * `cd kernel` -* `gomobile bind --tags fts5 -ldflags '-s -w' -v -o kernel.aar -target='android/arm,android/arm64' ./mobile/` +* `gomobile bind --tags fts5 -ldflags '-s -w' -v -o kernel.aar -target='android/arm64' ./mobile/` * https://github.com/siyuan-note/siyuan-android For the mobile-end, please refer to the corresponding project repository. diff --git a/.github/CONTRIBUTING_zh_CN.md b/.github/CONTRIBUTING_zh_CN.md index 38f1b18e8..5d947a9a0 100644 --- a/.github/CONTRIBUTING_zh_CN.md +++ b/.github/CONTRIBUTING_zh_CN.md @@ -52,7 +52,7 @@ NPM 镜像: ### Android -* `gomobile bind --tags fts5 -ldflags '-s -w' -v -o kernel.aar -target='android/arm,android/arm64' ./kernel/mobile/` +* `gomobile bind --tags fts5 -ldflags '-s -w' -v -o kernel.aar -target='android/arm64' ./kernel/mobile/` * https://github.com/siyuan-note/siyuan-android 移动端请参考对应项目仓库。 diff --git a/kernel/api/asset.go b/kernel/api/asset.go index 17ac70be7..9e1d94220 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.go index 8d7e4cf6f..2fc946386 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/treenode/node.go b/kernel/treenode/node.go index 65b0524ae..57710f269 100644 --- a/kernel/treenode/node.go +++ b/kernel/treenode/node.go @@ -172,7 +172,7 @@ func NodeStaticContent(node *ast.Node, excludeTypes []string, includeTextMarkATi var linkDestStr, ocrText string if nil != linkDest { linkDestStr = linkDest.TokensStr() - ocrText = util.GetAssetText(linkDestStr) + ocrText = util.GetAssetText(linkDestStr, false) } linkText := n.ChildByType(ast.NodeLinkText) diff --git a/kernel/util/tesseract.go b/kernel/util/tesseract.go index abbe5d47c..0e06e7bfc 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] = text AssetsTextsLock.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] = ret AssetsTextsLock.Unlock() + AssetsTextsChanged = true return ret } diff --git a/scripts/parse-changelog.py b/scripts/parse-changelog.py index 0b63c2b9c..3bbe1a3cc 100644 --- a/scripts/parse-changelog.py +++ b/scripts/parse-changelog.py @@ -3,8 +3,8 @@ import re from argparse import ArgumentParser from collections import defaultdict -import github - +import github # pip install PyGithub +# ensure the milestone is open before run this docmap = { "Feature": "Feature", "Enhancement": "Enhancement", @@ -35,7 +35,7 @@ def generate_msg_from_repo(repo_name, tag_name, lastestRelease): repo = gh.get_repo(repo_name) milestone = find_milestone(repo, tag_name, lastestRelease) - for issue in repo.get_issues(state="closed", milestone=milestone): + for issue in repo.get_issues(state="closed", milestone=milestone): # type: ignore # REF https://pygithub.readthedocs.io/en/latest/github_objects/Issue.html#github.Issue.Issue desc_mapping[get_issue_first_label(issue)].append( {"title": issue.title, "url": issue.html_url} diff --git a/scripts/win-build.bat b/scripts/win-build.bat index 91e7e34cf..1563a4052 100644 --- a/scripts/win-build.bat +++ b/scripts/win-build.bat @@ -1,3 +1,6 @@ +@echo off +echo 'use ".\scripts\win-build.bat" instead of "win-build.bat"' + echo 'Building UI' cd app call pnpm install @@ -9,16 +12,19 @@ del /S /Q /F app\build 1>nul del /S /Q /F app\kernel 1>nul echo 'Building Kernel' +@REM the C compiler "gcc" is necessary https://sourceforge.net/projects/mingw-w64/files/mingw-w64/ go version set GO111MODULE=on set GOPROXY=https://goproxy.io set CGO_ENABLED=1 cd kernel +@REM you can use `go generate` instead (nead add something in main.go) goversioninfo -platform-specific=true -icon=resource/icon.ico -manifest=resource/goversioninfo.exe.manifest set GOOS=windows set GOARCH=amd64 +@REM you can use `go mod tidy` to update kernel dependency bofore build go build --tags fts5 -v -o "../app/kernel/SiYuan-Kernel.exe" -ldflags "-s -w -H=windowsgui" . cd .. @@ -30,5 +36,7 @@ call pnpm run dist cd .. echo 'Building Appx' +echo 'Building Appx should be disabled if you do not need it. Not configured correctly will lead to build failures' cd . > app\build\win-unpacked\resources\ms-store electron-windows-store --input-directory app\build\win-unpacked --output-directory app\build\ --package-version 1.0.0.0 --package-name SiYuan --manifest app\appx\AppxManifest.xml --assets app\appx\assets\ --make-pri true +