1313flask_cors .CORS (routes )
1414
1515
16+ schemas = os .path .join (os .path .dirname (__file__ ), "schemas" )
17+
1618with open (
17- "src/opengeodeweb_back/routes/ schemas/ allowed_files.json" ,
19+ os . path . join ( schemas , " allowed_files.json") ,
1820 "r" ,
1921) as file :
2022 allowed_files_json = json .load (file )
@@ -31,7 +33,7 @@ def allowed_files():
3133
3234
3335with open (
34- "src/opengeodeweb_back/routes/ schemas/ upload_file.json" ,
36+ os . path . join ( schemas , " upload_file.json") ,
3537 "r" ,
3638) as file :
3739 upload_file_json = json .load (file )
@@ -48,17 +50,14 @@ def upload_file():
4850 UPLOAD_FOLDER = flask .current_app .config ["UPLOAD_FOLDER" ]
4951 if not os .path .exists (UPLOAD_FOLDER ):
5052 os .mkdir (UPLOAD_FOLDER )
51- files = flask .request .files .getlist ("content" )
52-
53- for file in files :
54- filename = werkzeug .utils .secure_filename (os .path .basename (file .filename ))
55- print (f"{ filename = } " )
56- file .save (os .path .join (UPLOAD_FOLDER , filename ))
53+ file = flask .request .files ["file" ]
54+ filename = werkzeug .utils .secure_filename (os .path .basename (file .filename ))
55+ file .save (os .path .join (UPLOAD_FOLDER , filename ))
5756 return flask .make_response ({"message" : "File uploaded" }, 201 )
5857
5958
6059with open (
61- "src/opengeodeweb_back/routes/ schemas/ allowed_objects.json" ,
60+ os . path . join ( schemas , " allowed_objects.json") ,
6261 "r" ,
6362) as file :
6463 allowed_objects_json = json .load (file )
@@ -69,17 +68,20 @@ def upload_file():
6968 methods = allowed_objects_json ["methods" ],
7069)
7170def allowed_objects ():
71+ if flask .request .method == "OPTIONS" :
72+ return flask .make_response ({}, 200 )
73+
74+ UPLOAD_FOLDER = flask .current_app .config ["UPLOAD_FOLDER" ]
7275 geode_functions .validate_request (flask .request , allowed_objects_json )
73- file_extension = os .path .splitext ( flask .request .json ["filename" ])[ 1 ][ 1 :]
76+ file_absolute_path = os .path .join ( UPLOAD_FOLDER , flask .request .json ["filename" ])
7477 allowed_objects = geode_functions .list_geode_objects (
75- file_extension , flask .request .json ["key" ]
78+ file_absolute_path , flask .request .json ["key" ]
7679 )
77-
7880 return flask .make_response ({"allowed_objects" : allowed_objects }, 200 )
7981
8082
8183with open (
82- "src/opengeodeweb_back/routes/ schemas/ missing_files.json" ,
84+ os . path . join ( schemas , " missing_files.json") ,
8385 "r" ,
8486) as file :
8587 missing_files_json = json .load (file )
@@ -98,29 +100,27 @@ def missing_files():
98100 os .path .join (UPLOAD_FOLDER , flask .request .json ["filename" ]),
99101 )
100102 has_missing_files = missing_files .has_missing_files ()
101- mandatory_files = missing_files .mandatory_files
102- additional_files = missing_files .additional_files
103103
104- mandatory_files_list = []
105- for mandatory_file in mandatory_files :
106- mandatory_files_list .append (os .path .basename (mandatory_file ))
104+ mandatory_files = []
105+ for mandatory_file in missing_files . mandatory_files :
106+ mandatory_files .append (os .path .basename (mandatory_file ))
107107
108- additional_files_list = []
109- for additional_file in additional_files :
110- additional_files_list .append (os .path .basename (additional_file ))
108+ additional_files = []
109+ for additional_file in missing_files . additional_files :
110+ additional_files .append (os .path .basename (additional_file ))
111111
112112 return flask .make_response (
113113 {
114114 "has_missing_files" : has_missing_files ,
115- "mandatory_files" : mandatory_files_list ,
116- "additional_files" : additional_files_list ,
115+ "mandatory_files" : mandatory_files ,
116+ "additional_files" : additional_files ,
117117 },
118118 200 ,
119119 )
120120
121121
122122with open (
123- "src/opengeodeweb_back/routes/ schemas/ geographic_coordinate_systems.json" ,
123+ os . path . join ( schemas , " geographic_coordinate_systems.json") ,
124124 "r" ,
125125) as file :
126126 geographic_coordinate_systems_json = json .load (file )
@@ -148,7 +148,7 @@ def crs_converter_geographic_coordinate_systems():
148148
149149
150150with open (
151- "src/opengeodeweb_back/routes/ schemas/ geode_objects_and_output_extensions.json" ,
151+ os . path . join ( schemas , " geode_objects_and_output_extensions.json") ,
152152 "r" ,
153153) as file :
154154 geode_objects_and_output_extensions_json = json .load (file )
@@ -160,25 +160,18 @@ def crs_converter_geographic_coordinate_systems():
160160)
161161def geode_objects_and_output_extensions ():
162162 UPLOAD_FOLDER = flask .current_app .config ["UPLOAD_FOLDER" ]
163-
164163 geode_functions .validate_request (
165164 flask .request , geode_objects_and_output_extensions_json
166165 )
167-
168166 data = geode_functions .load (
169167 flask .request .json ["input_geode_object" ],
170- os .path .join (
171- os .path .abspath (UPLOAD_FOLDER ),
172- flask .request .json ["filename" ],
173- ),
168+ os .path .join (UPLOAD_FOLDER , flask .request .json ["filename" ]),
174169 )
175170 geode_objects_and_output_extensions = (
176171 geode_functions .geode_objects_output_extensions (
177172 flask .request .json ["input_geode_object" ], data
178173 )
179174 )
180-
181- print (geode_objects_and_output_extensions )
182175 return flask .make_response (
183176 {"geode_objects_and_output_extensions" : geode_objects_and_output_extensions },
184177 200 ,
0 commit comments