@pi-r/gcp 0.12.0 → 0.12.2
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/download/index.js +6 -3
- package/package.json +6 -9
- package/upload/index.js +6 -3
package/download/index.js
CHANGED
|
@@ -37,12 +37,12 @@ function download(credential, service = "gcp") {
|
|
|
37
37
|
.catch(callback);
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const { flags = 0 } = target;
|
|
40
|
+
const { encryptionKey, flags = 0 } = target;
|
|
41
41
|
const tempDir = getTempDir(true, service);
|
|
42
42
|
const destination = path.join(tempDir, path.basename(target.filename || Key));
|
|
43
43
|
const bucket = storage.bucket(Bucket);
|
|
44
44
|
const file = bucket.file(Key, { generation: target.versionId });
|
|
45
|
-
const chunkSizeBytes = flags & 4 ? alignSize(target.chunkSize, 1024) : 0;
|
|
45
|
+
const chunkSizeBytes = (flags & 4) && !encryptionKey ? alignSize(target.chunkSize, 1024) : 0;
|
|
46
46
|
const complete = async () => {
|
|
47
47
|
callback(null, destination);
|
|
48
48
|
const copyTo = intoArray(target.copyObject);
|
|
@@ -72,13 +72,16 @@ function download(credential, service = "gcp") {
|
|
|
72
72
|
.then(complete)
|
|
73
73
|
.catch(callback);
|
|
74
74
|
}
|
|
75
|
-
else if (target.chunkLimit === 1 && !target.chunkSize) {
|
|
75
|
+
else if (target.chunkLimit === 1 && !target.chunkSize && !encryptionKey) {
|
|
76
76
|
file.createReadStream()
|
|
77
77
|
.pipe(fs.createWriteStream(destination))
|
|
78
78
|
.on('finish', complete)
|
|
79
79
|
.on('error', callback);
|
|
80
80
|
}
|
|
81
81
|
else {
|
|
82
|
+
if (encryptionKey) {
|
|
83
|
+
file.setEncryptionKey(encryptionKey);
|
|
84
|
+
}
|
|
82
85
|
file.download({ destination })
|
|
83
86
|
.then(complete)
|
|
84
87
|
.catch(callback);
|
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
|
-
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
8
|
-
},
|
|
9
6
|
"repository": {
|
|
10
7
|
"type": "git",
|
|
11
8
|
"url": "git+https://github.com/anpham6/pi-r.git",
|
|
@@ -19,10 +16,10 @@
|
|
|
19
16
|
"license": "MIT",
|
|
20
17
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
18
|
"dependencies": {
|
|
22
|
-
"@e-mc/cloud": "^0.14.
|
|
23
|
-
"@e-mc/module": "^0.14.
|
|
24
|
-
"@e-mc/types": "^0.14.
|
|
25
|
-
"@google-cloud/firestore": "^8.
|
|
26
|
-
"@google-cloud/storage": "^7.
|
|
19
|
+
"@e-mc/cloud": "^0.14.3",
|
|
20
|
+
"@e-mc/module": "^0.14.3",
|
|
21
|
+
"@e-mc/types": "^0.14.3",
|
|
22
|
+
"@google-cloud/firestore": "^8.6.0",
|
|
23
|
+
"@google-cloud/storage": "^7.21.0"
|
|
27
24
|
}
|
|
28
25
|
}
|
package/upload/index.js
CHANGED
|
@@ -16,7 +16,7 @@ function upload(credential, service = "gcp") {
|
|
|
16
16
|
return async (data, callback) => {
|
|
17
17
|
const firebase = isFirebaseApp(credential, true, true);
|
|
18
18
|
const { bucket, localUri } = data;
|
|
19
|
-
const { pathname, flags = 0, fileGroup, descendantsGroup, contentType, metadata, endpoint, active, publicRead, acl, admin = {}, overwrite, options } = data.upload;
|
|
19
|
+
const { pathname, flags = 0, fileGroup, descendantsGroup, contentType, encryptionKey, metadata, endpoint, active, publicRead, acl, admin = {}, overwrite, options } = data.upload;
|
|
20
20
|
let filename = data.upload.filename || path.basename(localUri), chunkSizeBytes = 0, bucketClient, bucketKey, listFiles;
|
|
21
21
|
const complete = (err, url) => {
|
|
22
22
|
if (!firebase) {
|
|
@@ -90,7 +90,7 @@ function upload(credential, service = "gcp") {
|
|
|
90
90
|
.catch(addLog);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
if (flags & 4) {
|
|
93
|
+
if ((flags & 4) && !encryptionKey) {
|
|
94
94
|
const chunkSize = alignSize(data.upload.chunkSize, 1024);
|
|
95
95
|
if (chunkSize > 0) {
|
|
96
96
|
chunkSizeBytes = Math.max(chunkSize, 8388608);
|
|
@@ -174,7 +174,7 @@ function upload(credential, service = "gcp") {
|
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
else if ((flags & 2) && !firebase) {
|
|
177
|
+
else if ((flags & 2) && !firebase && !encryptionKey) {
|
|
178
178
|
try {
|
|
179
179
|
Stream.push(data.buffer.length > 0 ? stream.Readable.from(data.buffer) : fs.createReadStream(localUri, { signal: this.signal }));
|
|
180
180
|
if (fileGroup) {
|
|
@@ -309,6 +309,9 @@ function upload(credential, service = "gcp") {
|
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
311
|
else {
|
|
312
|
+
if (encryptionKey) {
|
|
313
|
+
params.encryptionKey = encryptionKey;
|
|
314
|
+
}
|
|
312
315
|
uploadClient = file.save(Body[i], params);
|
|
313
316
|
}
|
|
314
317
|
}
|