Keep original filename during editing by using unique subfolders for downloads.
This commit is contained in:
@@ -255,8 +255,13 @@ class SharePointApp(ctk.CTk):
|
|||||||
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}")
|
||||||
|
|
||||||
ext = os.path.splitext(file_name)[1]
|
# Lav en unik undermappe til filen for at bevare det originale navn uden konflikter
|
||||||
local_path = os.path.join(TEMP_DIR, f"{hashlib.md5(item_id.encode()).hexdigest()[:8]}{ext}")
|
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)
|
||||||
|
|
||||||
|
local_path = os.path.join(file_dir, file_name)
|
||||||
|
|
||||||
with open(local_path, 'wb') as f:
|
with open(local_path, 'wb') as f:
|
||||||
f.write(res.content)
|
f.write(res.content)
|
||||||
|
|||||||
Reference in New Issue
Block a user