Skip to content

Commit

Permalink
restricted more files
Browse files Browse the repository at this point in the history
  • Loading branch information
rayb26 authored and ZhuoweiWen committed Oct 25, 2023
1 parent 7e20d10 commit 7ed3dba
Showing 1 changed file with 30 additions and 13 deletions.
43 changes: 30 additions & 13 deletions front-end/components/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,24 @@ export default function Upload({ generateChallenge }) {
const formData = new FormData();

files.forEach((fileDetails) => {
if (!fileDetails.file.name.toLowerCase().endsWith("kml")) {
toast.error("Invalid File Format. Please upload a KML file.", {
position: toast.POSITION.TOP_RIGHT,
autoClose: 10000,
});
const allowedExtensions = ["kml", "geojson", "csv", "kmz"];
const fileExtension = fileDetails.file.name
.split(".")
.pop()
.toLowerCase();

if (!allowedExtensions.includes(fileExtension)) {
toast.error(
"Invalid File Format. Please upload a KML, GeoJSON, CSV, or KMZ file.",
{
position: toast.POSITION.TOP_RIGHT,
autoClose: 10000,
}
);

setIsLoading(false)
setIsLoading(false);
return;
}

formData.append("fileData", JSON.stringify(fileDetails));
formData.append("file", fileDetails.file);
});
Expand Down Expand Up @@ -157,13 +165,22 @@ export default function Upload({ generateChallenge }) {
const formData = new FormData();

files.forEach((fileDetails) => {
if (!fileDetails.file.name.toLowerCase().endsWith("kml")) {
toast.error("Invalid File Format. Please upload a KML file.", {
position: toast.POSITION.TOP_RIGHT,
autoClose: 10000,
});
setIsLoading(false)
const allowedExtensions = ["kml", "geojson", "csv", "kmz"];
const fileExtension = fileDetails.file.name
.split(".")
.pop()
.toLowerCase();

if (!allowedExtensions.includes(fileExtension)) {
toast.error(
"Invalid File Format. Please upload a KML, GeoJSON, CSV, or KMZ file.",
{
position: toast.POSITION.TOP_RIGHT,
autoClose: 10000,
}
);

setIsLoading(false);
return;
}
formData.append("fileData", JSON.stringify(fileDetails));
Expand Down

0 comments on commit 7ed3dba

Please sign in to comment.