[Glitch] Use blob URL for Tesseract to avoid CORS issues
Port 7baedcb61e
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
pull/1224/head
parent
4b7c436ae9
commit
74af56b9cd
|
@ -261,7 +261,7 @@ export function uploadCompose(files) {
|
||||||
progress[i] = loaded;
|
progress[i] = loaded;
|
||||||
dispatch(uploadComposeProgress(progress.reduce((a, v) => a + v, 0), total));
|
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)));
|
}).catch(error => dispatch(uploadComposeFail(error)));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@ -316,10 +316,11 @@ export function uploadComposeProgress(loaded, total) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function uploadComposeSuccess(media) {
|
export function uploadComposeSuccess(media, file) {
|
||||||
return {
|
return {
|
||||||
type: COMPOSE_UPLOAD_SUCCESS,
|
type: COMPOSE_UPLOAD_SUCCESS,
|
||||||
media: media,
|
media: media,
|
||||||
|
file: file,
|
||||||
skipLoading: true,
|
skipLoading: true,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -173,7 +173,17 @@ class FocalPointModal extends ImmutablePureComponent {
|
||||||
langPath: `${assetHost}/ocr/lang-data`,
|
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 }))
|
.progress(({ progress }) => this.setState({ progress }))
|
||||||
.finally(() => worker.terminate())
|
.finally(() => worker.terminate())
|
||||||
.then(({ text }) => this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false }))
|
.then(({ text }) => this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false }))
|
||||||
|
|
|
@ -190,11 +190,11 @@ function continueThread (state, status) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendMedia(state, media) {
|
function appendMedia(state, media, file) {
|
||||||
const prevSize = state.get('media_attachments').size;
|
const prevSize = state.get('media_attachments').size;
|
||||||
|
|
||||||
return state.withMutations(map => {
|
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('is_uploading', false);
|
||||||
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
||||||
map.set('idempotencyKey', uuid());
|
map.set('idempotencyKey', uuid());
|
||||||
|
@ -422,7 +422,7 @@ export default function compose(state = initialState, action) {
|
||||||
case COMPOSE_UPLOAD_REQUEST:
|
case COMPOSE_UPLOAD_REQUEST:
|
||||||
return state.set('is_uploading', true);
|
return state.set('is_uploading', true);
|
||||||
case COMPOSE_UPLOAD_SUCCESS:
|
case COMPOSE_UPLOAD_SUCCESS:
|
||||||
return appendMedia(state, fromJS(action.media));
|
return appendMedia(state, fromJS(action.media), action.file);
|
||||||
case COMPOSE_UPLOAD_FAIL:
|
case COMPOSE_UPLOAD_FAIL:
|
||||||
return state.set('is_uploading', false);
|
return state.set('is_uploading', false);
|
||||||
case COMPOSE_UPLOAD_UNDO:
|
case COMPOSE_UPLOAD_UNDO:
|
||||||
|
|
Loading…
Reference in New Issue