mirror of
https://github.com/glitch-soc/mastodon.git
synced 2024-12-01 04:20:13 -05:00
[Glitch] Fix OCR failure when erroneous lang data is in cache
Port 8428faa085
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
4aa78027ea
commit
6dd51448a6
@ -219,6 +219,10 @@ class FocalPointModal extends ImmutablePureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleTextDetection = () => {
|
handleTextDetection = () => {
|
||||||
|
this._detectText();
|
||||||
|
}
|
||||||
|
|
||||||
|
_detectText = (refreshCache = false) => {
|
||||||
const { media } = this.props;
|
const { media } = this.props;
|
||||||
|
|
||||||
this.setState({ detecting: true });
|
this.setState({ detecting: true });
|
||||||
@ -235,6 +239,7 @@ class FocalPointModal extends ImmutablePureComponent {
|
|||||||
this.setState({ ocrStatus: 'preparing', progress });
|
this.setState({ ocrStatus: 'preparing', progress });
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
cacheMethod: refreshCache ? 'refresh' : 'write',
|
||||||
});
|
});
|
||||||
|
|
||||||
let media_url = media.get('url');
|
let media_url = media.get('url');
|
||||||
@ -247,14 +252,20 @@ class FocalPointModal extends ImmutablePureComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
return (async () => {
|
||||||
await worker.load();
|
await worker.load();
|
||||||
await worker.loadLanguage('eng');
|
await worker.loadLanguage('eng');
|
||||||
await worker.initialize('eng');
|
await worker.initialize('eng');
|
||||||
const { data: { text } } = await worker.recognize(media_url);
|
const { data: { text } } = await worker.recognize(media_url);
|
||||||
this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false });
|
this.setState({ description: removeExtraLineBreaks(text), dirty: true, detecting: false });
|
||||||
await worker.terminate();
|
await worker.terminate();
|
||||||
})();
|
})().catch((e) => {
|
||||||
|
if (refreshCache) {
|
||||||
|
throw e;
|
||||||
|
} else {
|
||||||
|
this._detectText(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}).catch((e) => {
|
}).catch((e) => {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
this.setState({ detecting: false });
|
this.setState({ detecting: false });
|
||||||
|
Loading…
Reference in New Issue
Block a user