]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Fix OCR failure when erroneous lang data is in cache
authorClaire <claire.github-309c@sitedethib.com>
Tue, 15 Jun 2021 20:11:07 +0000 (22:11 +0200)
committerClaire <claire.github-309c@sitedethib.com>
Wed, 16 Jun 2021 09:29:07 +0000 (11:29 +0200)
Port 8428faa0859d86c97950084658498a2c25e26f15 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
app/javascript/flavours/glitch/features/ui/components/focal_point_modal.js

index 893e76585601dee04f1bc39bb6bc6f054287ee03..b7ec63333c14d97ed12bd4494e92a8f783c2ebfd 100644 (file)
@@ -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 });