fix scraping

This commit is contained in:
jxxghp
2024-09-20 12:51:32 +08:00
parent 91fc41261f
commit 117bd80528
5 changed files with 15 additions and 20 deletions

View File

@@ -5,7 +5,7 @@ from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from app import schemas 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.event import eventmanager
from app.core.security import verify_token from app.core.security import verify_token
from app.db import get_db from app.db import get_db
@@ -87,15 +87,15 @@ def delete_transfer_history(history_in: schemas.TransferHistory,
# 册除媒体库文件 # 册除媒体库文件
if deletedest and history.dest_fileitem: if deletedest and history.dest_fileitem:
dest_fileitem = schemas.FileItem(**json.loads(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: 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: if deletesrc and history.dest_fileitem:
dest_fileitem = schemas.FileItem(**json.loads(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: if not state:
return schemas.Response(success=False, msg=msg) return schemas.Response(success=False, msg=f"{dest_fileitem.path}删除失败")
# 发送事件 # 发送事件
eventmanager.send_event( eventmanager.send_event(
EventType.DownloadFileDeleted, EventType.DownloadFileDeleted,

View File

@@ -7,6 +7,7 @@ from sqlalchemy.orm import Session
from app import schemas from app import schemas
from app.chain.media import MediaChain from app.chain.media import MediaChain
from app.chain.storage import StorageChain
from app.chain.transfer import TransferChain from app.chain.transfer import TransferChain
from app.core.metainfo import MetaInfoPath from app.core.metainfo import MetaInfoPath
from app.core.security import verify_token, verify_apitoken from app.core.security import verify_token, verify_apitoken
@@ -89,7 +90,6 @@ def manual_transfer(fileitem: FileItem = None,
""" """
force = False force = False
target_path = Path(target_path) if target_path else None target_path = Path(target_path) if target_path else None
transfer = TransferChain()
if logid: if logid:
# 查询历史记录 # 查询历史记录
history: TransferHistory = TransferHistory.get(db, logid) history: TransferHistory = TransferHistory.get(db, logid)
@@ -107,7 +107,7 @@ def manual_transfer(fileitem: FileItem = None,
if history.dest_fileitem: if history.dest_fileitem:
# 删除旧的已整理文件 # 删除旧的已整理文件
dest_fileitem = FileItem(**json.loads(history.dest_fileitem)) dest_fileitem = FileItem(**json.loads(history.dest_fileitem))
transfer.delete_files(dest_fileitem) StorageChain().delete_file(dest_fileitem)
# 从历史数据获取信息 # 从历史数据获取信息
if from_history: if from_history:
@@ -144,7 +144,7 @@ def manual_transfer(fileitem: FileItem = None,
offset=episode_offset, offset=episode_offset,
) )
# 开始转移 # 开始转移
state, errormsg = transfer.manual_transfer( state, errormsg = TransferChain().manual_transfer(
fileitem=src_fileitem, fileitem=src_fileitem,
target_storage=target_storage, target_storage=target_storage,
target_path=target_path, target_path=target_path,

View File

@@ -428,7 +428,7 @@ class TransferChain(ChainBase):
) )
# 刮削元数据事件 # 刮削元数据事件
if scrape: if scrape or transferinfo.need_scrape:
self.eventmanager.send_event(EventType.MetadataScrape, { self.eventmanager.send_event(EventType.MetadataScrape, {
'meta': file_meta, 'meta': file_meta,
'mediainfo': file_mediainfo, 'mediainfo': file_mediainfo,
@@ -599,7 +599,7 @@ class TransferChain(ChainBase):
if history.dest_fileitem: if history.dest_fileitem:
# 解析目标文件对象 # 解析目标文件对象
dest_fileitem = FileItem(**json.loads(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: if history.src_fileitem:
@@ -713,11 +713,3 @@ class TransferChain(ChainBase):
mtype=NotificationType.Organize, mtype=NotificationType.Organize,
title=msg_title, text=msg_str, image=mediainfo.get_message_image(), title=msg_title, text=msg_str, image=mediainfo.get_message_image(),
link=settings.MP_DOMAIN('#/history'))) link=settings.MP_DOMAIN('#/history')))
def delete_files(self, fileitem: FileItem) -> Tuple[bool, str]:
"""
TODO 删除转移后的文件以及空目录
:param fileitem: 文件项
:return: 成功标识,错误信息
"""
pass

View File

@@ -152,7 +152,7 @@ class LocalStorage(StorageBase):
return False return False
path_obj = Path(fileitem.path) path_obj = Path(fileitem.path)
if not path_obj.exists(): if not path_obj.exists():
return False return True
try: try:
if path_obj.is_file(): if path_obj.is_file():
path_obj.unlink() path_obj.unlink()

View File

@@ -429,7 +429,10 @@ class Monitor(metaclass=Singleton):
'transferinfo': transferinfo '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: except Exception as e:
logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc())) logger.error("目录监控发生错误:%s - %s" % (str(e), traceback.format_exc()))