🎨 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:42:18 +08:00
parent aac7647ff5
commit bebf8c8e9b
No known key found for this signature in database
GPG key ID: 86211BA83DF03017

View file

@ -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")