Fixed missing file type validation

This commit is contained in:
Max Nuding 2021-11-27 13:05:26 +01:00
parent 047088b622
commit 1ec2be5925
Signed by: phlaym
GPG Key ID: A06651BAB6777237

View File

@ -200,6 +200,19 @@ if (!isset($_POST['submit'])) {
return response; return response;
} }
function validateFileType(file) {
if (file.type && (file.type.startsWith('image/') || file.type.startsWith('video/'))) {
return true;
}
const parts = file.name.split('.');
const extension = parts.length > 0 ? parts[parts.length-1] : '';
if (['jpg', 'jpeg', 'png', 'heic', 'heif', 'mov', 'mp4', 'mkv'].includes(extension)) {
return true;
}
console.warn('Invalid file type', extension);
return false;
}
albumInput.addEventListener('change', (event) => { albumInput.addEventListener('change', (event) => {
console.log(event); console.log(event);
albumAnchor.href = `https://photos.phlaym.net${albumInput.selectedOptions[0].dataset.url}`; albumAnchor.href = `https://photos.phlaym.net${albumInput.selectedOptions[0].dataset.url}`;
@ -272,9 +285,11 @@ if (!isset($_POST['submit'])) {
sizeInMb, sizeInMb,
'MB big, which is over the limit of', 'MB big, which is over the limit of',
maxFileSize); maxFileSize);
} } else if(validateFileType(file)) {
fileList.push(file); fileList.push(file);
} }
}
} }
totalProgress.max = fileList.length; totalProgress.max = fileList.length;
@ -296,9 +311,12 @@ if (!isset($_POST['submit'])) {
? 'Die folgenden Dateien sind' ? 'Die folgenden Dateien sind'
: 'Die folgende Datei ist'; : 'Die folgende Datei ist';
errorDiv.innerHTML += ``` errorDiv.innerHTML += ```
${pluralizedMessage} zu groß: ${names}. ${pluralizedMessage} zu groß und wird beim Upload ignoriert: ${names}.
Jede Datei darf max. ${maxFileSize} MB groß sein.```; Jede Datei darf max. ${maxFileSize} MB groß sein.```;
}
if (!fileList.length) {
submitButton.disabled = true; submitButton.disabled = true;
errorDiv.innerHTML += 'Keine gültigen Bilder oder Videos gefunden';
} }
}); });
</script> </script>