From bebf8c8e9b3bbd0ee4e80649d62926e4b592e641 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Sat, 22 Nov 2025 14:42:18 +0800 Subject: [PATCH] :art: 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> --- kernel/util/ocr.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/kernel/util/ocr.go b/kernel/util/ocr.go index 040468b54..c3935212a 100644 --- a/kernel/util/ocr.go +++ b/kernel/util/ocr.go @@ -234,7 +234,16 @@ func Tesseract(imgAbsPath string) (ret []map[string]interface{}) { defer logging.Recover() - ctx, cancel := context.WithTimeout(context.Background(), 7*time.Second) + timeout := 7000 + timeoutEnv := os.Getenv("SIYUAN_TESSERACT_TIMEOUT") + if "" != timeoutEnv { + if timeoutParsed, parseErr := strconv.Atoi(timeoutEnv); nil == parseErr { + timeout = timeoutParsed + } else { + logging.LogWarnf("parse tesseract timeout [%s] failed: %s", timeoutEnv, parseErr) + } + } + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeout)*time.Millisecond) defer cancel() cmd := exec.CommandContext(ctx, TesseractBin, "-c", "debug_file=/dev/null", imgAbsPath, "stdout", "-l", strings.Join(TesseractLangs, "+"), "tsv")