}
handleTextDetection = () => {
+ this._detectText();
+ }
+
+ _detectText = (refreshCache = false) => {
const { media } = this.props;
this.setState({ detecting: true });
this.setState({ ocrStatus: 'preparing', progress });
}
},
+ cacheMethod: refreshCache ? 'refresh' : 'write',
});
let media_url = media.get('url');
}
}
- (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 });