From 0d81105a0b3104adaf85d742814491e8ac481132 Mon Sep 17 00:00:00 2001 From: Edward <73746306+WangEdward@users.noreply.github.com> Date: Tue, 6 Feb 2024 18:05:45 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E4=B8=AD=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=97=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/transfer.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/api/endpoints/transfer.py b/app/api/endpoints/transfer.py index 0652bea9..9b499529 100644 --- a/app/api/endpoints/transfer.py +++ b/app/api/endpoints/transfer.py @@ -56,16 +56,20 @@ def manual_transfer(path: str = None, return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}") # 强制转移 force = True - # 源路径 - in_path = Path(history.src) - # 目的路径 - if history.dest and str(history.dest) != "None": - # 删除旧的已整理文件 - transfer.delete_files(Path(history.dest)) - if not target: - target = transfer.get_root_path(path=history.dest, - type_name=history.type, - category=history.category) + if history.status: + # 重新整理成功的转移,则使用成功的 dest 做 in_path + in_path = Path(history.dest) + else: + # 源路径 + in_path = Path(history.src) + # 目的路径 + if history.dest and str(history.dest) != "None": + # 删除旧的已整理文件 + transfer.delete_files(Path(history.dest)) + if not target: + target = transfer.get_root_path(path=history.dest, + type_name=history.type, + category=history.category) elif path: in_path = Path(path) else: From 5851673b438f8828739686519a03a310a43fafc3 Mon Sep 17 00:00:00 2001 From: Edward <73746306+WangEdward@users.noreply.github.com> Date: Tue, 6 Feb 2024 21:07:57 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E9=87=8D=E6=96=B0=E6=95=B4=E7=90=86?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/transfer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api/endpoints/transfer.py b/app/api/endpoints/transfer.py index 9b499529..b98de963 100644 --- a/app/api/endpoints/transfer.py +++ b/app/api/endpoints/transfer.py @@ -37,7 +37,7 @@ def manual_transfer(path: str = None, :param type_name: 媒体类型、电影/电视剧 :param tmdbid: tmdbid :param season: 剧集季号 - :param transfer_type: 转移类型,move/copy + :param transfer_type: 转移类型,move/copy 等 :param episode_format: 剧集识别格式 :param episode_detail: 剧集识别详细信息 :param episode_part: 剧集识别分集信息 @@ -56,7 +56,7 @@ def manual_transfer(path: str = None, return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}") # 强制转移 force = True - if history.status: + if history.status and ("move" in history.mode): # 重新整理成功的转移,则使用成功的 dest 做 in_path in_path = Path(history.dest) else: From 7350216fc4024ff4008256538ebe79375977a678 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AE=E5=8F=AE=E5=BD=93?= <604054726@qq.com> Date: Thu, 8 Feb 2024 00:09:20 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E7=AA=97=E5=8F=A3=E6=89=93?= =?UTF-8?q?=E5=BC=80=E5=85=A8=E9=83=A8=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/system.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/app/api/endpoints/system.py b/app/api/endpoints/system.py index 8cc18f1b..41746945 100644 --- a/app/api/endpoints/system.py +++ b/app/api/endpoints/system.py @@ -123,9 +123,11 @@ def get_message(token: str): @router.get("/logging", summary="实时日志") -def get_logging(token: str): +def get_logging(token: str, length: int = 50): """ - 实时获取系统日志,返回格式为SSE + 实时获取系统日志 + length = -1 时, 返回text/plain + 否则 返回格式SSE """ if not token or not verify_token(token): raise HTTPException( @@ -133,18 +135,26 @@ def get_logging(token: str): detail="认证失败!", ) + log_path = settings.LOG_PATH / 'moviepilot.log' def log_generator(): - log_path = settings.LOG_PATH / 'moviepilot.log' # 读取文件末尾50行,不使用tailer模块 with open(log_path, 'r', encoding='utf-8') as f: - for line in f.readlines()[-50:]: + for line in f.readlines()[-max(length, 50):]: yield 'data: %s\n\n' % line while True: for text in tailer.follow(open(log_path, 'r', encoding='utf-8')): yield 'data: %s\n\n' % (text or '') time.sleep(1) - return StreamingResponse(log_generator(), media_type="text/event-stream") + # 根据length参数返回不同的响应 + if length == -1: + # 返回全部日志作为文本响应 + with open(log_path, 'r', encoding='utf-8') as f: + text = f.read() + return Response(content=text, media_type="text/plain") + else: + # 返回SSE流响应 + return StreamingResponse(log_generator(), media_type="text/event-stream") @router.get("/nettest", summary="测试网络连通性")