Skip to content

Commit 1cfbb96

Browse files
committed
remove: use params helper like the other functions
Signed-off-by: William Casarin <jb55@jb55.com>
1 parent a1e52be commit 1cfbb96

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

index.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,27 @@ S3BlobStore.prototype.createReadStream = function (opts) {
4141
return stream;
4242
};
4343

44-
S3BlobStore.prototype.uploadParams = function (opts) {
44+
S3BlobStore.prototype.baseParams = function (opts) {
4545
opts = Object.assign({}, opts, {
4646
params: Object.assign({}, opts.params)
4747
});
4848

49-
var filename = opts.name || opts.filename;
50-
var key = opts.key || filename;
51-
var contentType = opts.contentType;
49+
const filename = opts.name || opts.filename;
50+
const key = opts.key || filename;
51+
let params = opts.params;
5252

53-
var params = opts.params;
5453
params.Bucket = params.Bucket || this.bucket;
5554
params.Key = params.Key || key;
5655

56+
return params
57+
}
58+
59+
S3BlobStore.prototype.uploadParams = function (opts) {
60+
const params = this.baseParams(opts)
61+
62+
const filename = opts.name || opts.filename || params.Key;
63+
let contentType = opts.contentType;
64+
5765
if (!contentType) {
5866
contentType = filename ? mime.lookup(filename) : mime.lookup(opts.key);
5967
}
@@ -63,9 +71,7 @@ S3BlobStore.prototype.uploadParams = function (opts) {
6371
};
6472

6573
S3BlobStore.prototype.downloadParams = function (opts) {
66-
var params = this.uploadParams(opts);
67-
delete params.ContentType;
68-
return params;
74+
return this.baseParams(opts);
6975
};
7076

7177
/**
@@ -99,8 +105,8 @@ S3BlobStore.prototype.createWriteStream = function (opts, s3opts, done) {
99105
* @param {function(Error)} done callback
100106
*/
101107
S3BlobStore.prototype.remove = function (opts, done) {
102-
var key = typeof opts === 'string' ? opts : opts.key;
103-
this.s3.deleteObject({ Bucket: this.bucket, Key: key }, done);
108+
const params = this.baseParams(opts)
109+
this.s3.deleteObject(params, done);
104110
return this;
105111
};
106112

0 commit comments

Comments
 (0)