@pi-r/gcp 0.10.1 → 0.10.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/client/index.js +1 -1
- package/download/index.js +10 -22
- package/package.json +5 -5
package/client/index.js
CHANGED
|
@@ -741,7 +741,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
741
741
|
metadata.view = update;
|
|
742
742
|
await target.setMetadata(metadata);
|
|
743
743
|
}
|
|
744
|
-
const job =
|
|
744
|
+
const [job] = await dataset.createQueryJob(options);
|
|
745
745
|
[rows] = await job.getQueryResults();
|
|
746
746
|
}
|
|
747
747
|
else {
|
package/download/index.js
CHANGED
|
@@ -11,23 +11,11 @@ function download(credential, service = 'gcp') {
|
|
|
11
11
|
return (data, callback) => {
|
|
12
12
|
const { bucket: Bucket, download: target } = data;
|
|
13
13
|
const Key = target.keyname || target.filename;
|
|
14
|
-
let tempDir;
|
|
15
|
-
const downloadResponse = (err, url = null) => {
|
|
16
|
-
callback(err, url);
|
|
17
|
-
if (tempDir) {
|
|
18
|
-
setImmediate(() => {
|
|
19
|
-
Cloud.removeDir(tempDir);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
14
|
if (!Bucket || !Key) {
|
|
24
|
-
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
if (!(tempDir = this.getTempDir({ uuidDir: true }))) {
|
|
28
|
-
downloadResponse((0, types_1.errorValue)("Unable to create temp directory", service));
|
|
15
|
+
callback((0, types_1.errorValue)('Missing property', !Bucket ? 'Bucket' : 'Key'));
|
|
29
16
|
return;
|
|
30
17
|
}
|
|
18
|
+
const tempDir = (0, types_1.getTempDir)(true, service);
|
|
31
19
|
const location = Cloud.joinPath(Bucket, Key);
|
|
32
20
|
const destination = path.join(tempDir, path.basename(target.filename || Key));
|
|
33
21
|
const deleteMessage = () => {
|
|
@@ -40,10 +28,10 @@ function download(credential, service = 'gcp') {
|
|
|
40
28
|
https.get(url, res => {
|
|
41
29
|
const statusCode = res.statusCode;
|
|
42
30
|
if (statusCode >= 200 && statusCode < 300) {
|
|
43
|
-
res.on('error',
|
|
31
|
+
res.on('error', callback);
|
|
44
32
|
res.pipe(fs.createWriteStream(destination)
|
|
45
33
|
.on('finish', () => {
|
|
46
|
-
|
|
34
|
+
callback(null, destination);
|
|
47
35
|
if (target.deleteObject) {
|
|
48
36
|
deleteObject(objectRef)
|
|
49
37
|
.then(deleteMessage)
|
|
@@ -52,10 +40,10 @@ function download(credential, service = 'gcp') {
|
|
|
52
40
|
});
|
|
53
41
|
}
|
|
54
42
|
})
|
|
55
|
-
.on('error',
|
|
43
|
+
.on('error', callback));
|
|
56
44
|
}
|
|
57
45
|
else {
|
|
58
|
-
|
|
46
|
+
callback((0, types_1.errorMessage)(statusCode, 'Invalid HTTP request', location));
|
|
59
47
|
}
|
|
60
48
|
});
|
|
61
49
|
});
|
|
@@ -66,7 +54,7 @@ function download(credential, service = 'gcp') {
|
|
|
66
54
|
const file = bucket.file(Key, { generation: target.versionId });
|
|
67
55
|
const chunkSizeBytes = flags & 4 ? (0, types_1.alignSize)(target.chunkSize, 1024) : 0;
|
|
68
56
|
const fileDownload = () => {
|
|
69
|
-
|
|
57
|
+
callback(null, destination);
|
|
70
58
|
const deleteObject = target.deleteObject;
|
|
71
59
|
if (deleteObject) {
|
|
72
60
|
file.delete((0, types_1.isObject)(deleteObject) ? deleteObject : { ignoreNotFound: true }, err => {
|
|
@@ -86,18 +74,18 @@ function download(credential, service = 'gcp') {
|
|
|
86
74
|
concurrencyLimit: target.chunkLimit || target.options?.concurrencyLimit
|
|
87
75
|
})
|
|
88
76
|
.then(fileDownload)
|
|
89
|
-
.catch(
|
|
77
|
+
.catch(callback);
|
|
90
78
|
}
|
|
91
79
|
else if (target.chunkLimit === 1 && !target.chunkSize) {
|
|
92
80
|
file.createReadStream()
|
|
93
81
|
.pipe(fs.createWriteStream(destination))
|
|
94
82
|
.on('finish', fileDownload)
|
|
95
|
-
.on('error',
|
|
83
|
+
.on('error', callback);
|
|
96
84
|
}
|
|
97
85
|
else {
|
|
98
86
|
file.download({ destination })
|
|
99
87
|
.then(fileDownload)
|
|
100
|
-
.catch(
|
|
88
|
+
.catch(callback);
|
|
101
89
|
}
|
|
102
90
|
};
|
|
103
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@e-mc/cloud": "^0.12.
|
|
23
|
-
"@e-mc/module": "^0.12.
|
|
24
|
-
"@e-mc/types": "^0.12.
|
|
25
|
-
"@google-cloud/firestore": "^7.11.
|
|
22
|
+
"@e-mc/cloud": "^0.12.5",
|
|
23
|
+
"@e-mc/module": "^0.12.5",
|
|
24
|
+
"@e-mc/types": "^0.12.5",
|
|
25
|
+
"@google-cloud/firestore": "^7.11.3",
|
|
26
26
|
"@google-cloud/storage": "^7.16.0"
|
|
27
27
|
}
|
|
28
28
|
}
|