From bc8a243a6d8073026af53546ea53982db081a0fa Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 14 Oct 2023 13:05:00 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=95=B4=E5=90=88=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95Api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/history.py | 21 --------------------- app/api/endpoints/transfer.py | 26 +++++++++++++++++++++++--- app/chain/transfer.py | 6 +++--- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index 19a4ad13..ef98e257 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -11,7 +11,6 @@ from app.core.security import verify_token from app.db import get_db from app.db.models.downloadhistory import DownloadHistory from app.db.models.transferhistory import TransferHistory -from app.schemas import MediaType from app.schemas.types import EventType router = APIRouter() @@ -90,23 +89,3 @@ def delete_transfer_history(history_in: schemas.TransferHistory, # 删除记录 TransferHistory.delete(db, history_in.id) return schemas.Response(success=True) - - -@router.post("/transfer", summary="历史记录重新转移", response_model=schemas.Response) -def redo_transfer_history(history_in: schemas.TransferHistory, - mtype: str = None, - new_tmdbid: int = None, - db: Session = Depends(get_db), - _: schemas.TokenPayload = Depends(verify_token)) -> Any: - """ - 历史记录重新转移,不输入 mtype 和 new_tmdbid 时,自动使用文件名重新识别 - """ - if mtype and new_tmdbid: - state, errmsg = TransferChain(db).re_transfer(logid=history_in.id, - mtype=MediaType(mtype), tmdbid=new_tmdbid) - else: - state, errmsg = TransferChain(db).re_transfer(logid=history_in.id) - if state: - return schemas.Response(success=True) - else: - return schemas.Response(success=False, message=errmsg) diff --git a/app/api/endpoints/transfer.py b/app/api/endpoints/transfer.py index f743e755..3ecac9d4 100644 --- a/app/api/endpoints/transfer.py +++ b/app/api/endpoints/transfer.py @@ -8,13 +8,15 @@ from app import schemas from app.chain.transfer import TransferChain from app.core.security import verify_token from app.db import get_db +from app.db.models.transferhistory import TransferHistory from app.schemas import MediaType router = APIRouter() @router.post("/manual", summary="手动转移", response_model=schemas.Response) -def manual_transfer(path: str, +def manual_transfer(path: str = None, + logid: int = None, target: str = None, tmdbid: int = None, type_name: str = None, @@ -28,8 +30,9 @@ def manual_transfer(path: str, db: Session = Depends(get_db), _: schemas.TokenPayload = Depends(verify_token)) -> Any: """ - 手动转移,支持自定义剧集识别格式 + 手动转移,文件或历史记录,支持自定义剧集识别格式 :param path: 转移路径或文件 + :param logid: 转移历史记录ID :param target: 目标路径 :param type_name: 媒体类型、电影/电视剧 :param tmdbid: tmdbid @@ -43,7 +46,24 @@ def manual_transfer(path: str, :param db: 数据库 :param _: Token校验 """ - in_path = Path(path) + if logid: + # 查询历史记录 + history = TransferHistory.get(db, logid) + if not history: + return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}") + # 源路径 + in_path = Path(history.src) + # 目的路径 + if history.dest: + # 删除旧的已整理文件 + TransferChain(db).delete_files(Path(history.dest)) + if not target: + target = history.dest + elif path: + in_path = Path(path) + else: + return schemas.Response(success=False, message=f"缺少参数:path/logid") + if target: target = Path(target) if not target.exists(): diff --git a/app/chain/transfer.py b/app/chain/transfer.py index c217c96e..6d69934c 100644 --- a/app/chain/transfer.py +++ b/app/chain/transfer.py @@ -489,7 +489,7 @@ class TransferChain(ChainBase): def re_transfer(self, logid: int, mtype: MediaType = None, tmdbid: int = None) -> Tuple[bool, str]: """ - 根据历史记录,重新识别转移,只处理对应的src目录 + 根据历史记录,重新识别转移,只支持简单条件 :param logid: 历史记录ID :param mtype: 媒体类型 :param tmdbid: TMDB ID @@ -499,7 +499,7 @@ class TransferChain(ChainBase): if not history: logger.error(f"历史记录不存在,ID:{logid}") return False, "历史记录不存在" - # 没有下载记录,按源目录路径重新转移 + # 按源目录路径重新转移 src_path = Path(history.src) if not src_path.exists(): return False, f"源目录不存在:{src_path}" @@ -541,7 +541,7 @@ class TransferChain(ChainBase): epformat: EpisodeFormat = None, min_filesize: int = 0) -> Tuple[bool, Union[str, list]]: """ - 手动转移 + 手动转移,支持复杂条件,带进度显示 :param in_path: 源文件路径 :param target: 目标路径 :param tmdbid: TMDB ID