utilitas 1995.2.4 → 1995.2.5
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/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/manifest.mjs +1 -1
- package/lib/vision.mjs +7 -12
- package/package.json +1 -1
package/lib/manifest.mjs
CHANGED
package/lib/vision.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getApiKeyCredentials } from './encryption.mjs';
|
|
2
|
+
import get from './shot.mjs';
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
convert, deleteOnCloud, downloadFromCloud, getIdByGs, uploadToCloud,
|
|
@@ -12,6 +13,7 @@ const _NEED = ['@google-cloud/vision', 'tesseract.js'];
|
|
|
12
13
|
const [BASE64, BUFFER, FILE, DEFAULT_LANG] = ['BASE64', 'BUFFER', 'FILE', 'eng'];
|
|
13
14
|
const ceil = num => num.toFixed(4);
|
|
14
15
|
const errorMessage = 'Invalid image data.';
|
|
16
|
+
const getTextFromBatch = bt => bt.responses.map(p => p.fullTextAnnotation.text);
|
|
15
17
|
const log = content => _log(content, import.meta.url);
|
|
16
18
|
|
|
17
19
|
let client;
|
|
@@ -125,16 +127,14 @@ const read = async (image, options) => {
|
|
|
125
127
|
const content = await convert(image, {
|
|
126
128
|
input: options?.input, expected: BASE64, errorMessage,
|
|
127
129
|
});
|
|
128
|
-
|
|
130
|
+
let result = await client.batchAnnotateFiles({
|
|
129
131
|
requests: [{
|
|
130
132
|
inputConfig: { mimeType: 'application/pdf', content },
|
|
131
133
|
features: [{ type: 'DOCUMENT_TEXT_DETECTION' }],
|
|
132
134
|
pages: [1, 2, 3, 4, 5], // max 5 pages
|
|
133
135
|
}],
|
|
134
136
|
});
|
|
135
|
-
|
|
136
|
-
options?.raw || (pages = pages.map(x => x.fullTextAnnotation.text));
|
|
137
|
-
return pages;
|
|
137
|
+
return options?.raw ? result : getTextFromBatch(result[0].responses[0]);
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
const readAll = async (image, options) => {
|
|
@@ -159,14 +159,9 @@ const readAll = async (image, options) => {
|
|
|
159
159
|
options?.keep || (result.cleanup = await Promise.all(
|
|
160
160
|
[getIdByGs(uri), resultId].map(deleteOnCloud)
|
|
161
161
|
));
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
result.result[file].responses.map(x => pages.push(
|
|
166
|
-
x.fullTextAnnotation.text
|
|
167
|
-
));
|
|
168
|
-
}
|
|
169
|
-
return pages;
|
|
162
|
+
return options?.raw ? result : Object.keys(result.result).map(
|
|
163
|
+
f => getTextFromBatch(result.result[f])
|
|
164
|
+
).flat();
|
|
170
165
|
};
|
|
171
166
|
|
|
172
167
|
export {
|