@pi-r/gcp 0.2.1 → 0.2.8
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 +4 -2
- package/client/index.js +33 -33
- package/download/index.js +10 -6
- package/package.json +7 -7
- package/upload/index.js +11 -7
package/LICENSE
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2023
|
|
1
|
+
Copyright 2023 Mile Square Park
|
|
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
|
@@ -184,7 +184,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
184
184
|
}
|
|
185
185
|
return storage.createBucket(bucket, options)
|
|
186
186
|
.then(async ([target]) => {
|
|
187
|
-
this.formatMessage(64
|
|
187
|
+
this.formatMessage(64, service, ["Bucket created", bucket], '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
188
188
|
if (acl) {
|
|
189
189
|
await setBucketPolicy.call(this, credential, bucket, { acl, bucket: target }, service);
|
|
190
190
|
}
|
|
@@ -194,7 +194,7 @@ async function createBucketV2(credential, bucket, acl, options, service = 'gcp')
|
|
|
194
194
|
if (isErrorConflict(err)) {
|
|
195
195
|
return acl ? await setBucketPolicy.call(this, credential, bucket, { acl }, service) : true;
|
|
196
196
|
}
|
|
197
|
-
this.formatFail(64
|
|
197
|
+
this.formatFail(64, service, ["Unable to create bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL });
|
|
198
198
|
return false;
|
|
199
199
|
});
|
|
200
200
|
}
|
|
@@ -205,7 +205,7 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
205
205
|
}
|
|
206
206
|
const client = createStorageClient.call(this, credential, bucket).bucket(bucket);
|
|
207
207
|
if (!await hasBucket(client)) {
|
|
208
|
-
this.formatFail(64
|
|
208
|
+
this.formatFail(64, service, ["Bucket does not exist", bucket], (0, util_1.formatError)(service, "Bucket does not exist"), { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
209
209
|
return false;
|
|
210
210
|
}
|
|
211
211
|
const errors = [];
|
|
@@ -246,10 +246,10 @@ async function setBucketPolicy(credential, bucket, options, service = 'gcp') {
|
|
|
246
246
|
errors.push(...await updatePredefinedAcl(client.acl, options.acl, options));
|
|
247
247
|
}
|
|
248
248
|
if (errors.length) {
|
|
249
|
-
this.formatFail(64
|
|
249
|
+
this.formatFail(64, service, ["Unable to update bucket policy", bucket], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
250
250
|
return false;
|
|
251
251
|
}
|
|
252
|
-
this.formatMessage(64
|
|
252
|
+
this.formatMessage(64, service, ["Bucket ACL configured", bucket], (0, types_1.isString)(acl) ? acl : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
253
253
|
return true;
|
|
254
254
|
}
|
|
255
255
|
exports.setBucketPolicy = setBucketPolicy;
|
|
@@ -266,11 +266,11 @@ function setBucketWebsite(credential, bucket, options, service = 'gcp') {
|
|
|
266
266
|
}
|
|
267
267
|
return createStorageClient.call(this, credential, bucket).bucket(bucket).setMetadata({ website })
|
|
268
268
|
.then(() => {
|
|
269
|
-
this.formatMessage(64
|
|
269
|
+
this.formatMessage(64, service, ["Bucket configured", bucket], website, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
270
270
|
return true;
|
|
271
271
|
})
|
|
272
272
|
.catch(err => {
|
|
273
|
-
this.formatFail(64
|
|
273
|
+
this.formatFail(64, service, ["Unable to configure bucket", bucket], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
274
274
|
return false;
|
|
275
275
|
});
|
|
276
276
|
}
|
|
@@ -310,14 +310,14 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
310
310
|
const client = storage.bucket(bucket);
|
|
311
311
|
if (await hasBucket(client)) {
|
|
312
312
|
if (recursive) {
|
|
313
|
-
return client.deleteFiles({ force: true }).then(() => this.formatMessage(64
|
|
313
|
+
return client.deleteFiles({ force: true }).then(() => this.formatMessage(64, service, "Bucket emptied" + ' (recursive)', bucket, { ...Cloud.LOG_CLOUD_COMMAND }));
|
|
314
314
|
}
|
|
315
315
|
const tasks = [];
|
|
316
316
|
try {
|
|
317
317
|
const result = await client.getFiles();
|
|
318
318
|
for (const { name } of result[0]) {
|
|
319
319
|
if (name.indexOf('/') === -1) {
|
|
320
|
-
tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64
|
|
320
|
+
tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch(err => this.formatFail(64, service, ["Delete failed", name], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: false })));
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
}
|
|
@@ -331,7 +331,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
331
331
|
}
|
|
332
332
|
const checkErrors = () => {
|
|
333
333
|
if (errors.length) {
|
|
334
|
-
this.formatFail(64
|
|
334
|
+
this.formatFail(64, service, ["Unable to empty bucket" + (recursive ? ' (recursive)' : ''), errors.length + ' errors'], errors[0], { ...Cloud.LOG_CLOUD_FAIL, fatal: false });
|
|
335
335
|
return true;
|
|
336
336
|
}
|
|
337
337
|
return false;
|
|
@@ -341,7 +341,7 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
341
341
|
errors.push(...result.filter(item => item.status === 'rejected').map((item) => item.reason));
|
|
342
342
|
if (!checkErrors()) {
|
|
343
343
|
const files = result.length + ' files';
|
|
344
|
-
this.formatMessage(64
|
|
344
|
+
this.formatMessage(64, service, ["Bucket emptied" + ` (${recursive ? 'recursive' : files})`, bucket], recursive ? files : '', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
345
345
|
}
|
|
346
346
|
})
|
|
347
347
|
.catch(err => {
|
|
@@ -372,7 +372,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
372
372
|
return (clients[type] = createDatabaseClient.call(this, item, data));
|
|
373
373
|
};
|
|
374
374
|
const closeClient = () => {
|
|
375
|
-
const fs = clients[3
|
|
375
|
+
const fs = clients[3];
|
|
376
376
|
if (fs) {
|
|
377
377
|
fs.terminate();
|
|
378
378
|
}
|
|
@@ -421,7 +421,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
421
421
|
result[i] = rows;
|
|
422
422
|
continue;
|
|
423
423
|
}
|
|
424
|
-
const db = createClient(item, 4
|
|
424
|
+
const db = createClient(item, 4).instance(name).table(table);
|
|
425
425
|
if (id) {
|
|
426
426
|
const row = db.row(id);
|
|
427
427
|
if (Array.isArray(columns)) {
|
|
@@ -447,11 +447,11 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
447
447
|
const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
|
|
448
448
|
if (!(query || table && columns)) {
|
|
449
449
|
closeClient();
|
|
450
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
450
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
451
451
|
}
|
|
452
452
|
if (!name || !database) {
|
|
453
453
|
closeClient();
|
|
454
|
-
throw (0, util_1.formatError)(item, !name ? "Missing instance name"
|
|
454
|
+
throw (0, util_1.formatError)(item, !name ? "Missing instance name" : "Missing database name");
|
|
455
455
|
}
|
|
456
456
|
const { updateType, options = {} } = item;
|
|
457
457
|
if (cached) {
|
|
@@ -461,7 +461,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
461
461
|
continue;
|
|
462
462
|
}
|
|
463
463
|
}
|
|
464
|
-
const db = createClient(item, 5
|
|
464
|
+
const db = createClient(item, 5).instance(name).database(database, options.databasePool, options.databaseQuery);
|
|
465
465
|
if (table) {
|
|
466
466
|
if ((0, types_1.isPlainObject)(update)) {
|
|
467
467
|
await db.table(table)[updateType === 1 ? 'insert' : updateType === 2 ? 'replace' : 'update'](update, options.tableUpdate);
|
|
@@ -480,7 +480,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
480
480
|
await new Promise((resolve, reject) => {
|
|
481
481
|
db.runTransaction((err, transaction) => {
|
|
482
482
|
if (err || !transaction) {
|
|
483
|
-
reject(err || new Error("Unknown"
|
|
483
|
+
reject(err || new Error("Unknown"));
|
|
484
484
|
}
|
|
485
485
|
else {
|
|
486
486
|
transaction.runUpdate(update)
|
|
@@ -501,7 +501,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
501
501
|
else if (product === 'firebase' || product === 'bigquery' || !product && !table && typeof query === 'string') {
|
|
502
502
|
if (!(0, types_1.isString)(query)) {
|
|
503
503
|
closeClient();
|
|
504
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
504
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
505
505
|
}
|
|
506
506
|
const firebaseApp = product === 'firebase' || isFirebaseApp(credential);
|
|
507
507
|
if (cached) {
|
|
@@ -544,7 +544,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
546
|
}
|
|
547
|
-
const db = createClient(item, 0
|
|
547
|
+
const db = createClient(item, 0);
|
|
548
548
|
if ((0, types_1.isPlainObject)(update)) {
|
|
549
549
|
await updateDB(ref(db, query), update);
|
|
550
550
|
}
|
|
@@ -562,20 +562,20 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
562
562
|
if (limit > 0) {
|
|
563
563
|
options.maxResults = limit;
|
|
564
564
|
}
|
|
565
|
-
const [job] = await createClient(item, 1
|
|
565
|
+
const [job] = await createClient(item, 1).createQueryJob(options);
|
|
566
566
|
[rows] = await job.getQueryResults();
|
|
567
567
|
}
|
|
568
568
|
}
|
|
569
569
|
else if (product === 'datastore' || !product && !table && (keys || query)) {
|
|
570
570
|
if (!keys && !Array.isArray(query)) {
|
|
571
571
|
closeClient();
|
|
572
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
572
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
573
573
|
}
|
|
574
574
|
if (cached && (rows = getCache(queryString = Module.asString(keys || query, true) + Module.asString(item.options, true) + limit))) {
|
|
575
575
|
result[i] = rows;
|
|
576
576
|
continue;
|
|
577
577
|
}
|
|
578
|
-
const db = createClient(item, 2
|
|
578
|
+
const db = createClient(item, 2);
|
|
579
579
|
if (keys) {
|
|
580
580
|
const items = !Array.isArray(keys) ? db.key(keys) : keys.map((key) => db.key(key));
|
|
581
581
|
rows = await db.get(items, item.options);
|
|
@@ -598,7 +598,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
598
598
|
case 'order':
|
|
599
599
|
case 'select':
|
|
600
600
|
case 'start':
|
|
601
|
-
task[method].apply(task, args.slice(1));
|
|
601
|
+
task[method].apply(task, args.slice(1));
|
|
602
602
|
break;
|
|
603
603
|
}
|
|
604
604
|
}
|
|
@@ -612,7 +612,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
612
612
|
else if (product === 'firestore' || !product && table) {
|
|
613
613
|
if (!table) {
|
|
614
614
|
closeClient();
|
|
615
|
-
throw (0, util_1.formatError)(item, "Missing database table"
|
|
615
|
+
throw (0, util_1.formatError)(item, "Missing database table");
|
|
616
616
|
}
|
|
617
617
|
if (cached) {
|
|
618
618
|
queryString = table + '_';
|
|
@@ -625,7 +625,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
625
625
|
continue;
|
|
626
626
|
}
|
|
627
627
|
}
|
|
628
|
-
const db = createClient(item, 3
|
|
628
|
+
const db = createClient(item, 3).collection(table).doc(id);
|
|
629
629
|
if ((0, types_1.isPlainObject)(update)) {
|
|
630
630
|
await db.update(update, { exists: true });
|
|
631
631
|
}
|
|
@@ -639,7 +639,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
639
639
|
result[i] = rows;
|
|
640
640
|
continue;
|
|
641
641
|
}
|
|
642
|
-
let db = createClient(item, 3
|
|
642
|
+
let db = createClient(item, 3).collection(table);
|
|
643
643
|
for (const args of query) {
|
|
644
644
|
if ((0, types_1.isArray)(args)) {
|
|
645
645
|
const method = args[0];
|
|
@@ -655,7 +655,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
655
655
|
case 'startAt':
|
|
656
656
|
case 'where':
|
|
657
657
|
case 'withConverter':
|
|
658
|
-
db = db[method].apply(db, args.slice(1));
|
|
658
|
+
db = db[method].apply(db, args.slice(1));
|
|
659
659
|
break;
|
|
660
660
|
}
|
|
661
661
|
}
|
|
@@ -674,12 +674,12 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
674
674
|
}
|
|
675
675
|
else {
|
|
676
676
|
closeClient();
|
|
677
|
-
throw (0, util_1.formatError)(item, "Missing database query"
|
|
677
|
+
throw (0, util_1.formatError)(item, "Missing database query");
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
680
|
else {
|
|
681
681
|
closeClient();
|
|
682
|
-
throw (0, util_1.formatError)(item, "Missing database product"
|
|
682
|
+
throw (0, util_1.formatError)(item, "Missing database product");
|
|
683
683
|
}
|
|
684
684
|
result[i] = this.setQueryResult(service, credential, queryString, rows, cacheValue);
|
|
685
685
|
}
|
|
@@ -691,12 +691,12 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
|
|
|
691
691
|
acl.add({ entity: 'allUsers', role: 'READER' })
|
|
692
692
|
.then(() => {
|
|
693
693
|
if (requested) {
|
|
694
|
-
this.formatMessage(64
|
|
694
|
+
this.formatMessage(64, service, "Grant public-read", pathname, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
695
695
|
}
|
|
696
696
|
})
|
|
697
697
|
.catch(err => {
|
|
698
698
|
if (requested) {
|
|
699
|
-
this.formatMessage(64
|
|
699
|
+
this.formatMessage(64, service, ["Unable to grant public-read", pathname], err, { ...Cloud.LOG_CLOUD_WARN });
|
|
700
700
|
}
|
|
701
701
|
});
|
|
702
702
|
}
|
|
@@ -778,10 +778,10 @@ async function setPredefinedAcl(target, value, bucket, pathname = '', metadata =
|
|
|
778
778
|
}
|
|
779
779
|
return updatePredefinedAcl(target, items, metadata).then(errors => {
|
|
780
780
|
if (errors.length) {
|
|
781
|
-
this.formatMessage(64
|
|
781
|
+
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 });
|
|
782
782
|
}
|
|
783
783
|
else if (requested && (bucket || pathname)) {
|
|
784
|
-
this.formatMessage(64
|
|
784
|
+
this.formatMessage(64, service, [(revoke ? 'Revoke' : 'Grant') + ' ' + value, bucket?.name], pathname, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
785
785
|
}
|
|
786
786
|
});
|
|
787
787
|
}
|
package/download/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
5
|
const https = require("https");
|
|
6
|
-
const client_1 = require("
|
|
6
|
+
const client_1 = require("@pi-r/gcp");
|
|
7
7
|
const types_1 = require("@e-mc/types");
|
|
8
8
|
const Module = require("@e-mc/module");
|
|
9
9
|
const Cloud = require("@e-mc/cloud");
|
|
@@ -25,12 +25,12 @@ function download(credential, service = 'gcp') {
|
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
|
|
28
|
-
downloadResponse(new Error("Unable to create temp directory"
|
|
28
|
+
downloadResponse(new Error("Unable to create temp directory"));
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
const location = Module.joinPath(Bucket, Key);
|
|
32
32
|
const destination = path.join(tempDir, path.basename(Key));
|
|
33
|
-
const deleteMessage = () => this.formatMessage(64
|
|
33
|
+
const deleteMessage = () => this.formatMessage(64, service, "Delete success", location, { ...Cloud.LOG_CLOUD_DELETE });
|
|
34
34
|
if (firebase) {
|
|
35
35
|
const { ref, getDownloadURL, deleteObject } = require('@firebase/storage');
|
|
36
36
|
const objectRef = ref(storage, Key);
|
|
@@ -45,7 +45,7 @@ function download(credential, service = 'gcp') {
|
|
|
45
45
|
if (target.deleteObject) {
|
|
46
46
|
deleteObject(objectRef)
|
|
47
47
|
.then(() => deleteMessage())
|
|
48
|
-
.catch(err => this.formatFail(64
|
|
48
|
+
.catch(err => this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active }));
|
|
49
49
|
}
|
|
50
50
|
})
|
|
51
51
|
.on('error', err => downloadResponse(err)));
|
|
@@ -69,7 +69,7 @@ function download(credential, service = 'gcp') {
|
|
|
69
69
|
deleteMessage();
|
|
70
70
|
}
|
|
71
71
|
else {
|
|
72
|
-
this.formatFail(64
|
|
72
|
+
this.formatFail(64, service, ["Delete failed", location], err, { ...Cloud.LOG_CLOUD_FAIL, fatal: !!target.active });
|
|
73
73
|
}
|
|
74
74
|
});
|
|
75
75
|
}
|
|
@@ -78,5 +78,9 @@ function download(credential, service = 'gcp') {
|
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
|
+
exports.default = download;
|
|
81
82
|
|
|
82
|
-
|
|
83
|
+
if (exports.default) {
|
|
84
|
+
module.exports = exports.default;
|
|
85
|
+
module.exports.default = exports.default;
|
|
86
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/anpham6/pi-r.git",
|
|
11
|
+
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
12
12
|
"directory": "src/cloud/gcp"
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
@@ -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.5.
|
|
24
|
-
"@e-mc/module": "^0.5.
|
|
25
|
-
"@e-mc/types": "^0.5.
|
|
26
|
-
"@google-cloud/firestore": "^6.
|
|
27
|
-
"@google-cloud/storage": "^6.
|
|
23
|
+
"@e-mc/cloud": "^0.5.4",
|
|
24
|
+
"@e-mc/module": "^0.5.4",
|
|
25
|
+
"@e-mc/types": "^0.5.4",
|
|
26
|
+
"@google-cloud/firestore": "^6.8.0",
|
|
27
|
+
"@google-cloud/storage": "^6.12.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/upload/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path = require("path");
|
|
4
4
|
const fs = require("fs");
|
|
5
|
-
const client_1 = require("
|
|
5
|
+
const client_1 = require("@pi-r/gcp");
|
|
6
6
|
const util_1 = require("@e-mc/cloud/util");
|
|
7
7
|
const types_1 = require("@e-mc/types");
|
|
8
8
|
const Module = require("@e-mc/module");
|
|
@@ -72,13 +72,13 @@ function upload(credential, service = 'gcp') {
|
|
|
72
72
|
}
|
|
73
73
|
} while (exists && ++i);
|
|
74
74
|
if (i > 0) {
|
|
75
|
-
this.formatMessage(64
|
|
75
|
+
this.formatMessage(64, service, ["File renamed", current], filename, { ...Cloud.LOG_CLOUD_WARN });
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
const Key = [filename];
|
|
79
79
|
const Body = [data.buffer];
|
|
80
80
|
const ContentType = [contentType];
|
|
81
|
-
const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com"
|
|
81
|
+
const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com", bucket, value);
|
|
82
82
|
const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
|
|
83
83
|
if (fileGroup) {
|
|
84
84
|
for (const [content, ext, localFile] of fileGroup) {
|
|
@@ -123,7 +123,7 @@ function upload(credential, service = 'gcp') {
|
|
|
123
123
|
uploadBytes(ref(bucketClient, destination), Body[i], params)
|
|
124
124
|
.then(() => {
|
|
125
125
|
const url = getURL(destination);
|
|
126
|
-
this.formatMessage(64
|
|
126
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
127
127
|
if (first) {
|
|
128
128
|
uploadResponse(null, url);
|
|
129
129
|
}
|
|
@@ -143,7 +143,7 @@ function upload(credential, service = 'gcp') {
|
|
|
143
143
|
const output = Body[i];
|
|
144
144
|
if (Buffer.isBuffer(output) || path.basename(output) !== Key[i]) {
|
|
145
145
|
if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
|
|
146
|
-
throw new Error("Unable to create temp directory"
|
|
146
|
+
throw new Error("Unable to create temp directory");
|
|
147
147
|
}
|
|
148
148
|
outputUri = path.join(tempDir, Key[i]);
|
|
149
149
|
if (typeof output === 'string') {
|
|
@@ -204,7 +204,7 @@ function upload(credential, service = 'gcp') {
|
|
|
204
204
|
bucketClient.upload(outputUri, params, (err, file) => {
|
|
205
205
|
if (file) {
|
|
206
206
|
const url = getURL(file.name);
|
|
207
|
-
this.formatMessage(64
|
|
207
|
+
this.formatMessage(64, service, "Upload success", url, { ...Cloud.LOG_CLOUD_UPLOAD });
|
|
208
208
|
if (first) {
|
|
209
209
|
uploadResponse(null, url);
|
|
210
210
|
}
|
|
@@ -226,5 +226,9 @@ function upload(credential, service = 'gcp') {
|
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
228
|
}
|
|
229
|
+
exports.default = upload;
|
|
229
230
|
|
|
230
|
-
|
|
231
|
+
if (exports.default) {
|
|
232
|
+
module.exports = exports.default;
|
|
233
|
+
module.exports.default = exports.default;
|
|
234
|
+
}
|