Keep original filename during editing by using unique subfolders for downloads.

This commit is contained in:
Martin Tranberg
2026-03-30 15:44:06 +02:00
parent 8def477647
commit b2d7f8f24f

View File

@@ -254,9 +254,14 @@ class SharePointApp(ctk.CTk):
res = requests.get(f"{base_url}/content", headers=self.headers) res = requests.get(f"{base_url}/content", headers=self.headers)
if res.status_code != 200: if res.status_code != 200:
raise Exception(f"Download fejlede: {res.status_code}") raise Exception(f"Download fejlede: {res.status_code}")
# Lav en unik undermappe til filen for at bevare det originale navn uden konflikter
short_hash = hashlib.md5(item_id.encode()).hexdigest()[:8]
file_dir = os.path.join(TEMP_DIR, short_hash)
if not os.path.exists(file_dir):
os.makedirs(file_dir)
ext = os.path.splitext(file_name)[1] local_path = os.path.join(file_dir, file_name)
local_path = os.path.join(TEMP_DIR, f"{hashlib.md5(item_id.encode()).hexdigest()[:8]}{ext}")
with open(local_path, 'wb') as f: with open(local_path, 'wb') as f:
f.write(res.content) f.write(res.content)