Skip to content

Commit

Permalink
- 修复历史记录重新整理时路径不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Dec 16, 2023
1 parent 995c359 commit cb12a05
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
17 changes: 8 additions & 9 deletions app/api/endpoints/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
# 强制转移
Expand All @@ -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
# 自定义格式
Expand All @@ -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,
Expand Down
20 changes: 19 additions & 1 deletion app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,24 @@ def args_error():
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]:
"""
Expand All @@ -498,7 +516,7 @@ def re_transfer(self, logid: int, mtype: MediaType = None,
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,
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
APP_VERSION = 'v1.5.1-1'
APP_VERSION = 'v1.5.2'

0 comments on commit cb12a05

Please sign in to comment.