Improve environment variable stuff

This commit is contained in:
Jonathan Cremin 2015-08-30 18:35:05 +02:00
parent 760ee07a2e
commit 6ba174cff0
16 changed files with 66 additions and 64 deletions

View file

@ -3,17 +3,15 @@ import s3UploadStream from 's3-upload-stream';
import debugname from 'debug';
const debug = debugname('hostr:s3');
const bucket = process.env.AWS_BUCKET || 'hostrdotcodev';
const s3 = new aws.S3();
const s3Stream = s3UploadStream(s3);
export function get(key) {
debug('fetching file: %s', 'hostr_files/' + key);
return s3.getObject({Bucket: bucket, Key: 'hostr_files/' + key}).createReadStream();
debug('fetching from s3: %s', 'hostr_files/' + key);
return s3.getObject({Bucket: process.env.AWS_BUCKET, Key: 'hostr_files/' + key}).createReadStream();
}
export function upload(key) {
debug('Uploading file: %s', 'hostr_files/' + key);
return s3Stream.upload({Bucket: bucket, Key: 'hostr_files/' + key});
debug('sending to s3: %s', 'hostr_files/' + key);
return s3Stream.upload({Bucket: process.env.AWS_BUCKET, Key: 'hostr_files/' + key});
}