added gcs

This commit is contained in:
Danny Coates 2018-11-02 14:24:10 -07:00
parent 9bb36cd827
commit 53426b950a
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
5 changed files with 4318 additions and 6074 deletions

10437
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -114,7 +114,8 @@
"webpack-unassert-loader": "^1.2.0"
},
"dependencies": {
"aws-sdk": "^2.329.0",
"@google-cloud/storage": "^2.0.3",
"aws-sdk": "^2.328.0",
"babel-polyfill": "^6.26.0",
"choo": "^6.13.0",
"cldr-core": "^32.0.0",
@ -122,6 +123,7 @@
"convict": "^4.4.0",
"express": "^4.16.3",
"fluent": "^0.6.4",
"fast-crc32c": "^1.0.4",
"fluent-langneg": "^0.1.0",
"helmet": "^3.13.0",
"mkdirp": "^0.5.1",

View File

@ -9,6 +9,11 @@ const conf = convict({
default: '',
env: 'S3_BUCKET'
},
gcs_bucket: {
format: String,
default: '',
env: 'GCS_BUCKET'
},
redis_host: {
format: String,
default: 'localhost',

37
server/storage/gcs.js Normal file
View File

@ -0,0 +1,37 @@
const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
class GCSStorage {
constructor(config, log) {
this.bucket = storage.bucket(config.gcs_bucket);
this.log = log;
}
async length(id) {
const data = await this.bucket.file(id).getMetadata();
return data[0].size;
}
getStream(id) {
return this.bucket.file(id).createReadStream();
}
set(id, file) {
return new Promise((resolve, reject) => {
file
.pipe(this.bucket.file(id).createWriteStream())
.on('error', reject)
.on('finish', resolve);
});
}
del(id) {
return this.bucket.file(id).delete();
}
ping() {
return this.bucket.exists();
}
}
module.exports = GCSStorage;

View File

@ -5,7 +5,14 @@ const createRedisClient = require('./redis');
class DB {
constructor(config) {
const Storage = config.s3_bucket ? require('./s3') : require('./fs');
let Storage = null;
if (config.s3_bucket) {
Storage = require('./s3');
} else if (config.gcs_bucket) {
Storage = require('./gcs');
} else {
Storage = require('./fs');
}
this.log = mozlog('send.storage');
this.expireSeconds = config.expire_seconds;
this.storage = new Storage(config, this.log);