From cd6522b99c09c8c0d36f9937de4aca5367b408ee Mon Sep 17 00:00:00 2001 From: administrateur Date: Sat, 29 Mar 2025 18:43:33 +0100 Subject: [PATCH] fix: webdav secure --- script_creator.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/script_creator.py b/script_creator.py index 624b997..df86cb4 100644 --- a/script_creator.py +++ b/script_creator.py @@ -7,6 +7,24 @@ import redis import shutil from threading import Lock from webdav3.client import Client +from requests.structures import CaseInsensitiveDict +from webdav3.client import WebDavClient + +def safe_download_file(self, remote_path, local_path, progress=None, progress_args=()): + response = self.execute_request(action='download', path=remote_path, headers={'accept-encoding': 'identity'}) + total = response.headers.get('content-length') + if total is None: + log_debug(f"⚠️ Skipping file without content-length: {remote_path}") + return + total = int(total) + + with open(local_path, 'wb') as f: + for chunk in response.iter_content(chunk_size=1024): + if chunk: + f.write(chunk) + log_debug(f"✅ Downloaded file: {remote_path} → {local_path}") + +WebDavClient.download_file = safe_download_file app = Flask(__name__)