Skip to content

Commit

Permalink
fix transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Sep 19, 2024
1 parent f3b2bbf commit 4016295
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
4 changes: 2 additions & 2 deletions app/chain/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def check_login(self, storage: str, **kwargs) -> Optional[Tuple[dict, str]]:
"""
return self.run_module("check_login", storage=storage, **kwargs)

def list_files(self, fileitem: schemas.FileItem) -> Optional[List[schemas.FileItem]]:
def list_files(self, fileitem: schemas.FileItem, recursion: bool = False) -> Optional[List[schemas.FileItem]]:
"""
查询当前目录下所有目录和文件
"""
return self.run_module("list_files", fileitem=fileitem)
return self.run_module("list_files", fileitem=fileitem, recursion=recursion)

def create_folder(self, fileitem: schemas.FileItem, name: str) -> Optional[schemas.FileItem]:
"""
Expand Down
30 changes: 9 additions & 21 deletions app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,14 @@ def __do_transfer(self, fileitem: FileItem,
# 跳过数量
skip_num = 0

# 目录所有文件清单
transfer_files = self.storagechain.list_files(fileitem=fileitem)
if transfer_files:
# 过滤后缀和大小
transfer_files = [f for f in transfer_files
if (f".{f.extension.lower()}" in self.all_exts
and (not min_filesize or f.size > min_filesize * 1024 * 1024))]
if formaterHandler:
# 有集自定义格式,过滤文件
transfer_files = [f for f in transfer_files if formaterHandler.match(f.name)]
else:
return False, f"{fileitem.name} 没有找到可转移的媒体文件"

# 获取待转移路径清单
trans_items = self.__get_trans_fileitems(fileitem)
# 总文件数
total_num = len(transfer_files)
total_num = len(trans_items)
self.progress.update(value=0,
text=f"开始转移 {fileitem.path},共 {total_num} 个文件 ...",
text=f"开始转移 {fileitem.path},共 {total_num} 个文件或子目录 ...",
key=ProgressKey.FileTransfer)

# 获取待转移路径清单
trans_items = self.__get_trans_fileitems(fileitem)
if not trans_items:
logger.warn(f"{fileitem.path} 没有找到可转移的媒体文件")
return False, f"{fileitem.name} 没有找到可转移的媒体文件"
Expand All @@ -231,15 +218,16 @@ def __do_transfer(self, fileitem: FileItem,
# 如果是目录且不是⼀蓝光原盘,获取所有文件并转移
if (trans_item.type == "dir"
and not (trans_item.storage == "local" and not SystemUtils.is_bluray_dir(item_path))):
# 遍历获取下载目录所有文件
file_items = self.storagechain.list_files(trans_item)
# 遍历获取下载目录所有文件(递归)
file_items = self.storagechain.list_files(trans_item, recursion=True)
if not file_items:
continue
# 过滤后缀和大小
file_items = [f for f in file_items
if (f".{f.extension.lower()}" in self.all_exts
and (not min_filesize or f.size > min_filesize * 1024 * 1024))]
if f.extension and (f".{f.extension.lower()}" in self.all_exts
and (not min_filesize or f.size > min_filesize * 1024 * 1024))]
else:
# 文件或蓝光目录
file_items = [trans_item]

if formaterHandler:
Expand Down
26 changes: 23 additions & 3 deletions app/modules/filemanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,37 @@ def check_login(self, storage: str, **kwargs) -> Optional[Dict[str, str]]:
return None
return storage_oper.check_login(**kwargs)

def list_files(self, fileitem: FileItem) -> Optional[List[FileItem]]:
def list_files(self, fileitem: FileItem, recursion: bool = False) -> Optional[List[FileItem]]:
"""
浏览文件
:param fileitem: 源文件
:return: 文件列表
:param recursion: 是否递归,此时只浏览文件
:return: 文件项列表
"""
storage_oper = self.__get_storage_oper(fileitem.storage)
if not storage_oper:
logger.error(f"不支持 {fileitem.storage} 的文件浏览")
return None
return storage_oper.list(fileitem)

def __get_files(_item: FileItem, _r: bool = False):
"""
递归处理
"""
_items = storage_oper.list(_item)
if _items:
if _r:
for t in _items:
if t.type == "dir":
__get_files(t, _r)
else:
result.append(t)
else:
result.extend(_items)
# 返回结果
result = []
__get_files(fileitem, recursion)

return result

def create_folder(self, fileitem: FileItem, name: str) -> Optional[FileItem]:
"""
Expand Down

0 comments on commit 4016295

Please sign in to comment.