@pi-r/gcp 0.6.3 → 0.6.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/LICENSE +1 -1
- package/README.md +6 -3
- package/client/index.js +34 -34
- package/download/index.js +5 -6
- package/package.json +5 -5
- package/upload/index.js +6 -7
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
4
|
|
package/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -194,7 +194,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
194
194
|
}
|
|
195
195
|
return instance.createBucket(bucket, options)
|
|
196
196
|
.then(async ([target]) => {
|
|
197
|
-
this.formatMessage(64
|
|
197
|
+
this.formatMessage(64, service, ["Bucket created", bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
198
198
|
if (acl) {
|
|
199
199
|
await setBucketPolicy.call(this, credential, bucket, { acl, bucket: target }, service);
|
|
200
200
|
}
|
|
@@ -204,7 +204,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
204
204
|
if (isErrorConflict(err)) {
|
|
205
205
|
return acl ? await setBucketPolicy.call(this, credential, bucket, { acl }, service) : true;
|
|
206
206
|
}
|
|
207
|
-
this.formatFail(64
|
|
207
|
+
this.formatFail(64, service, ["Unable to create bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
208
208
|
return false;
|
|
209
209
|
});
|
|
210
210
|
}
|
|
@@ -215,7 +215,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
215
215
|
}
|
|
216
216
|
const client = createStorageClient.call(this, credential, bucket).bucket(bucket);
|
|
217
217
|
if (!await hasBucket(client)) {
|
|
218
|
-
this.formatFail(64
|
|
218
|
+
this.formatFail(64, service, ["Bucket does not exist", bucket], (0, types_1.errorMessage)(service, "Bucket does not exist"), { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
219
219
|
return false;
|
|
220
220
|
}
|
|
221
221
|
const errors = [];
|
|
@@ -256,10 +256,10 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
256
256
|
errors.push(...await updatePredefinedAcl(client.acl, options.acl, options.metadata));
|
|
257
257
|
}
|
|
258
258
|
if (errors.length) {
|
|
259
|
-
this.formatFail(64
|
|
259
|
+
this.formatFail(64, service, ["Unable to update bucket policy", bucket], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
260
260
|
return false;
|
|
261
261
|
}
|
|
262
|
-
this.formatMessage(64
|
|
262
|
+
this.formatMessage(64, service, ["Bucket ACL configured", bucket], (0, types_1.isString)(acl) ? acl : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
263
263
|
return true;
|
|
264
264
|
}
|
|
265
265
|
exports.setBucketPolicy = setBucketPolicy;
|
|
@@ -277,11 +277,11 @@ async function setBucketWebsite(credential, bucket, options, service = 'gcp') {
|
|
|
277
277
|
}
|
|
278
278
|
return createStorageClient.call(this, credential, bucket).bucket(bucket).setMetadata({ website })
|
|
279
279
|
.then(() => {
|
|
280
|
-
this.formatMessage(64
|
|
280
|
+
this.formatMessage(64, service, ["Bucket configured", bucket], website, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
281
281
|
return true;
|
|
282
282
|
})
|
|
283
283
|
.catch(err => {
|
|
284
|
-
this.formatFail(64
|
|
284
|
+
this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
285
285
|
return false;
|
|
286
286
|
});
|
|
287
287
|
}
|
|
@@ -321,14 +321,14 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
321
321
|
const client = instance.bucket(bucket);
|
|
322
322
|
if (await hasBucket(client)) {
|
|
323
323
|
if (recursive) {
|
|
324
|
-
return client.deleteFiles({ force: true }).then(() => this.formatMessage(64
|
|
324
|
+
return client.deleteFiles({ force: true }).then(() => this.formatMessage(64, service, "Bucket emptied" + ' (recursive)', bucket, { ...Cloud.LOG_CLOUD_COMMAND }));
|
|
325
325
|
}
|
|
326
326
|
const tasks = [];
|
|
327
327
|
try {
|
|
328
328
|
const result = await client.getFiles();
|
|
329
329
|
for (const { name } of result[0]) {
|
|
330
330
|
if (!name.includes('/')) {
|
|
331
|
-
tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64
|
|
331
|
+
tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64, service, ["Delete failed", name], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false })));
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
}
|
|
@@ -342,7 +342,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
342
342
|
}
|
|
343
343
|
const checkErrors = () => {
|
|
344
344
|
if (errors.length) {
|
|
345
|
-
this.formatFail(64
|
|
345
|
+
this.formatFail(64, service, ["Unable to empty bucket" + (recursive ? ' (recursive)' : ''), errors.length + ' errors'], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
346
346
|
return true;
|
|
347
347
|
}
|
|
348
348
|
return false;
|
|
@@ -352,7 +352,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
352
352
|
errors.push(...result.filter(item => item.status === 'rejected').map((item) => item.reason));
|
|
353
353
|
if (!checkErrors()) {
|
|
354
354
|
const files = result.length + ' files';
|
|
355
|
-
this.formatMessage(64
|
|
355
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
356
356
|
}
|
|
357
357
|
})
|
|
358
358
|
.catch(err => {
|
|
@@ -383,7 +383,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
383
383
|
return (clients[type] = createDatabaseClient.call(this, item, data));
|
|
384
384
|
};
|
|
385
385
|
const closeClient = () => {
|
|
386
|
-
const fs = clients[3
|
|
386
|
+
const fs = clients[3];
|
|
387
387
|
fs?.terminate();
|
|
388
388
|
};
|
|
389
389
|
const getFamily = (data, row, family) => {
|
|
@@ -420,7 +420,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
420
420
|
if (product === 'firebase' || isFirebaseApp(credential)) {
|
|
421
421
|
if (!(0, types_1.isString)(query)) {
|
|
422
422
|
closeClient();
|
|
423
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
423
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
424
424
|
}
|
|
425
425
|
const orderBy = item.orderBy;
|
|
426
426
|
if (useCache) {
|
|
@@ -462,7 +462,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
464
|
}
|
|
465
|
-
const db = createClient(item, 0
|
|
465
|
+
const db = createClient(item, 0);
|
|
466
466
|
if ((0, types_1.isPlainObject)(update)) {
|
|
467
467
|
await updateDB(ref(db, query), update);
|
|
468
468
|
}
|
|
@@ -477,11 +477,11 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
477
477
|
const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
|
|
478
478
|
if (!(query || table && columns)) {
|
|
479
479
|
closeClient();
|
|
480
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
480
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
481
481
|
}
|
|
482
482
|
if (!name || !database) {
|
|
483
483
|
closeClient();
|
|
484
|
-
throw (0, util_1.formatError)(item, !name ? "Missing instance name"
|
|
484
|
+
throw (0, util_1.formatError)(item, !name ? "Missing instance name" : "Missing database name");
|
|
485
485
|
}
|
|
486
486
|
const { updateType, options = {} } = item;
|
|
487
487
|
if (useCache) {
|
|
@@ -491,7 +491,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
491
491
|
continue;
|
|
492
492
|
}
|
|
493
493
|
}
|
|
494
|
-
const db = createClient(item, 5
|
|
494
|
+
const db = createClient(item, 5).instance(name).database(database, options.databasePool, options.databaseQuery);
|
|
495
495
|
if (table) {
|
|
496
496
|
if ((0, types_1.isPlainObject)(update)) {
|
|
497
497
|
await db.table(table)[updateType === 1 ? 'insert' : updateType === 2 ? 'replace' : 'update'](update, options.tableUpdate);
|
|
@@ -512,7 +512,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
512
512
|
await new Promise((resolve, reject) => {
|
|
513
513
|
db.runTransaction((err, transaction) => {
|
|
514
514
|
if (err || !transaction) {
|
|
515
|
-
reject(err || new Error("Unknown"
|
|
515
|
+
reject(err || new Error("Unknown"));
|
|
516
516
|
}
|
|
517
517
|
else {
|
|
518
518
|
transaction.runUpdate(update)
|
|
@@ -533,7 +533,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
533
533
|
else if (product === 'bigtable' || !product && name && table && !database) {
|
|
534
534
|
if (!name || !table) {
|
|
535
535
|
closeClient();
|
|
536
|
-
throw (0, util_1.formatError)(item, !name ? "Missing database name"
|
|
536
|
+
throw (0, util_1.formatError)(item, !name ? "Missing database name" : "Missing database table");
|
|
537
537
|
}
|
|
538
538
|
const { columns, options = {} } = item;
|
|
539
539
|
if ((0, types_1.isObject)(query)) {
|
|
@@ -549,7 +549,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
549
549
|
continue;
|
|
550
550
|
}
|
|
551
551
|
}
|
|
552
|
-
const db = createClient(item, 4
|
|
552
|
+
const db = createClient(item, 4).instance(name).table(table);
|
|
553
553
|
if ((0, types_1.isString)(id)) {
|
|
554
554
|
const row = db.row(id);
|
|
555
555
|
if (update) {
|
|
@@ -592,7 +592,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
592
592
|
continue;
|
|
593
593
|
}
|
|
594
594
|
}
|
|
595
|
-
const instance = createClient(item, 1
|
|
595
|
+
const instance = createClient(item, 1);
|
|
596
596
|
let job;
|
|
597
597
|
if (database) {
|
|
598
598
|
const dataset = instance.dataset(database);
|
|
@@ -617,7 +617,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
617
617
|
const { keys, kind } = item;
|
|
618
618
|
if (!keys && !kind && !Array.isArray(query)) {
|
|
619
619
|
closeClient();
|
|
620
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
620
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
621
621
|
}
|
|
622
622
|
if (useCache) {
|
|
623
623
|
queryString = (keys ? Cloud.asString(keys, true) : (kind ? (name ? name + '_' : '') + Cloud.asString(kind, true) : '') + (limit > 0 ? '_' + limit : 0) + Cloud.asString(query, true)) + Cloud.asString(item.options, true);
|
|
@@ -626,7 +626,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
626
626
|
continue;
|
|
627
627
|
}
|
|
628
628
|
}
|
|
629
|
-
const db = createClient(item, 2
|
|
629
|
+
const db = createClient(item, 2);
|
|
630
630
|
if (keys) {
|
|
631
631
|
const items = !Array.isArray(keys) || !Array.isArray(keys[0]) ? db.key(keys) : keys.map((key) => db.key(key));
|
|
632
632
|
if ((0, types_1.isPlainObject)(update)) {
|
|
@@ -652,7 +652,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
652
652
|
case 'order':
|
|
653
653
|
case 'select':
|
|
654
654
|
case 'start':
|
|
655
|
-
task[method].apply(task, args.slice(1));
|
|
655
|
+
task[method].apply(task, args.slice(1));
|
|
656
656
|
break;
|
|
657
657
|
case 'hasAncestor':
|
|
658
658
|
task.hasAncestor(db.key(args[1]));
|
|
@@ -684,7 +684,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
684
684
|
else if (product === 'firestore' || !product && table) {
|
|
685
685
|
if (!table) {
|
|
686
686
|
closeClient();
|
|
687
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
687
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
688
688
|
}
|
|
689
689
|
if (id) {
|
|
690
690
|
if (useCache) {
|
|
@@ -694,7 +694,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
694
694
|
continue;
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
|
-
const db = createClient(item, 3
|
|
697
|
+
const db = createClient(item, 3);
|
|
698
698
|
if (Array.isArray(id)) {
|
|
699
699
|
const items = id.map(ref => db.doc(table + '/' + ref));
|
|
700
700
|
if ((0, types_1.isPlainObject)(item.options)) {
|
|
@@ -719,7 +719,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
719
719
|
result[i] = rows;
|
|
720
720
|
continue;
|
|
721
721
|
}
|
|
722
|
-
let db = createClient(item, 3
|
|
722
|
+
let db = createClient(item, 3).collection(table);
|
|
723
723
|
for (const args of query) {
|
|
724
724
|
if ((0, types_1.isArray)(args)) {
|
|
725
725
|
const method = args[0];
|
|
@@ -745,7 +745,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
745
745
|
case 'startAt':
|
|
746
746
|
case 'where':
|
|
747
747
|
case 'withConverter':
|
|
748
|
-
db = db[method].apply(db, params);
|
|
748
|
+
db = db[method].apply(db, params);
|
|
749
749
|
break;
|
|
750
750
|
}
|
|
751
751
|
}
|
|
@@ -764,12 +764,12 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
764
764
|
}
|
|
765
765
|
else {
|
|
766
766
|
closeClient();
|
|
767
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
767
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
770
|
else {
|
|
771
771
|
closeClient();
|
|
772
|
-
throw (0, util_1.formatError)(item, "Missing database product"
|
|
772
|
+
throw (0, util_1.formatError)(item, "Missing database product");
|
|
773
773
|
}
|
|
774
774
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
775
775
|
}
|
|
@@ -781,12 +781,12 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
|
|
|
781
781
|
acl.add({ entity: 'allUsers', role: 'READER' })
|
|
782
782
|
.then(() => {
|
|
783
783
|
if (requested) {
|
|
784
|
-
this.formatMessage(64
|
|
784
|
+
this.formatMessage(64, service, "Grant public-read", pathname, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
785
785
|
}
|
|
786
786
|
})
|
|
787
787
|
.catch(err => {
|
|
788
788
|
if (requested) {
|
|
789
|
-
this.formatMessage(64
|
|
789
|
+
this.formatMessage(64, service, ["Unable to grant public-read", pathname], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
790
790
|
}
|
|
791
791
|
});
|
|
792
792
|
}
|
|
@@ -861,10 +861,10 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
861
861
|
}
|
|
862
862
|
return updatePredefinedAcl(target, items, metadata).then(errors => {
|
|
863
863
|
if (errors.length) {
|
|
864
|
-
this.formatMessage(64
|
|
864
|
+
this.formatMessage(64, service, [`Unable to ${revoke ? 'revoke' : 'grant'} ` + value, bucket && pathname ? bucket.name + '/' + pathname : bucket ? bucket.name : pathname], errors[0], { ...Cloud.LOG_CLOUD_WARN });
|
|
865
865
|
}
|
|
866
866
|
else if (requested && (bucket || pathname)) {
|
|
867
|
-
this.formatMessage(64
|
|
867
|
+
this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
868
868
|
}
|
|
869
869
|
});
|
|
870
870
|
}
|
package/download/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const fs = require("fs");
|
|
5
4
|
const https = require("https");
|
|
6
5
|
const types_1 = require("@e-mc/types");
|
|
7
6
|
const Module = require("@e-mc/module");
|
|
8
7
|
const Cloud = require("@e-mc/cloud");
|
|
9
|
-
const client_1 = require("
|
|
8
|
+
const client_1 = require("@pi-r/gcp");
|
|
10
9
|
function download(credential, service = 'gcp') {
|
|
11
10
|
const storage = client_1.createStorageClient.call(this, credential);
|
|
12
11
|
return (data, callback) => {
|
|
@@ -25,12 +24,12 @@ function download(credential, service = 'gcp') {
|
|
|
25
24
|
return;
|
|
26
25
|
}
|
|
27
26
|
if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
|
|
28
|
-
downloadResponse(new Error("Unable to create temp directory"
|
|
27
|
+
downloadResponse(new Error("Unable to create temp directory"));
|
|
29
28
|
return;
|
|
30
29
|
}
|
|
31
30
|
const location = Module.joinPath(Bucket, Key);
|
|
32
31
|
const destination = path.join(tempDir, path.basename(Key));
|
|
33
|
-
const deleteMessage = () => this.formatMessage(64
|
|
32
|
+
const deleteMessage = () => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
|
|
34
33
|
if (firebase) {
|
|
35
34
|
const { ref, getDownloadURL, deleteObject } = require('@firebase/storage');
|
|
36
35
|
const objectRef = ref(storage, Key);
|
|
@@ -45,7 +44,7 @@ function download(credential, service = 'gcp') {
|
|
|
45
44
|
if (target.deleteObject) {
|
|
46
45
|
deleteObject(objectRef)
|
|
47
46
|
.then(() => deleteMessage())
|
|
48
|
-
.catch(err => this.formatFail(64
|
|
47
|
+
.catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
|
|
49
48
|
}
|
|
50
49
|
})
|
|
51
50
|
.on('error', err => downloadResponse(err)));
|
|
@@ -69,7 +68,7 @@ function download(credential, service = 'gcp') {
|
|
|
69
68
|
deleteMessage();
|
|
70
69
|
}
|
|
71
70
|
else {
|
|
72
|
-
this.formatFail(64
|
|
71
|
+
this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
|
|
73
72
|
}
|
|
74
73
|
});
|
|
75
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.8.
|
|
24
|
-
"@e-mc/module": "^0.8.
|
|
25
|
-
"@e-mc/types": "^0.8.
|
|
26
|
-
"@google-cloud/firestore": "^7.
|
|
23
|
+
"@e-mc/cloud": "^0.8.6",
|
|
24
|
+
"@e-mc/module": "^0.8.6",
|
|
25
|
+
"@e-mc/types": "^0.8.6",
|
|
26
|
+
"@google-cloud/firestore": "^7.3.1",
|
|
27
27
|
"@google-cloud/storage": "^7.7.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/upload/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
const path = require("path");
|
|
4
3
|
const util_1 = require("@e-mc/cloud/util");
|
|
5
4
|
const types_1 = require("@e-mc/types");
|
|
6
5
|
const Module = require("@e-mc/module");
|
|
7
6
|
const Cloud = require("@e-mc/cloud");
|
|
8
|
-
const client_1 = require("
|
|
7
|
+
const client_1 = require("@pi-r/gcp");
|
|
9
8
|
const BUCKET_SESSION = new Set();
|
|
10
9
|
const BUCKET_RESPONSE = {};
|
|
11
10
|
const getBucketKey = (credential, bucket, acl = '') => Module.asString(credential, true) + bucket + '_' + acl;
|
|
@@ -56,7 +55,7 @@ function upload(credential, service = 'gcp') {
|
|
|
56
55
|
if (typeof retentionPolicy === 'number') {
|
|
57
56
|
bucketClient.setRetentionPeriod(retentionPolicy)
|
|
58
57
|
.then(([response]) => {
|
|
59
|
-
this.formatMessage(64
|
|
58
|
+
this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], response.retentionPolicy?.effectiveTime, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
60
59
|
})
|
|
61
60
|
.catch(err => addLog(err));
|
|
62
61
|
}
|
|
@@ -81,10 +80,10 @@ function upload(credential, service = 'gcp') {
|
|
|
81
80
|
}
|
|
82
81
|
} while (exists && ++i);
|
|
83
82
|
if (i > 0) {
|
|
84
|
-
this.formatMessage(64
|
|
83
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
|
-
const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com"
|
|
86
|
+
const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com", bucket, value);
|
|
88
87
|
const Key = [filename];
|
|
89
88
|
const Body = [data.buffer];
|
|
90
89
|
const ContentType = [contentType];
|
|
@@ -118,7 +117,7 @@ function upload(credential, service = 'gcp') {
|
|
|
118
117
|
uploadBytes(ref(bucketClient, destination), Body[i], params)
|
|
119
118
|
.then(() => {
|
|
120
119
|
const url = getURL(destination);
|
|
121
|
-
this.formatMessage(64
|
|
120
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
122
121
|
if (first) {
|
|
123
122
|
uploadResponse(null, url);
|
|
124
123
|
}
|
|
@@ -172,7 +171,7 @@ function upload(credential, service = 'gcp') {
|
|
|
172
171
|
const file = bucketClient.file(destination);
|
|
173
172
|
file.save(Body[i], params).then(async () => {
|
|
174
173
|
const url = getURL(file.name);
|
|
175
|
-
this.formatMessage(64
|
|
174
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
176
175
|
if (first) {
|
|
177
176
|
uploadResponse(null, url);
|
|
178
177
|
}
|