Skip to content

Commit

Permalink
fix scraping
Browse files Browse the repository at this point in the history
  • Loading branch information
jxxghp committed Sep 20, 2024
1 parent 91fc412 commit 117bd80
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
10 changes: 5 additions & 5 deletions app/api/endpoints/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from sqlalchemy.orm import Session

from app import schemas
from app.chain.transfer import TransferChain
from app.chain.storage import StorageChain
from app.core.event import eventmanager
from app.core.security import verify_token
from app.db import get_db
Expand Down Expand Up @@ -87,15 +87,15 @@ def delete_transfer_history(history_in: schemas.TransferHistory,
# 册除媒体库文件
if deletedest and history.dest_fileitem:
dest_fileitem = schemas.FileItem(**json.loads(history.dest_fileitem))
state, msg = TransferChain().delete_files(dest_fileitem)
state = StorageChain().delete_file(dest_fileitem)
if not state:
return schemas.Response(success=False, msg=msg)
return schemas.Response(success=False, msg=f"{dest_fileitem.path}删除失败")
# 删除源文件
if deletesrc and history.dest_fileitem:
dest_fileitem = schemas.FileItem(**json.loads(history.dest_fileitem))
state, msg = TransferChain().delete_files(dest_fileitem)
state = StorageChain().delete_file(dest_fileitem)
if not state:
return schemas.Response(success=False, msg=msg)
return schemas.Response(success=False, msg=f"{dest_fileitem.path}删除失败")
# 发送事件
eventmanager.send_event(
EventType.DownloadFileDeleted,
Expand Down
6 changes: 3 additions & 3 deletions app/api/endpoints/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from app import schemas
from app.chain.media import MediaChain
from app.chain.storage import StorageChain
from app.chain.transfer import TransferChain
from app.core.metainfo import MetaInfoPath
from app.core.security import verify_token, verify_apitoken
Expand Down Expand Up @@ -89,7 +90,6 @@ def manual_transfer(fileitem: FileItem = None,
"""
force = False
target_path = Path(target_path) if target_path else None
transfer = TransferChain()
if logid:
# 查询历史记录
history: TransferHistory = TransferHistory.get(db, logid)
Expand All @@ -107,7 +107,7 @@ def manual_transfer(fileitem: FileItem = None,
if history.dest_fileitem:
# 删除旧的已整理文件
dest_fileitem = FileItem(**json.loads(history.dest_fileitem))
transfer.delete_files(dest_fileitem)
StorageChain().delete_file(dest_fileitem)

# 从历史数据获取信息
if from_history:
Expand Down Expand Up @@ -144,7 +144,7 @@ def manual_transfer(fileitem: FileItem = None,
offset=episode_offset,
)
# 开始转移
state, errormsg = transfer.manual_transfer(
state, errormsg = TransferChain().manual_transfer(
fileitem=src_fileitem,
target_storage=target_storage,
target_path=target_path,
Expand Down
12 changes: 2 additions & 10 deletions app/chain/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def __do_transfer(self, fileitem: FileItem,
)

# 刮削元数据事件
if scrape:
if scrape or transferinfo.need_scrape:
self.eventmanager.send_event(EventType.MetadataScrape, {
'meta': file_meta,
'mediainfo': file_mediainfo,
Expand Down Expand Up @@ -599,7 +599,7 @@ def __re_transfer(self, logid: int, mtype: MediaType = None,
if history.dest_fileitem:
# 解析目标文件对象
dest_fileitem = FileItem(**json.loads(history.dest_fileitem))
self.delete_files(dest_fileitem)
self.storagechain.delete_file(dest_fileitem)

# 强制转移
if history.src_fileitem:
Expand Down Expand Up @@ -713,11 +713,3 @@ def send_transfer_message(self, meta: MetaBase, mediainfo: MediaInfo,
mtype=NotificationType.Organize,
title=msg_title, text=msg_str, image=mediainfo.get_message_image(),
link=settings.MP_DOMAIN('#/history')))

def delete_files(self, fileitem: FileItem) -> Tuple[bool, str]:
"""
TODO 删除转移后的文件以及空目录
:param fileitem: 文件项
:return: 成功标识,错误信息
"""
pass
2 changes: 1 addition & 1 deletion app/modules/filemanager/storages/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def delete(self, fileitem: schemas.FileItem) -> bool:
return False
path_obj = Path(fileitem.path)
if not path_obj.exists():
return False
return True
try:
if path_obj.is_file():
path_obj.unlink()
Expand Down
5 changes: 4 additions & 1 deletion app/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,10 @@ def __get_bluray_dir(_path: Path):
'transferinfo': transferinfo
})

# TODO 移动模式删除空目录
# 移动模式删除空目录
if dir_info.transfer_type in ["move"]:
logger.info(f"正在删除: {file_item.storage} {file_item.path}")
self.storagechain.delete_file(file_item)

except Exception as e:
logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc()))
Expand Down

0 comments on commit 117bd80

Please sign in to comment.