stubbed in gcs (untested)
This commit is contained in:
parent
d87fb64390
commit
9e8e604024
5 changed files with 1544 additions and 1180 deletions
37
server/storage/gcs.js
Normal file
37
server/storage/gcs.js
Normal 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;
|
|
@ -9,7 +9,14 @@ function getPrefix(seconds) {
|
|||
|
||||
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.storage = new Storage(config, this.log);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue