Keep original filename during editing by using unique subfolders for downloads.
This commit is contained in:
@@ -254,9 +254,14 @@ class SharePointApp(ctk.CTk):
|
||||
res = requests.get(f"{base_url}/content", headers=self.headers)
|
||||
if res.status_code != 200:
|
||||
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(TEMP_DIR, f"{hashlib.md5(item_id.encode()).hexdigest()[:8]}{ext}")
|
||||
local_path = os.path.join(file_dir, file_name)
|
||||
|
||||
with open(local_path, 'wb') as f:
|
||||
f.write(res.content)
|
||||
|
||||
Reference in New Issue
Block a user