Skip to content

Commit 1b08cf7

Browse files
committed
feat(save_viewable): Added function
1 parent 426dfab commit 1b08cf7

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

src/opengeodeweb_back/routes/blueprint_routes.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import flask_cors
88
from .. import geode_functions
99
import werkzeug
10+
import uuid
1011

1112

1213
routes = flask.Blueprint("routes", __name__)
@@ -204,3 +205,55 @@ def geode_objects_and_output_extensions():
204205
{"geode_objects_and_output_extensions": geode_objects_and_output_extensions},
205206
200,
206207
)
208+
209+
210+
with open(
211+
os.path.join(schemas, "save_viewable_file.json"),
212+
"r",
213+
) as file:
214+
save_viewable_file_json = json.load(file)
215+
216+
217+
@routes.route(
218+
save_viewable_file_json["route"],
219+
methods=save_viewable_file_json["methods"],
220+
)
221+
def save_viewable_file():
222+
UPLOAD_FOLDER = flask.current_app.config["UPLOAD_FOLDER"]
223+
secure_filename = werkzeug.utils.secure_filename(flask.request.json["filename"])
224+
file_path = os.path.abspath(os.path.join(UPLOAD_FOLDER, secure_filename))
225+
data = geode_functions.load(flask.request.json["input_geode_object"], file_path)
226+
generated_id = str(uuid.uuid4()).replace("-", "")
227+
228+
if geode_functions.is_viewable(flask.request.json["input_geode_object"]):
229+
name = data.name()
230+
else:
231+
name = flask.request.json["filename"]
232+
233+
native_extension = data.native_extension()
234+
235+
absolute_native_file_path = os.path.join(
236+
UPLOAD_FOLDER, generated_id + "." + native_extension
237+
)
238+
239+
saved_viewable_file_path = geode_functions.save_viewable(
240+
flask.request.json["input_geode_object"], data, UPLOAD_FOLDER, generated_id
241+
)
242+
geode_functions.save(
243+
flask.request.json["input_geode_object"],
244+
data,
245+
UPLOAD_FOLDER,
246+
generated_id + "." + native_extension,
247+
)
248+
249+
native_file_name = os.path.basename(absolute_native_file_path)
250+
viewable_file_name = os.path.basename(saved_viewable_file_path)
251+
return flask.make_response(
252+
{
253+
"name": name,
254+
"native_file_name": native_file_name,
255+
"viewable_file_name": viewable_file_name,
256+
"id": generated_id,
257+
},
258+
200,
259+
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"route": "/save_viewable_file",
3+
"methods": [
4+
"POST"
5+
],
6+
"type": "object",
7+
"properties": {
8+
"input_geode_object": {
9+
"type": "string"
10+
},
11+
"filename": {
12+
"type": "string"
13+
}
14+
},
15+
"required": [
16+
"input_geode_object",
17+
"filename"
18+
],
19+
"additionalProperties": false
20+
}

0 commit comments

Comments
 (0)