From 9dec4d704be9b6147a551251dec4245a647c4370 Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sat, 23 Nov 2024 22:10:05 +0800 Subject: [PATCH 1/3] =?UTF-8?q?`get=5Fdir`=E5=8E=BB=E9=99=A4`fileitem`?= =?UTF-8?q?=E5=8F=82=E6=95=B0=20-=20=E5=92=8C`src=5Fpath=20&=20storage`?= =?UTF-8?q?=E9=87=8D=E5=A4=8D,=20=E9=9C=80=E8=A6=81=E7=9A=84=E8=AF=9D?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5=E4=BC=A0=E5=85=A5=E8=BF=99=E4=B8=A4=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helper/directory.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/helper/directory.py b/app/helper/directory.py index d5cd0761..6731ed62 100644 --- a/app/helper/directory.py +++ b/app/helper/directory.py @@ -50,8 +50,8 @@ class DirectoryHelper: return [d for d in self.get_library_dirs() if d.library_storage == "local"] def get_dir(self, media: MediaInfo, - storage: str = "local", fileitem: schemas.FileItem = None, src_path: Path = None, - target_storage: str = "local", dest_path: Path = None + storage: str = None, src_path: Path = None, + target_storage: str = None, dest_path: Path = None ) -> Optional[schemas.TransferDirectoryConf]: """ 根据媒体信息获取下载目录、媒体库目录配置 @@ -69,7 +69,7 @@ class DirectoryHelper: media_type = media.type.value dirs = self.get_dirs() # 已匹配的目录 - matched_dirs = [] + matched_dirs: List[schemas.TransferDirectoryConf] = [] # 按照配置顺序查找 for d in dirs: # 没有启用整理的目录 @@ -81,17 +81,11 @@ class DirectoryHelper: # 目标存储类型不匹配 if target_storage and d.library_storage != target_storage: continue - # 有文件项时,源存储不匹配 - if fileitem and fileitem.storage != d.storage: - continue - # 有文件项时,文件项不匹配下载目录 - if fileitem and not Path(fileitem.path).is_relative_to(d.download_path): - continue # 有源目录时,源目录不匹配下载目录 if src_path and not src_path.is_relative_to(d.download_path): continue # 有目标目录时,目标目录不匹配媒体库目录 - if dest_path and not dest_path.is_relative_to(d.library_path): + if dest_path and dest_path != Path(d.library_path): continue # 目录类型为全部的,符合条件 if not d.media_type: From 85324acacc1aa6b5f46281f9a6dfc08cf1b8b313 Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sat, 23 Nov 2024 22:17:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=B8=AD`get=5Fdir()`=E6=B7=BB=E5=8A=A0`storage=3D"local"`?= =?UTF-8?q?=E5=85=A5=E5=8F=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/chain/download.py b/app/chain/download.py index 2b5db0c6..20913b4e 100644 --- a/app/chain/download.py +++ b/app/chain/download.py @@ -256,7 +256,7 @@ class DownloadChain(ChainBase): download_dir = Path(save_path) else: # 根据媒体信息查询下载目录配置 - dir_info = self.directoryhelper.get_dir(_media) + dir_info = self.directoryhelper.get_dir(_media, storage="local") # 拼装子目录 if dir_info: # 一级目录 From fccbe39547d491d322c9ca4e9affe10b91a441d3 Mon Sep 17 00:00:00 2001 From: Attente <19653207+wikrin@users.noreply.github.com> Date: Sat, 23 Nov 2024 22:39:53 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9`target=5Fdirectory`?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chain/transfer.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/chain/transfer.py b/app/chain/transfer.py index 44bc8aa1..206240b3 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -392,13 +392,19 @@ class TransferChain(ChainBase): download_hash = download_file.download_hash # 查询整理目标目录 - if not target_directory and not target_path: + if not target_directory: if src_match: # 按源目录匹配,以便找到更合适的目录配置 - target_directory = self.directoryhelper.get_dir(file_mediainfo, + target_directory = self.directoryhelper.get_dir(media=file_mediainfo, storage=file_item.storage, src_path=file_path, target_storage=target_storage) + elif target_path: + # 指定目标路径,`手动整理`场景下使用,忽略源目录匹配,使用指定目录匹配 + target_directory = self.directoryhelper.get_dir(media=file_mediainfo, + storage=target_storage, + target_path=target_path, + target_storage=target_storage) else: # 未指定目标路径,根据媒体信息获取目标目录 target_directory = self.directoryhelper.get_dir(file_mediainfo,