1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-01 09:40:21 +01:00
haste-server/lib/document_stores/amazon-s3.js

55 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-08-26 04:54:58 +02:00
const AWS = require('aws-sdk');
const winston = require('winston');
2019-06-28 20:09:40 +02:00
2020-08-28 04:39:03 +02:00
const AmazonS3DocumentStore = function(options){
this.expire = options.expire;
this.bucket = options.bucket;
this.client = new AWS.S3({region: options.region});
};
AmazonS3DocumentStore.prototype.get = function(key, callback, skipExpire){
const _this = this;
const req = {
Bucket: _this.bucket,
Key: key
};
_this.client.getObject(req, function(err, data){
if(err){
callback(false);
}
else {
callback(data.Body.toString('utf-8'));
if (_this.expire && !skipExpire){
winston.warn('amazon s3 store cannot set expirations on keys');
}
}
});
2019-06-28 20:09:40 +02:00
};
2020-08-28 04:39:03 +02:00
AmazonS3DocumentStore.prototype.set = function(key, data, callback, skipExpire){
const _this = this;
const req = {
Bucket: _this.bucket,
Key: key,
Body: data,
ContentType: 'text/plain'
};
_this.client.putObject(req, function(err, data){
if (err){
callback(false);
}
else {
callback(true);
if (_this.expire && !skipExpire){
winston.warn('amazon s3 store cannot set expirations on keys');
}
}
});
};
2019-06-28 20:09:40 +02:00
module.exports = AmazonS3DocumentStore;