]> cat aescling's git repositories - mastodon.git/commitdiff
Use blob URL for Tesseract to avoid CORS issues (#11964)
authorThibG <thib@sitedethib.com>
Fri, 27 Sep 2019 00:16:11 +0000 (02:16 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Fri, 27 Sep 2019 00:16:11 +0000 (02:16 +0200)
app/javascript/mastodon/actions/compose.js
app/javascript/mastodon/features/ui/components/focal_point_modal.js
app/javascript/mastodon/reducers/compose.js

index 061a36bb8e75665171f201ceec9feab51042ecb7..79d64dc3e81a859e152c8282fe592d5a06249f6e 100644 (file)
@@ -234,7 +234,7 @@ export function uploadCompose(files) {
             progress[i] = loaded;
             dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
           },
-        }).then(({ data }) => dispatch(uploadComposeSuccess(data)));
+        }).then(({ data }) => dispatch(uploadComposeSuccess(data, f)));
       }).catch(error => dispatch(uploadComposeFail(error)));
     };
   };
@@ -289,10 +289,11 @@ export function uploadComposeProgress(loaded, total) {
   };
 };
 
-export function uploadComposeSuccess(media) {
+export function uploadComposeSuccess(media, file) {
   return {
     type: COMPOSE_UPLOAD_SUCCESS,
     media: media,
+    file: file,
     skipLoading: true,
   };
 };
index 7891d6690fec45af78a835069b83339f17fa017a..1ab79a21df2e60493d6199b09da0067c7861b931 100644 (file)
@@ -173,7 +173,17 @@ class FocalPointModal extends ImmutablePureComponent {
         langPath: `${assetHost}/ocr/lang-data`,
       });
 
-      worker.recognize(media.get('url'))
+      let media_url = media.get('file');
+
+      if (window.URL && URL.createObjectURL) {
+        try {
+          media_url = URL.createObjectURL(media.get('file'));
+        } catch (error) {
+          console.error(error);
+        }
+      }
+
+      worker.recognize(media_url)
         .progress(({ progress }) => this.setState({ progress }))
         .finally(() => worker.terminate())
         .then(({ text }) => this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false }))
index 268237846c63351251a5c44407ae9c1568720b91..5798f529dc30d6f5d61700697859e2c12d0dafa0 100644 (file)
@@ -103,11 +103,11 @@ function clearAll(state) {
   });
 };
 
-function appendMedia(state, media) {
+function appendMedia(state, media, file) {
   const prevSize = state.get('media_attachments').size;
 
   return state.withMutations(map => {
-    map.update('media_attachments', list => list.push(media));
+    map.update('media_attachments', list => list.push(media.set('file', file)));
     map.set('is_uploading', false);
     map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
     map.set('idempotencyKey', uuid());
@@ -321,7 +321,7 @@ export default function compose(state = initialState, action) {
   case COMPOSE_UPLOAD_REQUEST:
     return state.set('is_uploading', true);
   case COMPOSE_UPLOAD_SUCCESS:
-    return appendMedia(state, fromJS(action.media));
+    return appendMedia(state, fromJS(action.media), action.file);
   case COMPOSE_UPLOAD_FAIL:
     return state.set('is_uploading', false);
   case COMPOSE_UPLOAD_UNDO: