Skip to content

Commit

Permalink
#17: Fixes for directive content-disposition (specific to s3) and max…
Browse files Browse the repository at this point in the history
…Size (now limited by service).
  • Loading branch information
gsuess committed Dec 21, 2014
1 parent e98550d commit 178fbd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 8 additions & 9 deletions lib/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ Slingshot.Directive = function (service, directive) {

_.defaults(directive, service.directiveDefault);

check(directive, _.defaults({
check(directive, _.extend({
authorize: Function,
maxSize: Match.OneOf(Number, null),
maxSize: Match.Where(function (size) {
check(size, Match.OneOf(Number, null));

return !size || size > 0 && size <= (service.maxSize || Infinity);
}),
allowedFileTypes: matchAllowedFileTypes,
cdn: Match.Optional(String)
}, service.directiveMatch));
Expand Down Expand Up @@ -223,9 +227,8 @@ _.extend(Slingshot.Directive.prototype, {
*/

getInstructions: function (method, file, meta) {
var instructions = this.storageService().upload(method, _.extend({
contentDisposition: "inline; filename=" + quoteString(file.name, '"')
}, this._directive), file, meta);
var instructions = this.storageService().upload(method, this._directive,
file, meta);

check(instructions, {
upload: String,
Expand Down Expand Up @@ -302,7 +305,3 @@ function formatBytes(size) {
return (Math.round(size * 100) / 100) + " " + unit;
}


function quoteString(string, quotes) {
return quotes + string.replace(quotes, '\\' + quotes) + quotes;
}
7 changes: 6 additions & 1 deletion services/aws-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Slingshot.S3Storage = {
"acl": directive.acl,

"Cache-Control": directive.cacheControl,
"Content-Disposition": directive.contentDisposition
"Content-Disposition": directive.contentDisposition ||
"inline; filename=" + quoteString(file.name, '"')
},

bucketUrl = _.isFunction(directive.bucketUrl) ?
Expand Down Expand Up @@ -120,3 +121,7 @@ Slingshot.S3Storage = {
.digest("base64");
}
};

function quoteString(string, quotes) {
return quotes + string.replace(quotes, '\\' + quotes) + quotes;
}

0 comments on commit 178fbd5

Please sign in to comment.