From cb12a052ace654cf6d60a0d888afb3fbe37593bb Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 16 Dec 2023 12:21:22 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E4=BF=AE=E5=A4=8D=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86=E6=97=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=B8=8D=E6=AD=A3=E7=A1=AE=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/transfer.py | 17 ++++++++--------- app/chain/transfer.py | 20 +++++++++++++++++++- version.py | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/app/api/endpoints/transfer.py b/app/api/endpoints/transfer.py index 6c6cf8a1..0652bea9 100644 --- a/app/api/endpoints/transfer.py +++ b/app/api/endpoints/transfer.py @@ -47,9 +47,11 @@ def manual_transfer(path: str = None, :param _: Token校验 """ force = False + target = Path(target) if target else None + transfer = TransferChain() if logid: # 查询历史记录 - history = TransferHistory.get(db, logid) + history: TransferHistory = TransferHistory.get(db, logid) if not history: return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}") # 强制转移 @@ -59,19 +61,16 @@ def manual_transfer(path: str = None, # 目的路径 if history.dest and str(history.dest) != "None": # 删除旧的已整理文件 - TransferChain().delete_files(Path(history.dest)) + transfer.delete_files(Path(history.dest)) if not target: - target = history.dest + target = transfer.get_root_path(path=history.dest, + type_name=history.type, + category=history.category) elif path: in_path = Path(path) else: return schemas.Response(success=False, message=f"缺少参数:path/logid") - if target and target != "None": - target = Path(target) - else: - target = None - # 类型 mtype = MediaType(type_name) if type_name else None # 自定义格式 @@ -84,7 +83,7 @@ def manual_transfer(path: str = None, offset=episode_offset, ) # 开始转移 - state, errormsg = TransferChain().manual_transfer( + state, errormsg = transfer.manual_transfer( in_path=in_path, target=target, tmdbid=tmdbid, diff --git a/app/chain/transfer.py b/app/chain/transfer.py index d1a00163..d1b48290 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -481,6 +481,24 @@ class TransferChain(ChainBase): text=errmsg, userid=userid)) return + @staticmethod + def get_root_path(path: str, type_name: str, category: str) -> Path: + """ + 计算媒体库目录的根路径 + """ + if not path or path == "None": + return None + index = -2 + if type_name != '电影': + index = -3 + if category: + index -= 1 + if '/' in path: + retpath = '/'.join(path.split('/')[:index]) + else: + retpath = '\\'.join(path.split('\\')[:index]) + return Path(retpath) + def re_transfer(self, logid: int, mtype: MediaType = None, mediaid: str = None) -> Tuple[bool, str]: """ @@ -498,7 +516,7 @@ class TransferChain(ChainBase): src_path = Path(history.src) if not src_path.exists(): return False, f"源目录不存在:{src_path}" - dest_path = Path(history.dest) if history.dest else None + dest_path = self.get_root_path(path=history.dest, type_name=history.type, category=history.category) # 查询媒体信息 if mtype and mediaid: mediainfo = self.recognize_media(mtype=mtype, tmdbid=int(mediaid) if str(mediaid).isdigit() else None, diff --git a/version.py b/version.py index f5905f25..574a0985 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -APP_VERSION = 'v1.5.1-1' +APP_VERSION = 'v1.5.2'