Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,34 @@ S3BlobStore.prototype.createReadStream = function (opts) {
return stream;
};

S3BlobStore.prototype.uploadParams = function (opts) {
S3BlobStore.prototype.baseParams = function (opts) {
opts = Object.assign({}, opts, {
params: Object.assign({}, opts.params)
});

var filename = opts.name || opts.filename;
var key = opts.key || filename;
var contentType = opts.contentType;
const filename = opts.name || opts.filename;
const key = opts.key || filename;
let params = opts.params;

var params = opts.params;
params.Bucket = params.Bucket || this.bucket;
params.Key = params.Key || key;

if (!contentType) {
contentType = filename ? mime.lookup(filename) : mime.lookup(opts.key);
}
if (contentType) params.ContentType = contentType;
return params
}

S3BlobStore.prototype.uploadParams = function (opts) {
const params = this.baseParams(opts)
const filename = opts.name || opts.filename || params.Key;
let contentType = opts.contentType || mime.lookup(filename)
Comment on lines +61 to +62
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think filename is already present in params.Key,
as in baseParams function, you assign to params.Key either opts.name, opts.filename or opts.key.

Suggested change
const filename = opts.name || opts.filename || params.Key;
let contentType = opts.contentType || mime.lookup(filename)
const contentType = opts.contentType || mime.lookup(params.Key)

Also, as contentType is defined once, I think const is better than let ?


if (contentType)
params.ContentType = contentType

return params;
};

S3BlobStore.prototype.downloadParams = function (opts) {
var params = this.uploadParams(opts);
delete params.ContentType;
return params;
return this.baseParams(opts);
};

/**
Expand Down Expand Up @@ -99,8 +102,8 @@ S3BlobStore.prototype.createWriteStream = function (opts, s3opts, done) {
* @param {function(Error)} done callback
*/
S3BlobStore.prototype.remove = function (opts, done) {
var key = typeof opts === 'string' ? opts : opts.key;
this.s3.deleteObject({ Bucket: this.bucket, Key: key }, done);
const params = this.baseParams(opts)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to keep the typeof opts === 'string' test ?

Or test it in the baseParams function ?

As it is mentionned in https://github.com/maxogden/abstract-blob-store#storeremoveopts-cb,
the remove methods accept either a string (and that's the key) or an object.

this.s3.deleteObject(params, done);
return this;
};

Expand Down