[Glitch] Use blob URL for Tesseract to avoid CORS issues

Port 7baedcb61e to glitch-soc

Signed-off-by: Thibaut Girka <thib@sitedethib.com>
This commit is contained in:
ThibG
2019-09-27 02:16:11 +02:00
committed by Thibaut Girka
parent 4b7c436ae9
commit 74af56b9cd
3 changed files with 17 additions and 6 deletions

View 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 }))