-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
55 lines (46 loc) · 1.5 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// nodemon restarts server automatically after changes
const express = require('express');
const app = express();
const ipAddress = '127.0.0.1';
const port = 8124;
var cors = require('cors');
var bodyParser = require('body-parser');
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ImageAnnotatorClient({
keyFilename: './gcp/APIKey.json',
});
async function runOCR() {
// Performs label detection on the image file
const [result] = await client.labelDetection('./resources/ball.jpg');
[textResult] = await client.textDetection('./resources/pdf-files.jpg');
const text = textResult.textAnnotations;
const labels = result.labelAnnotations;
const data = [text, labels];
console.log(data[0][0]);
// pass quickbooks data
//callback(data);
//return data;
}
// allow CORS from all origins
app.use(cors());
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// parse application/json. Parse response/requests bodies to JSON
app.use(bodyParser.json());
app.get('/', (req, res) => {
res.send('homepage route');
});
app.post('/upload', (req, res) => {
res.send(req.body);
});
app.get('/scanner', async (req, res) => {
console.log(req);
const [asyncData] = await client.labelDetection('./resources/nodejs.jpg');
const data = asyncData.labelAnnotations;
res.send(data);
});
app.listen(port, ipAddress, () => {
console.log(`listening on http://localhost:${port}`);
});