Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
9521a3ef09
@ -123,9 +123,11 @@ def get_message(token: str):
|
|||||||
|
|
||||||
|
|
||||||
@router.get("/logging", summary="实时日志")
|
@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):
|
if not token or not verify_token(token):
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
@ -133,18 +135,26 @@ def get_logging(token: str):
|
|||||||
detail="认证失败!",
|
detail="认证失败!",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
log_path = settings.LOG_PATH / 'moviepilot.log'
|
||||||
def log_generator():
|
def log_generator():
|
||||||
log_path = settings.LOG_PATH / 'moviepilot.log'
|
|
||||||
# 读取文件末尾50行,不使用tailer模块
|
# 读取文件末尾50行,不使用tailer模块
|
||||||
with open(log_path, 'r', encoding='utf-8') as f:
|
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
|
yield 'data: %s\n\n' % line
|
||||||
while True:
|
while True:
|
||||||
for text in tailer.follow(open(log_path, 'r', encoding='utf-8')):
|
for text in tailer.follow(open(log_path, 'r', encoding='utf-8')):
|
||||||
yield 'data: %s\n\n' % (text or '')
|
yield 'data: %s\n\n' % (text or '')
|
||||||
time.sleep(1)
|
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="测试网络连通性")
|
@router.get("/nettest", summary="测试网络连通性")
|
||||||
|
@ -37,7 +37,7 @@ def manual_transfer(path: str = None,
|
|||||||
:param type_name: 媒体类型、电影/电视剧
|
:param type_name: 媒体类型、电影/电视剧
|
||||||
:param tmdbid: tmdbid
|
:param tmdbid: tmdbid
|
||||||
:param season: 剧集季号
|
:param season: 剧集季号
|
||||||
:param transfer_type: 转移类型,move/copy
|
:param transfer_type: 转移类型,move/copy 等
|
||||||
:param episode_format: 剧集识别格式
|
:param episode_format: 剧集识别格式
|
||||||
:param episode_detail: 剧集识别详细信息
|
:param episode_detail: 剧集识别详细信息
|
||||||
:param episode_part: 剧集识别分集信息
|
:param episode_part: 剧集识别分集信息
|
||||||
@ -56,16 +56,20 @@ def manual_transfer(path: str = None,
|
|||||||
return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}")
|
return schemas.Response(success=False, message=f"历史记录不存在,ID:{logid}")
|
||||||
# 强制转移
|
# 强制转移
|
||||||
force = True
|
force = True
|
||||||
# 源路径
|
if history.status and ("move" in history.mode):
|
||||||
in_path = Path(history.src)
|
# 重新整理成功的转移,则使用成功的 dest 做 in_path
|
||||||
# 目的路径
|
in_path = Path(history.dest)
|
||||||
if history.dest and str(history.dest) != "None":
|
else:
|
||||||
# 删除旧的已整理文件
|
# 源路径
|
||||||
transfer.delete_files(Path(history.dest))
|
in_path = Path(history.src)
|
||||||
if not target:
|
# 目的路径
|
||||||
target = transfer.get_root_path(path=history.dest,
|
if history.dest and str(history.dest) != "None":
|
||||||
type_name=history.type,
|
# 删除旧的已整理文件
|
||||||
category=history.category)
|
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:
|
elif path:
|
||||||
in_path = Path(path)
|
in_path = Path(path)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user