mindee 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/api/endpoint.js +6 -13
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/api/endpoint.js
CHANGED
|
@@ -51,21 +51,21 @@ class Endpoint {
|
|
|
51
51
|
*/
|
|
52
52
|
predictRequest(input, includeWords = false, cropper = false) {
|
|
53
53
|
return new Promise((resolve, reject) => {
|
|
54
|
-
const form = new form_data_1.default();
|
|
55
|
-
let body;
|
|
56
54
|
let headers = {
|
|
57
55
|
"User-Agent": USER_AGENT,
|
|
58
56
|
Authorization: `Token ${this.apiKey}`,
|
|
59
57
|
};
|
|
60
58
|
const uri = new url_1.URL(`${this.urlRoot}/predict`);
|
|
59
|
+
if (cropper) {
|
|
60
|
+
uri.searchParams.append("cropper", "true");
|
|
61
|
+
}
|
|
62
|
+
logger_1.logger.debug(`Prediction request: ${uri}`);
|
|
63
|
+
const form = new form_data_1.default();
|
|
61
64
|
const fileParams = { filename: input.filename };
|
|
62
65
|
form.append("document", input.fileObject, fileParams);
|
|
63
66
|
if (includeWords) {
|
|
64
67
|
form.append("include_mvision", "true");
|
|
65
68
|
}
|
|
66
|
-
if (cropper) {
|
|
67
|
-
uri.searchParams.append("cropper", "true");
|
|
68
|
-
}
|
|
69
69
|
headers = { ...headers, ...form.getHeaders() };
|
|
70
70
|
const options = {
|
|
71
71
|
method: "POST",
|
|
@@ -73,7 +73,6 @@ class Endpoint {
|
|
|
73
73
|
hostname: uri.hostname,
|
|
74
74
|
path: `${uri.pathname}${uri.search}`,
|
|
75
75
|
};
|
|
76
|
-
logger_1.logger.debug(`Prediction request: ${uri}`);
|
|
77
76
|
const req = https.request(options, function (res) {
|
|
78
77
|
// when the encoding is set, data chunks will be strings
|
|
79
78
|
res.setEncoding("utf-8");
|
|
@@ -93,16 +92,10 @@ class Endpoint {
|
|
|
93
92
|
}
|
|
94
93
|
});
|
|
95
94
|
});
|
|
95
|
+
form.pipe(req);
|
|
96
96
|
req.on("error", (err) => {
|
|
97
97
|
reject(err);
|
|
98
98
|
});
|
|
99
|
-
if (["path", "stream"].includes(input.inputType)) {
|
|
100
|
-
form.pipe(req);
|
|
101
|
-
}
|
|
102
|
-
if (input.inputType === "base64") {
|
|
103
|
-
req.write(body);
|
|
104
|
-
req.end();
|
|
105
|
-
}
|
|
106
99
|
});
|
|
107
100
|
}
|
|
108
101
|
apiKeyFromEnv() {
|