Refactor uploader
This commit is contained in:
parent
a1a39778aa
commit
6ec5f456f3
12 changed files with 647 additions and 261 deletions
18
lib/s3.js
18
lib/s3.js
|
@ -5,16 +5,10 @@ const debug = debugname('hostr:s3');
|
|||
const s3 = new aws.S3();
|
||||
|
||||
export function get(key) {
|
||||
debug('fetching from s3: %s', 'hostr_files/' + key);
|
||||
return s3.getObject({Bucket: process.env.AWS_BUCKET, Key: 'hostr_files/' + key}).createReadStream();
|
||||
}
|
||||
|
||||
export function upload(stream, key, callback) {
|
||||
debug('sending to s3: %s', 'hostr_files/' + key);
|
||||
const params = {Bucket: process.env.AWS_BUCKET, Key: 'hostr_files/' + key, Body: stream};
|
||||
const uploading = s3.upload(params);
|
||||
uploading.on('error', (err) => {
|
||||
console.log(err)
|
||||
});
|
||||
uploading.send(callback);
|
||||
let fullKey = `hostr_files/${key}`;
|
||||
if (key.substr(2, 5) === '970/' || key.substr(2, 5) === '150/') {
|
||||
fullKey = `hostr_files/${key.substr(2)}`;
|
||||
}
|
||||
debug('fetching from s3: %s', fullKey);
|
||||
return s3.getObject({ Bucket: process.env.AWS_BUCKET, Key: fullKey }).createReadStream();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue