Skip to content

Commit 233512e

Browse files
committed
feat: Upload ZIP folders
1 parent ce4ab68 commit 233512e

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

app/modules/dataset/templates/dataset/create_and_edit_dataset.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ <h2 class="fw-bold text-gray-900">Upload UVL files</h2>
235235
<div class="dropzone dropzone-queue mb-2" id="uvl_dropzone">
236236
<!--begin::Controls-->
237237
<div class="dropzone-panel mb-lg-0 mb-2">
238-
<h3 class="mb-10">Drag & drop your UVL files</h3>
239238
<a class="dropzone-select btn btn-sm btn-primary me-2">Attach files</a>
240239
<a id="clear-all-btn" href="javascript:void(0)" class="btn btn-sm btn-danger">Clear all</a>
241240
</div>
@@ -280,7 +279,7 @@ <h3 class="mb-10">Drag & drop your UVL files</h3>
280279
<!--end::Dropzone-->
281280

282281
<!--begin::Hint-->
283-
<span class="form-text text-muted">Max file size is 1MB and max number of files is 100.</span>
282+
<span class="form-text text-muted">Max file size is 100MB and max number of files is 20.</span>
284283
<!--end::Hint-->
285284

286285
<!--end::Col-->

app/modules/hubfile/routes.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def upload_file():
2424
uuid = request.form.get("uuid") # Retrieve the UUID sent from the frontend
2525
temp_folder = current_user.temp_folder()
2626

27-
if not file or not file.filename.endswith(".uvl"):
28-
return jsonify({"message": "No valid file"}), 400
27+
if not file:
28+
return jsonify({"message": "No file uploaded"}), 400
2929

3030
# Validate that the UUID is provided
3131
if not uuid:
@@ -39,8 +39,6 @@ def upload_file():
3939

4040
# Generate a unique filename for the file
4141
unique_filename = f"{uuid}_{file.filename}"
42-
43-
# Define the temporary path for the file
4442
temp_file_path = os.path.join(temp_folder, unique_filename)
4543

4644
# Save the file temporarily
@@ -49,26 +47,33 @@ def upload_file():
4947
except Exception as e:
5048
return jsonify({"message": f"Error saving file: {str(e)}"}), 500
5149

52-
# Validate the UVL file using `check_uvl`
53-
try:
54-
validation_result, status_code = flamapy_service.check_uvl(temp_file_path)
55-
56-
if status_code != 200:
57-
# If the file is invalid, remove it and return an error
58-
os.remove(temp_file_path)
59-
return jsonify(validation_result), status_code
60-
61-
except Exception as e:
62-
# Remove the file if an unexpected error occurs during validation
63-
if os.path.exists(temp_file_path):
64-
os.remove(temp_file_path)
65-
return jsonify({"message": f"Error validating UVL: {str(e)}"}), 500
50+
ext = file.filename.lower().split(".")[-1]
51+
52+
if ext == "uvl":
53+
# Validate the UVL file
54+
try:
55+
validation_result, status_code = flamapy_service.check_uvl(temp_file_path)
56+
57+
if status_code != 200:
58+
os.remove(temp_file_path)
59+
return jsonify(validation_result), status_code
60+
except Exception as e:
61+
if os.path.exists(temp_file_path):
62+
os.remove(temp_file_path)
63+
return jsonify({"message": f"Error validating UVL: {str(e)}"}), 500
64+
65+
elif ext == "zip":
66+
# Do not validate ZIPs, just accept them
67+
pass
68+
else:
69+
# Unsupported extension
70+
os.remove(temp_file_path)
71+
return jsonify({"message": "Unsupported file type"}), 400
6672

67-
# If the file is valid, return the unique filename
6873
return (
6974
jsonify(
7075
{
71-
"message": "UVL uploaded and validated successfully",
76+
"message": f"{ext.upper()} uploaded successfully",
7277
"filename": unique_filename,
7378
}
7479
),

0 commit comments

Comments
 (0)