Comparing version 0.0.5 to 0.0.6
28
aws3.js
@@ -29,2 +29,4 @@ /* jshint laxcomma: true */ | ||
this.expirein = expirein || 3600; | ||
this.asattachment = false; // must be explicitly set eg. aws3.asattachment = true; | ||
} | ||
@@ -37,8 +39,7 @@ | ||
Aws3.prototype.generateSignedRequest = function(method, encoded) { | ||
var signature = this.signature(method); | ||
if (encoded) { | ||
signature = encodeURIComponent(signature); | ||
Aws3.prototype.attachable = function(method, delimiter) { | ||
if (method === 'get' && this.asattachment) { | ||
return delimiter+'response-content-disposition=attachment'; | ||
} | ||
return [this.fileUrl(), this.keyAndExpiresParams()+'&Signature='+signature].join('?'); | ||
return ''; | ||
}; | ||
@@ -51,2 +52,12 @@ | ||
Aws3.prototype.generateSignedRequest = function(method) { | ||
var signature = encodeURIComponent(this.signature(method)); | ||
return [this.fileUrl(), this.keyAndExpiresParams()+'&Signature='+signature+this.attachable(method, '&')].join('?'); | ||
}; | ||
/* | ||
* @api private | ||
*/ | ||
Aws3.prototype.payload = function(method) { | ||
@@ -58,3 +69,3 @@ var arr = [ | ||
, this.expiresIn() | ||
, this.bucketFilePath() | ||
, this.bucketFilePath()+this.attachable(method, '?') | ||
]; | ||
@@ -144,6 +155,5 @@ if (method === 'put') arr.splice(4, 0, this.amzAclHeader()); | ||
Aws3.prototype.signedUrl = function(method, encoded) { | ||
return this.generateSignedRequest(method, encoded); | ||
Aws3.prototype.signedUrl = function(method) { | ||
return this.generateSignedRequest(method); | ||
}; | ||
{ | ||
"name": "aws3.js", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "Simple AWS S3 Generator", | ||
@@ -5,0 +5,0 @@ "main": "aws3.js", |
@@ -78,5 +78,5 @@ /* jshint laxcomma: true */ | ||
function signature(str) { | ||
return crypto.createHmac('sha1', process.env.AWS_SECRET_ACCESS_KEY) | ||
return encodeURIComponent(crypto.createHmac('sha1', process.env.AWS_SECRET_ACCESS_KEY) | ||
.update(str) | ||
.digest('base64'); | ||
.digest('base64')); | ||
} | ||
@@ -105,2 +105,16 @@ | ||
it('can return a signed get request to download as an attachment', function() { | ||
aws3.asattachment = true; | ||
var arr = [ | ||
'GET' | ||
, '' | ||
, '' | ||
, one_hour_from_now() | ||
, '/aws3_bucket/abcd/large.txt?response-content-disposition=attachment' | ||
].join('\n'); | ||
assert.equal(aws3.signedUrl('get'), url()+'&Signature='+signature(arr)+'&response-content-disposition=attachment'); | ||
}); | ||
it('returns a signed put request', function() { | ||
@@ -107,0 +121,0 @@ var arr = [ |
7809
228