🎨 Image OCR supports setting the timeout via the environment variable SIYUAN_TESSERACT_TIMEOUT https://github.com/siyuan-note/siyuan/issues/16419

Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
Daniel 2025-11-22 14:43:03 +08:00
parent bebf8c8e9b
commit a5a82795ad
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -19,6 +19,7 @@ package util
import ( import (
"bytes" "bytes"
"context" "context"
"errors"
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
@ -249,8 +250,8 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) {
cmd := exec.CommandContext(ctx, TesseractBin, "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"), "tsv") cmd := exec.CommandContext(ctx, TesseractBin, "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"), "tsv")
gulu.CmdAttr(cmd) gulu.CmdAttr(cmd)
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()
if ctx.Err() == context.DeadlineExceeded { if errors.Is(ctx.Err(), context.DeadlineExceeded) {
logging.LogWarnf("tesseract [path=%s, size=%d] timeout", imgAbsPath, info.Size()) logging.LogWarnf("tesseract [path=%s, size=%d] timeout [%dms]", imgAbsPath, info.Size(), timeout)
return return
} }