Browse Source

Edited loadLanguage to no longer overwrite cache with data from cache per #666

dev/v4
Balearica 2 years ago
parent
commit
c0298ff1fa
  1. 4
      src/worker-script/index.js

4
src/worker-script/index.js

@ -82,6 +82,7 @@ res) => {
? () => Promise.resolve() ? () => Promise.resolve()
: adapter.readCache; : adapter.readCache;
let data = null; let data = null;
let newData = false;
try { try {
const _data = await readCache(`${cachePath || '.'}/${lang}.traineddata`); const _data = await readCache(`${cachePath || '.'}/${lang}.traineddata`);
@ -93,6 +94,7 @@ res) => {
throw Error('Not found in cache'); throw Error('Not found in cache');
} }
} catch (e) { } catch (e) {
newData = true;
log(`[${workerId}]: Load ${lang}.traineddata from ${langPath}`); log(`[${workerId}]: Load ${lang}.traineddata from ${langPath}`);
if (typeof _lang === 'string') { if (typeof _lang === 'string') {
let path = null; let path = null;
@ -134,7 +136,7 @@ res) => {
TessModule.FS.writeFile(`${dataPath || '.'}/${lang}.traineddata`, data); TessModule.FS.writeFile(`${dataPath || '.'}/${lang}.traineddata`, data);
} }
if (['write', 'refresh', undefined].includes(cacheMethod)) { if (newData && ['write', 'refresh', undefined].includes(cacheMethod)) {
await adapter.writeCache(`${cachePath || '.'}/${lang}.traineddata`, data); await adapter.writeCache(`${cachePath || '.'}/${lang}.traineddata`, data);
} }

Loading…
Cancel
Save