From c6c2766381f75b058fb61f91556788b0720b058b Mon Sep 17 00:00:00 2001
From: retoor <retoor@molodetz.nl>
Date: Tue, 11 Mar 2025 10:10:50 +0100
Subject: [PATCH] Added better file handling.

---
 src/snek/view/upload.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/snek/view/upload.py b/src/snek/view/upload.py
index f9bad33..8884d72 100644
--- a/src/snek/view/upload.py
+++ b/src/snek/view/upload.py
@@ -25,6 +25,7 @@ class UploadView(BaseView):
         drive_item = await self.services.drive_item.get(uid)
         response = web.FileResponse(drive_item["path"])
         response.headers['Cache-Control'] = f'public, max-age={1337*420}'
+        response.headers['Content-Disposition'] = f'attachment; filename="{drive_item["name"]}"'
         return response
 
     async def post(self):
@@ -57,8 +58,10 @@ class UploadView(BaseView):
             filename = field.filename
             if not filename:
                 continue
+            
+            name = str(uuid.uuid4()) + pathlib.Path(filename).suffix
 
-            file_path = pathlib.Path(UPLOAD_DIR).joinpath(filename.strip("/").strip("."))
+            file_path = pathlib.Path(UPLOAD_DIR).joinpath(name)
             files.append(file_path)
 
             async with aiofiles.open(str(file_path.absolute()), 'wb') as f: