diff --git a/src/components/forms/AddSolutionForm.js b/src/components/forms/AddSolutionForm.js index a853018098bc5bcc221ba4af51f6d1aac7aceb94..15d69396df73697f8471361f5822107637f4d7d1 100644 --- a/src/components/forms/AddSolutionForm.js +++ b/src/components/forms/AddSolutionForm.js @@ -35,6 +35,16 @@ const allowedFileTypes = [ 'application/x-zip', ]; +const allowedFileEnds = ['.zip', '.jpeg', '.jpg', '.jpe', '.png']; + +function validateFileName(fileNameToValidate) { + return ( + allowedFileEnds.find((typeName) => { + return fileNameToValidate.toLowerCase().endsWith(typeName); + }).length > 0 + ); +} + // in megabytes const maxFileSize = 50; @@ -211,7 +221,7 @@ class AddSolutionForm extends Component { !description || (!file ? false - : !allowedFileTypes.includes(file.type) || + : validateFileName(file.name) || file.size > maxFileSize * 1024 ** 2) } inverted