generated from olcortesb/serverless-aws-nodejs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
34 lines (28 loc) · 750 Bytes
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict';
const path = require('path');
const fs = require('fs');
const { createWorker } = require('tesseract.js');
module.exports.hello = async (event) => {
const dir = path.join('/tmp');
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
const worker = createWorker({
cachePath: path.join('/tmp'),
});
const result = await run(worker);
return {
statusCode: 200,
body: result
};
};
async function run(worker) {
await worker.load();
await worker.loadLanguage('eng');
//await move_file('');
await worker.initialize('eng');
const { data: { text } } = await worker.recognize('https://tesseract.projectnaptha.com/img/eng_bw.png');
console.log(text);
await worker.terminate();
return text;
}