forked from peihsinsu/google-vision-api-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
requtil.js
52 lines (47 loc) · 966 Bytes
/
requtil.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
var fs = require('fs');
/**
* Build the base64 image content from path
*/
function imgContent(path) {
var result = fs.readFileSync(path).toString('base64');
return process.env['TEST'] ? result.substring(0,50) + '...' : result;
}
/**
* Create the leaf request
*/
exports.createRequest = createRequest;
function createRequest(path){
return {
image: {content: imgContent(path)},
features: [],
withFeature: function(type, maxResult) {
this.features.push({
type: type,
maxResults: maxResult
})
return this;
},
build: function() {
return {
image: this.image,
features: this.features
}
}
}
}
/**
* Create the root request
*/
exports.createRequests = createRequests;
function createRequests(){
return {
requests:[],
addRequest: function(req) {
this.requests.push(req);
return this;
},
build: function(){
return {requests: this.requests}
}
}
}