|
|
@ -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); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|