thorin-plugin-upload-gcloud 2.0.1 → 2.0.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/store.js +10 -8
- package/package.json +1 -1
package/lib/store.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
const Storage = require('@google-cloud/storage');
|
|
2
|
+
const { Storage, File } = require('@google-cloud/storage');
|
|
3
3
|
const url = require('url'),
|
|
4
4
|
fs = require('fs'),
|
|
5
5
|
path = require('path'),
|
|
6
6
|
concat = require('concat-stream');
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
const GCLOUD_STORAGE_URL = 'https://storage.googleapis.com/',
|
|
10
9
|
GCLOUD_STORAGE_HOST = 'storage.googleapis.com';
|
|
11
10
|
|
|
@@ -48,7 +47,7 @@ module.exports = function (thorin, opt, IStorage) {
|
|
|
48
47
|
} else {
|
|
49
48
|
let credPath = this[config].credentials.charAt(0) === '/' ? path.normalize(this[config].credentials) : path.normalize(thorin.root + '/' + this[config].credentials);
|
|
50
49
|
try {
|
|
51
|
-
let creds = fs.readFileSync(credPath, {encoding: 'utf8'});
|
|
50
|
+
let creds = fs.readFileSync(credPath, { encoding: 'utf8' });
|
|
52
51
|
creds = JSON.parse(creds);
|
|
53
52
|
this[config].credentials = creds;
|
|
54
53
|
} catch (e) {
|
|
@@ -65,7 +64,9 @@ module.exports = function (thorin, opt, IStorage) {
|
|
|
65
64
|
return;
|
|
66
65
|
}
|
|
67
66
|
this[sdk] = new Storage({
|
|
68
|
-
credentials: this[config].credentials
|
|
67
|
+
credentials: this[config].credentials,
|
|
68
|
+
projectId: this[config].credentials.project_id,
|
|
69
|
+
email: this[config].credentials.email
|
|
69
70
|
});
|
|
70
71
|
}
|
|
71
72
|
|
|
@@ -83,7 +84,7 @@ module.exports = function (thorin, opt, IStorage) {
|
|
|
83
84
|
save(fileObj) {
|
|
84
85
|
return new Promise((resolve, reject) => {
|
|
85
86
|
const bucketObj = this[sdk].bucket(this[config].bucket);
|
|
86
|
-
let sFileObj = new
|
|
87
|
+
let sFileObj = new File(bucketObj, fileObj.getKey(), {
|
|
87
88
|
//resumable: false
|
|
88
89
|
});
|
|
89
90
|
let fOpt = thorin.util.extend({
|
|
@@ -172,7 +173,7 @@ module.exports = function (thorin, opt, IStorage) {
|
|
|
172
173
|
if (!fopt.bucket) fopt.bucket = this[config].bucket;
|
|
173
174
|
return new Promise((resolve, reject) => {
|
|
174
175
|
const bucketObj = this[sdk].bucket(fopt.bucket);
|
|
175
|
-
let sFileObj = new
|
|
176
|
+
let sFileObj = new File(bucketObj, fopt.key);
|
|
176
177
|
let readStr = sFileObj.createReadStream(opt);
|
|
177
178
|
if (opt.raw === true) {
|
|
178
179
|
return resolve(readStr);
|
|
@@ -239,7 +240,7 @@ module.exports = function (thorin, opt, IStorage) {
|
|
|
239
240
|
opt.expire = 60;
|
|
240
241
|
}
|
|
241
242
|
const bucketObj = this[sdk].bucket(opt.bucket);
|
|
242
|
-
const fileObj = new
|
|
243
|
+
const fileObj = new File(bucketObj, opt.key);
|
|
243
244
|
const fOpt = {
|
|
244
245
|
action: opt.action || 'read'
|
|
245
246
|
};
|
|
@@ -277,7 +278,8 @@ module.exports = function (thorin, opt, IStorage) {
|
|
|
277
278
|
if (!opt.bucket) opt.bucket = this[config].bucket;
|
|
278
279
|
if (!opt.key) return resolve(null);
|
|
279
280
|
const bucketObj = this[sdk].bucket(opt.bucket);
|
|
280
|
-
|
|
281
|
+
if (opt.key.charAt(0) === '/') opt.key = opt.key.substr(1);
|
|
282
|
+
const fileObj = new File(bucketObj, opt.key);
|
|
281
283
|
fileObj.delete((err) => {
|
|
282
284
|
if (err) {
|
|
283
285
|
if (err.code === 404) {
|