Skip to content
Snippets Groups Projects
Commit f791ceb9 authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

update file validation

parent 75b48d81
No related branches found
No related tags found
No related merge requests found
...@@ -35,6 +35,16 @@ const allowedFileTypes = [ ...@@ -35,6 +35,16 @@ const allowedFileTypes = [
'application/x-zip', '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 // in megabytes
const maxFileSize = 50; const maxFileSize = 50;
...@@ -211,7 +221,7 @@ class AddSolutionForm extends Component { ...@@ -211,7 +221,7 @@ class AddSolutionForm extends Component {
!description || !description ||
(!file (!file
? false ? false
: !allowedFileTypes.includes(file.type) || : validateFileName(file.name) ||
file.size > maxFileSize * 1024 ** 2) file.size > maxFileSize * 1024 ** 2)
} }
inverted inverted
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment