Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createDirective() copies restrictions into options, 2nd createDirective() doesn't overwrite them #233

Open
RealHandy opened this issue May 14, 2018 · 0 comments

Comments

@RealHandy
Copy link

I'm creating two different directives that differ only in their restrictions, so I do this:

let imageConfigs = {
  allowedFileTypes: ['image/png', 'image/jpeg', 'image/jpg', 'image/svg', 'image/gif', 'image/svg+xml'],
  maxSize: 10 * 1024 * 1024, // 10MB limit (use null for unlimited)
}
let docConfigs = {
  allowedFileTypes: null,
  maxSize: 100 * 1024 * 1024, // 100MB limit (use null for unlimited)
}

let baseConfigs = {
  bucket: Meteor.settings.S3Bucket,
  acl: 'private', 
  region: Meteor.settings.S3Region,
  authorize() {
    ...
  },
  key(file, metaContext) {
    ...
  }
}
let imageUploader = 'imageUploader';
let targetUploader = 'targetUploader';
Slingshot.fileRestrictions(imageUploader, {
  allowedFileTypes: imageConfigs.allowedFileTypes,
  maxSize: imageConfigs.maxSize
});
Slingshot.createDirective( imageUploader, Slingshot.S3Storage, baseConfigs );
Slingshot.fileRestrictions(targetUploader, {
  allowedFileTypes: docConfigs.allowedFileTypes,
  maxSize: docConfigs.maxSize
});
Slingshot.createDirective( targetUploader, Slingshot.S3Storage, baseConfigs );

In createDirective(), the use of _defaults() causes the baseConfigs object gets maxSize and allowedFileTypes written to it, so when I use baseConfigs in the 2nd createDirective() call, those (wrong) values are in baseConfigs, but _defaults() usage also causes the 2nd call to createDirective() not to overwrite the maxSize and allowedFileTypes, so the targetUploader directive ends up getting the same restrictions as the imageUploader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant