@@ -24,8 +24,8 @@ def upload_file():
24
24
uuid = request .form .get ("uuid" ) # Retrieve the UUID sent from the frontend
25
25
temp_folder = current_user .temp_folder ()
26
26
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
29
29
30
30
# Validate that the UUID is provided
31
31
if not uuid :
@@ -39,8 +39,6 @@ def upload_file():
39
39
40
40
# Generate a unique filename for the file
41
41
unique_filename = f"{ uuid } _{ file .filename } "
42
-
43
- # Define the temporary path for the file
44
42
temp_file_path = os .path .join (temp_folder , unique_filename )
45
43
46
44
# Save the file temporarily
@@ -49,26 +47,33 @@ def upload_file():
49
47
except Exception as e :
50
48
return jsonify ({"message" : f"Error saving file: { str (e )} " }), 500
51
49
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
66
72
67
- # If the file is valid, return the unique filename
68
73
return (
69
74
jsonify (
70
75
{
71
- "message" : "UVL uploaded and validated successfully" ,
76
+ "message" : f" { ext . upper () } uploaded successfully" ,
72
77
"filename" : unique_filename ,
73
78
}
74
79
),
0 commit comments