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/lib/manifest.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const manifest = {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1995.2.3",
4
+ "version": "1995.2.4",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",
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 getGs = id => `gs://${id}`.replace(/[\/][^\/]*$/, '');
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 = getGs(result?.id));
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
- result.clear = await deleteOnCloud(destination);
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
- result.response[0].responses[0].outputConfig.gcsDestination.uri.replace(
159
- /^gs:\/\/[^/]*\/(.*)$/, '$1'
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) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for JavaScript.",
4
- "version": "1995.2.3",
4
+ "version": "1995.2.4",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.mjs",