added check for file name in publish requests
This commit is contained in:
parent
57c08fd3ad
commit
93d23a3721
2 changed files with 12 additions and 1 deletions
|
@ -12,9 +12,18 @@ const parsePublishApiRequestFiles = ({file, thumbnail}) => {
|
|||
throw new Error('no file type found');
|
||||
}
|
||||
if (!file.size) {
|
||||
throw new Error('no file type found');
|
||||
throw new Error('no file size found');
|
||||
}
|
||||
// validate the file name
|
||||
if (!file.name) {
|
||||
throw new Error('no file name found');
|
||||
}
|
||||
if (file.name.indexOf('.') < 0) {
|
||||
throw new Error('no file extension found in file name');
|
||||
}
|
||||
if (file.name.indexOf('.') === 0) {
|
||||
throw new Error('file name cannot start with "."');
|
||||
}
|
||||
if (/'/.test(file.name)) {
|
||||
throw new Error('apostrophes are not allowed in the file name');
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const logger = require('winston');
|
||||
|
||||
const validateFileTypeAndSize = (file) => {
|
||||
logger.debug('FILE:', file);
|
||||
// check file type and size
|
||||
switch (file.type) {
|
||||
case 'image/jpeg':
|
||||
|
@ -27,6 +28,7 @@ const validateFileTypeAndSize = (file) => {
|
|||
logger.debug('publish > file validation > unrecognized file type');
|
||||
throw new Error('The ' + file.type + ' content type is not supported. Only, .jpeg, .png, .gif, and .mp4 files are currently supported.');
|
||||
}
|
||||
// check file name
|
||||
return file;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue