From 8fac8c530756865fed7e50a7d37c2acdde82e82d Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sun, 24 Aug 2025 16:33:44 +0800 Subject: [PATCH] fix progress step --- app/modules/filemanager/storages/__init__.py | 2 +- app/modules/filemanager/storages/alipan.py | 5 ++++- app/modules/filemanager/storages/alist.py | 4 +--- app/modules/filemanager/storages/local.py | 4 ++-- app/modules/filemanager/storages/smb.py | 13 +++++-------- app/modules/filemanager/storages/u115.py | 5 ++++- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/modules/filemanager/storages/__init__.py b/app/modules/filemanager/storages/__init__.py index dcc03aae..a3ec4ee3 100644 --- a/app/modules/filemanager/storages/__init__.py +++ b/app/modules/filemanager/storages/__init__.py @@ -14,7 +14,7 @@ def transfer_process(path: str) -> Callable[[int | float], None]: """ 传输进度回调 """ - pbar = tqdm(total=100, desc="整理进度", unit="%") + pbar = tqdm(total=100, desc="整理进度") progress = ProgressHelper(path) progress.start() diff --git a/app/modules/filemanager/storages/alipan.py b/app/modules/filemanager/storages/alipan.py index c141bdb5..58936df0 100644 --- a/app/modules/filemanager/storages/alipan.py +++ b/app/modules/filemanager/storages/alipan.py @@ -45,6 +45,9 @@ class AliPan(StorageBase, metaclass=WeakSingleton): # 基础url base_url = "https://openapi.alipan.com" + # 文件块大小,默认10MB + chunk_size = 10 * 1024 * 1024 + def __init__(self): super().__init__() self._auth_state = {} @@ -724,7 +727,7 @@ class AliPan(StorageBase, metaclass=WeakSingleton): downloaded_size = 0 with open(local_path, "wb") as f: - for chunk in r.iter_content(chunk_size=8192): + for chunk in r.iter_content(chunk_size=self.chunk_size): if chunk: f.write(chunk) downloaded_size += len(chunk) diff --git a/app/modules/filemanager/storages/alist.py b/app/modules/filemanager/storages/alist.py index e8ac0ae8..95b903ee 100644 --- a/app/modules/filemanager/storages/alist.py +++ b/app/modules/filemanager/storages/alist.py @@ -31,9 +31,7 @@ class Alist(StorageBase, metaclass=WeakSingleton): "move": "移动", } - # 文件块大小,默认1MB - chunk_size = 1024 * 1024 - + # 快照检查目录修改时间 snapshot_check_folder_modtime = settings.OPENLIST_SNAPSHOT_CHECK_FOLDER_MODTIME def __init__(self): diff --git a/app/modules/filemanager/storages/local.py b/app/modules/filemanager/storages/local.py index f1aaef5e..725f742d 100644 --- a/app/modules/filemanager/storages/local.py +++ b/app/modules/filemanager/storages/local.py @@ -25,8 +25,8 @@ class LocalStorage(StorageBase): "softlink": "软链接" } - # 文件块大小,默认1MB - chunk_size = 1024 * 1024 + # 文件块大小,默认100MB + chunk_size = 100 * 1024 * 1024 def init_storage(self): """ diff --git a/app/modules/filemanager/storages/smb.py b/app/modules/filemanager/storages/smb.py index 19f8bd8e..063b2129 100644 --- a/app/modules/filemanager/storages/smb.py +++ b/app/modules/filemanager/storages/smb.py @@ -39,6 +39,9 @@ class SMB(StorageBase, metaclass=WeakSingleton): "copy": "复制", } + # 文件块大小,默认100MB + chunk_size = 100 * 1024 * 1024 + def __init__(self): super().__init__() self._connected = False @@ -433,12 +436,9 @@ class SMB(StorageBase, metaclass=WeakSingleton): # 使用更高效的文件传输方式 with smbclient.open_file(smb_path, mode="rb") as src_file: with open(local_path, "wb") as dst_file: - # 使用更大的缓冲区提高性能 - buffer_size = 1024 * 1024 # 1MB downloaded_size = 0 - while True: - chunk = src_file.read(buffer_size) + chunk = src_file.read(self.chunk_size) if not chunk: break dst_file.write(chunk) @@ -483,12 +483,9 @@ class SMB(StorageBase, metaclass=WeakSingleton): # 使用更高效的文件传输方式 with open(path, "rb") as src_file: with smbclient.open_file(smb_path, mode="wb") as dst_file: - # 使用更大的缓冲区提高性能 - buffer_size = 1024 * 1024 # 1MB uploaded_size = 0 - while True: - chunk = src_file.read(buffer_size) + chunk = src_file.read(self.chunk_size) if not chunk: break dst_file.write(chunk) diff --git a/app/modules/filemanager/storages/u115.py b/app/modules/filemanager/storages/u115.py index 6905c70c..a149fafb 100644 --- a/app/modules/filemanager/storages/u115.py +++ b/app/modules/filemanager/storages/u115.py @@ -43,6 +43,9 @@ class U115Pan(StorageBase, metaclass=WeakSingleton): # 基础url base_url = "https://proapi.115.com" + # 文件块大小,默认10MB + chunk_size = 10 * 1024 * 1024 + def __init__(self): super().__init__() self._auth_state = {} @@ -610,7 +613,7 @@ class U115Pan(StorageBase, metaclass=WeakSingleton): downloaded_size = 0 with open(local_path, "wb") as f: - for chunk in r.iter_content(chunk_size=8192): + for chunk in r.iter_content(chunk_size=self.chunk_size): if chunk: f.write(chunk) downloaded_size += len(chunk)