createDirective() copies restrictions into options, 2nd createDirective() doesn't overwrite them
Opened this issue · 0 comments
RealHandy commented
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.