diff options
author | Claire <claire.github-309c@sitedethib.com> | 2021-06-15 22:11:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-15 22:11:07 +0200 |
commit | 8428faa0859d86c97950084658498a2c25e26f15 (patch) | |
tree | 2e8fc546b94289e63e8a2c0454a8a25a5b67e7b9 | |
parent | ee91c8a3a16a81e36965006a5e168db4f4b5d454 (diff) |
Fix OCR failure when erroneous lang data is in cache (#16386)
Fixes #15472 If the Tesseract worker fails at any point, re-try with cache settings that overwrite the cache. It is difficult to catch more precise errors as those are pretty opaque and do not occur when loading lang data but when trying to detect text.
-rw-r--r-- | app/javascript/mastodon/features/ui/components/focal_point_modal.js | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/javascript/mastodon/features/ui/components/focal_point_modal.js b/app/javascript/mastodon/features/ui/components/focal_point_modal.js index 3457b7633..edeb281e9 100644 --- a/app/javascript/mastodon/features/ui/components/focal_point_modal.js +++ b/app/javascript/mastodon/features/ui/components/focal_point_modal.js @@ -219,6 +219,10 @@ class FocalPointModal extends ImmutablePureComponent { } handleTextDetection = () => { + this._detectText(); + } + + _detectText = (refreshCache = false) => { const { media } = this.props; this.setState({ detecting: true }); @@ -235,6 +239,7 @@ class FocalPointModal extends ImmutablePureComponent { this.setState({ ocrStatus: 'preparing', progress }); } }, + cacheMethod: refreshCache ? 'refresh' : 'write', }); let media_url = media.get('url'); @@ -247,14 +252,20 @@ class FocalPointModal extends ImmutablePureComponent { } } - (async () => { + return (async () => { await worker.load(); await worker.loadLanguage('eng'); await worker.initialize('eng'); const { data: { text } } = await worker.recognize(media_url); this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false }); await worker.terminate(); - })(); + })().catch((e) => { + if (refreshCache) { + throw e; + } else { + this._detectText(true); + } + }); }).catch((e) => { console.error(e); this.setState({ detecting: false }); |