From 7bb8fb028782f60578a12ab84b04ab9385e66e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Mon, 29 May 2023 23:16:56 +0200 Subject: [PATCH] Improve generated file's filename --- app/app.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/app.py b/app/app.py index d12d2ac..f222afa 100644 --- a/app/app.py +++ b/app/app.py @@ -85,13 +85,24 @@ async def generate_rest(name: str): break bytes_io.write(data) + out_filename = secure_filename(name) + + # a tester found that, if only special characters (like _) are sent to this method, it will return an + # empty string + # to improve UX, we replace empty strings with a _ + if not out_filename: + out_filename = "_" + + # to further improve the UX, let's add some prefix and the .stl suffix + out_filename = f"bottle-clip-{out_filename}.stl" + # using secure_filename allows us to send the file to the user with some safe yet reasonably # identifiable filename return await send_file( bytes_io, mimetype="model/stl", as_attachment=True, - attachment_filename=secure_filename(f"{name}.stl") + attachment_filename=out_filename, )