fix actions

This commit is contained in:
jxxghp
2025-02-22 09:57:32 +08:00
parent b84896b4f9
commit 0b3138fec6
10 changed files with 252 additions and 12 deletions
+35 -2
View File
@@ -1,5 +1,8 @@
from app.actions import BaseAction
from app.schemas import ActionParams, ActionContext
from chain.storage import StorageChain
from chain.transfer import TransferChain
from log import logger
class TransferFileParams(ActionParams):
@@ -14,6 +17,13 @@ class TransferFileAction(BaseAction):
整理文件
"""
__fileitems = []
def __init__(self):
super().__init__()
self.transferchain = TransferChain()
self.storagechain = StorageChain()
@property
def name(self) -> str:
return "整理文件"
@@ -24,7 +34,30 @@ class TransferFileAction(BaseAction):
@property
def success(self) -> bool:
return True
return True if self.__fileitems else False
async def execute(self, params: TransferFileParams, context: ActionContext) -> ActionContext:
pass
"""
从downloads中整理文件,记录到fileitems
"""
for download in context.downloads:
if not download.completed:
logger.info(f"下载任务 {download.download_id} 未完成")
continue
fileitem = self.storagechain.get_file_item(storage="local", path=download.path)
if not fileitem:
logger.info(f"文件 {download.path} 不存在")
continue
logger.info(f"开始整理文件 {download.path} ...")
state, errmsg = self.transferchain.do_transfer(fileitem, background=False)
if not state:
logger.error(f"整理文件 {download.path} 失败: {errmsg}")
continue
logger.info(f"整理文件 {download.path} 完成")
self.__fileitems.append(fileitem)
if self.__fileitems:
context.fileitems.extend(self.__fileitems)
self.job_done()
return context