Skip to content

Commit

Permalink
#32: Reverted the api and changed how restrictions are injected
Browse files Browse the repository at this point in the history
  • Loading branch information
Pagebakers committed Dec 29, 2014
1 parent 500dfed commit a4200a5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
18 changes: 6 additions & 12 deletions lib/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Slingshot.createDirective = function (name, service, options) {
_.defaults(options, restrictions);

return (Slingshot._directives[name] =
new Slingshot.Directive(name, service, options));
new Slingshot.Directive(service, options));
};

/**
Expand All @@ -97,11 +97,9 @@ Slingshot.getDirective = function (name) {
* @constructor
*/

Slingshot.Directive = function (name, service, directive) {
Slingshot.Directive = function (service, directive) {
check(this, Slingshot.Directive);

check(name, String);

//service does not have to be a plain-object, so checking fields individually
check(service.directiveMatch, Object);
check(service.upload, Function);
Expand All @@ -118,12 +116,6 @@ Slingshot.Directive = function (name, service, directive) {
contentDisposition: Match.Optional(Match.OneOf(String, null))
}, service.directiveMatch));

/**
* @public
* @property {String} The directive name
*/
this.name = name;

/**
* @method storageService
* @returns {Object}
Expand Down Expand Up @@ -174,8 +166,10 @@ _.extend(Slingshot.Directive.prototype, mixins, {
*/

getRestriction: function (restriction) {
return Slingshot.getRestrictions(this.name)[restriction] ||
this._directive[restriction];
var restrictions = _.pick(this._directive,
['authorize', 'maxSize', 'allowedFileTypes']
);
return restrictions[restriction];
}
});

Expand Down
7 changes: 7 additions & 0 deletions lib/restrictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Slingshot.fileRestrictions = function (name, restrictions) {
allowedFileTypes: Match.Optional(matchAllowedFileTypes),
});

if (Meteor.isServer) {
var directive = Slingshot.getDirective(name);
if (directive) {
_.extend(directive._directive, restrictions);
}
}

return (Slingshot._restrictions[name] =
_.extend(Slingshot._restrictions[name] || {}, restrictions));
};
Expand Down
2 changes: 1 addition & 1 deletion lib/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Slingshot.Upload = function (directive, metaData) {

var file = _.pick(self.file, "name", "size", "type");

status.set("authorizing");
status.set("validating");

var valid = this.validate(file);
if (valid !== true) {
Expand Down

0 comments on commit a4200a5

Please sign in to comment.