]> cat aescling's git repositories - mastodon.git/commitdiff
[Glitch] Fix tesseract.js being part of the common chunk
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 15 Aug 2019 15:24:45 +0000 (17:24 +0200)
committerThibaut Girka <thib@sitedethib.com>
Mon, 19 Aug 2019 19:56:25 +0000 (21:56 +0200)
Port dfe60598899738250fc707db91048b871ab09282 to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
app/javascript/flavours/glitch/features/ui/components/focal_point_modal.js
app/javascript/flavours/glitch/util/async-components.js

index e5a0d029a2f4fc63dd57396dad67611a4c74b9dd..6dc47dca38805a40ef41eda1201e70f487fa5e2a 100644 (file)
@@ -10,11 +10,11 @@ import { FormattedMessage, defineMessages, injectIntl } from 'react-intl';
 import IconButton from 'flavours/glitch/components/icon_button';
 import Button from 'flavours/glitch/components/button';
 import Video from 'flavours/glitch/features/video';
-import { TesseractWorker } from 'tesseract.js';
 import Textarea from 'react-textarea-autosize';
 import UploadProgress from 'flavours/glitch/features/compose/components/upload_progress';
 import CharacterCounter from 'flavours/glitch/features/compose/components/character_counter';
 import { length } from 'stringz';
+import { Tesseract as fetchTesseract } from 'flavours/glitch/util/async-components';
 
 const messages = defineMessages({
   close: { id: 'lightbox.close', defaultMessage: 'Close' },
@@ -148,19 +148,21 @@ class FocalPointModal extends ImmutablePureComponent {
   handleTextDetection = () => {
     const { media } = this.props;
 
-    const worker = new TesseractWorker({
-      workerPath: `${assetHost}/packs/ocr/worker.min.js`,
-      corePath: `${assetHost}/packs/ocr/tesseract-core.wasm.js`,
-      langPath: `${assetHost}/ocr/lang-data`,
-    });
-
     this.setState({ detecting: true });
 
-    worker.recognize(media.get('url'))
-      .progress(({ progress }) => this.setState({ progress }))
-      .finally(() => worker.terminate())
-      .then(({ text }) => this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false }))
-      .catch(() => this.setState({ detecting: false }));
+    fetchTesseract().then(({ TesseractWorker }) => {
+      const worker = new TesseractWorker({
+        workerPath: `${assetHost}/packs/ocr/worker.min.js`,
+        corePath: `${assetHost}/packs/ocr/tesseract-core.wasm.js`,
+        langPath: `${assetHost}/ocr/lang-data`,
+      });
+
+      worker.recognize(media.get('url'))
+        .progress(({ progress }) => this.setState({ progress }))
+        .finally(() => worker.terminate())
+        .then(({ text }) => this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false }))
+        .catch(() => this.setState({ detecting: false }));
+    }).catch(() => this.setState({ detecting: false }));
   }
 
   render () {
index f2aeda834b01768251641d9dfb7cf49e1e0e8110..8f2e4c6e41c90e2d50bcc28dbdf614c9782530b0 100644 (file)
@@ -153,3 +153,7 @@ export function ListAdder () {
 export function Search () {
   return import(/*webpackChunkName: "features/glitch/async/search" */'flavours/glitch/features/search');
 }
+
+export function Tesseract () {
+  return import(/*webpackChunkName: "tesseract" */'tesseract.js');
+}