about summary refs log tree commit diff
path: root/app/javascript/flavours/glitch
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2021-06-16 12:42:40 +0200
committerGitHub <noreply@github.com>2021-06-16 12:42:40 +0200
commita434f370f38ac66e05000545e36d7c696f4962d0 (patch)
tree7ca43e484bb6111c2f219adb47e11a4445e38917 /app/javascript/flavours/glitch
parentdb5baf3d1a93cbf6961f721205cff0beaf71bffd (diff)
parent6dd51448a6ba318d3007169c443f6613a0944eea (diff)
Merge pull request #1550 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours/glitch')
-rw-r--r--app/javascript/flavours/glitch/features/ui/components/focal_point_modal.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/features/ui/components/focal_point_modal.js b/app/javascript/flavours/glitch/features/ui/components/focal_point_modal.js
index 893e76585..b7ec63333 100644
--- a/app/javascript/flavours/glitch/features/ui/components/focal_point_modal.js
+++ b/app/javascript/flavours/glitch/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 });