mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix(input): updated file validation
This commit is contained in:
1 parent
6154a7109f
commit
deee62175f
1 file changed
+14
-12
@@ -20,18 +20,6 @@
|
||||
function setFiles(value: FileList) {
|
||||
if (!value) return;
|
||||
|
||||
const hasInvalidExt = Array.from(value).some((file) => {
|
||||
const fileExtension = file.name.split('.').pop();
|
||||
return allowedFileExtensions?.length
|
||||
? !allowedFileExtensions.includes(fileExtension)
|
||||
: false;
|
||||
});
|
||||
if (hasInvalidExt) {
|
||||
error = 'Invalid file extension';
|
||||
input.value = null;
|
||||
return;
|
||||
}
|
||||
|
||||
files = value;
|
||||
input.files = value;
|
||||
}
|
||||
@@ -79,6 +67,20 @@
|
||||
|
||||
const handleChange = (event: Event) => {
|
||||
const target = event.currentTarget as HTMLInputElement;
|
||||
|
||||
const isValidFiles = Array.from(target.files).every((file) => {
|
||||
const fileExtension = file.name.split('.').pop();
|
||||
return allowedFileExtensions?.length
|
||||
? allowedFileExtensions.includes(fileExtension)
|
||||
: true;
|
||||
});
|
||||
|
||||
if (!isValidFiles) {
|
||||
error = 'Invalid file extension';
|
||||
target.value = '';
|
||||
return;
|
||||
}
|
||||
|
||||
setFiles(target.files);
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in new issue
Block a user