utilitas 1995.2.3 → 1995.2.4
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/README.md +1 -0
- package/dist/utilitas.lite.mjs +1 -1
- package/dist/utilitas.lite.mjs.map +1 -1
- package/lib/manifest.mjs +1 -1
- package/lib/storage.mjs +4 -2
- package/lib/vision.mjs +7 -8
- package/package.json +1 -1
package/lib/manifest.mjs
CHANGED
package/lib/storage.mjs
CHANGED
|
@@ -16,7 +16,8 @@ const _NEED = ['mime-types', '@google-cloud/storage'];
|
|
|
16
16
|
const errorMessage = 'Invalid file.';
|
|
17
17
|
const defaultMetadata = { cacheControl: 'public, max-age=31536000' };
|
|
18
18
|
const getGcUrlByBucket = bucket => `https://storage.cloud.google.com/${bucket}`;
|
|
19
|
-
const
|
|
19
|
+
const getGsById = id => `gs://${id}`.replace(/[\/][^\/]*$/, '');
|
|
20
|
+
const getIdByGs = gs => gs.replace(/^gs:\/\/[^/]*\/(.*)$/, '$1');
|
|
20
21
|
const mapFilename = name => join(name.substr(0, 2), name.substr(2, 2));
|
|
21
22
|
const [_zip, _unzip] = [__zip, __unzip].map(promisify);
|
|
22
23
|
const log = content => _log(content, import.meta.url);
|
|
@@ -349,7 +350,7 @@ const uploadToCloud = async (data, options) => {
|
|
|
349
350
|
});
|
|
350
351
|
const result = options?.raw ? raw : raw[0].metadata;
|
|
351
352
|
input !== FILE && await tryRm(file.path);
|
|
352
|
-
!options?.raw && result && (result.gs =
|
|
353
|
+
!options?.raw && result && (result.gs = getGsById(result?.id));
|
|
353
354
|
return result;
|
|
354
355
|
};
|
|
355
356
|
|
|
@@ -428,6 +429,7 @@ export {
|
|
|
428
429
|
getConfig,
|
|
429
430
|
getConfigFilename,
|
|
430
431
|
getGcUrlByBucket,
|
|
432
|
+
getIdByGs,
|
|
431
433
|
getTempPath,
|
|
432
434
|
handleError,
|
|
433
435
|
init,
|
package/lib/vision.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getApiKeyCredentials } from './encryption.mjs';
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
convert, deleteOnCloud, downloadFromCloud, uploadToCloud,
|
|
4
|
+
convert, deleteOnCloud, downloadFromCloud, getIdByGs, uploadToCloud,
|
|
5
5
|
} from './storage.mjs';
|
|
6
6
|
|
|
7
7
|
import {
|
|
@@ -145,7 +145,8 @@ const readAll = async (image, options) => {
|
|
|
145
145
|
});
|
|
146
146
|
const uri = result.upload?.gs;
|
|
147
147
|
const destination = `${uri}_result/`;
|
|
148
|
-
|
|
148
|
+
const resultId = getIdByGs(destination);
|
|
149
|
+
result.clear = await deleteOnCloud(resultId);
|
|
149
150
|
result.submit = await client.asyncBatchAnnotateFiles({
|
|
150
151
|
requests: [{
|
|
151
152
|
inputConfig: { mimeType: 'application/pdf', gcsSource: { uri } },
|
|
@@ -154,12 +155,10 @@ const readAll = async (image, options) => {
|
|
|
154
155
|
}],
|
|
155
156
|
});
|
|
156
157
|
result.response = await result.submit[0].promise();
|
|
157
|
-
result.result = await downloadFromCloud(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
{ expected: 'JSON' }
|
|
162
|
-
);
|
|
158
|
+
result.result = await downloadFromCloud(resultId, { expected: 'JSON' });
|
|
159
|
+
options?.keep || (result.cleanup = await Promise.all(
|
|
160
|
+
[getIdByGs(uri), resultId].map(deleteOnCloud)
|
|
161
|
+
));
|
|
163
162
|
if (options?.raw) { return result; }
|
|
164
163
|
const pages = [];
|
|
165
164
|
for (let file in result.result) {
|