2018-01-11 01:30:17 +01:00
|
|
|
module.exports = {
|
|
|
|
validateFile (file) {
|
|
|
|
if (!file) {
|
|
|
|
console.log('no file found');
|
|
|
|
throw new Error('no file provided');
|
|
|
|
}
|
|
|
|
if (/'/.test(file.name)) {
|
|
|
|
console.log('file name had apostrophe in it');
|
|
|
|
throw new Error('apostrophes are not allowed in the file name');
|
|
|
|
}
|
|
|
|
// validate size and type
|
|
|
|
switch (file.type) {
|
|
|
|
case 'image/jpeg':
|
|
|
|
case 'image/jpg':
|
|
|
|
case 'image/png':
|
|
|
|
if (file.size > 10000000) {
|
|
|
|
console.log('file was too big');
|
|
|
|
throw new Error('Sorry, images are limited to 10 megabytes.');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'image/gif':
|
|
|
|
if (file.size > 50000000) {
|
|
|
|
console.log('file was too big');
|
2018-01-18 19:13:51 +01:00
|
|
|
throw new Error('Sorry, GIFs are limited to 50 megabytes.');
|
2018-01-11 01:30:17 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'video/mp4':
|
|
|
|
if (file.size > 50000000) {
|
|
|
|
console.log('file was too big');
|
|
|
|
throw new Error('Sorry, videos are limited to 50 megabytes.');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
console.log('file type is not supported');
|
|
|
|
throw new Error(file.type + ' is not a supported file type. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.');
|
|
|
|
}
|
|
|
|
},
|
2018-02-22 02:02:57 +01:00
|
|
|
};
|