From b8f4cd5fea8c98c42c21e8e3bbf20dc34c84b00f Mon Sep 17 00:00:00 2001 From: jxxghp Date: Fri, 14 Feb 2025 19:35:49 +0800 Subject: [PATCH] v2.2.9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 资源包升级以提升安全性 - 优化了页面数据刷新机制 注意:本次升级后会默认清理一次种子识别缓存 --- app/actions/__init__.py | 23 ++++++++++++++-- app/chain/__init__.py | 2 +- app/db/models/workflow.py | 35 +++++++++++++++++++++++++ app/schemas/workflow.py | 35 +++++++++++++++++++++++++ database/versions/279a949d81b6_2_1_1.py | 24 +++++++++++++++++ version.py | 4 +-- 6 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 database/versions/279a949d81b6_2_1_1.py diff --git a/app/actions/__init__.py b/app/actions/__init__.py index d7d4ab3e..00546036 100644 --- a/app/actions/__init__.py +++ b/app/actions/__init__.py @@ -1,6 +1,25 @@ -class BaseAction: +from abc import ABC, abstractmethod + +from pydantic.main import BaseModel + +from app.schemas import ActionContext + + +class BaseAction(BaseModel, ABC): """ 工作流动作基类 """ - async def execute(self, params: dict, context: dict) -> dict: + + @property + @abstractmethod + def name(self) -> str: + pass + + @property + @abstractmethod + def description(self) -> str: + pass + + @abstractmethod + async def execute(self, params: dict, context: ActionContext) -> ActionContext: raise NotImplementedError diff --git a/app/chain/__init__.py b/app/chain/__init__.py index da3b64fe..04ca91bf 100644 --- a/app/chain/__init__.py +++ b/app/chain/__init__.py @@ -76,7 +76,7 @@ class ChainBase(metaclass=ABCMeta): """ cache_path = settings.TEMP_PATH / filename if cache_path.exists(): - Path(cache_path).unlink() + cache_path.unlink() def run_module(self, method: str, *args, **kwargs) -> Any: """ diff --git a/app/db/models/workflow.py b/app/db/models/workflow.py index e69de29b..fe398730 100644 --- a/app/db/models/workflow.py +++ b/app/db/models/workflow.py @@ -0,0 +1,35 @@ +from datetime import datetime + +from sqlalchemy import Column, Integer, JSON, Sequence, String + +from app.db import Base + + +class Workflow(Base): + """ + 工作流表 + """ + # ID + id = Column(Integer, Sequence('id'), primary_key=True, index=True) + # 名称 + name = Column(String, index=True, nullable=False) + # 描述 + description = Column(String) + # 定时器 + timer = Column(String) + # 状态:N-新建 R-运行中 P-暂停 S-成功 F-失败 + state = Column(String, nullable=False, index=True, default='N') + # 当前执行动作 + current_action = Column(String) + # 任务执行结果 + result = Column(String) + # 已执行次数 + run_count = Column(Integer, default=0) + # 任务列表 + actions = Column(JSON, default=list) + # 执行上下文 + context = Column(JSON, default=dict) + # 创建时间 + add_time = Column(String, default=datetime.now().strftime('%Y-%m-%d %H:%M:%S')) + # 最后执行时间 + last_time = Column(String) diff --git a/app/schemas/workflow.py b/app/schemas/workflow.py index e69de29b..bc080172 100644 --- a/app/schemas/workflow.py +++ b/app/schemas/workflow.py @@ -0,0 +1,35 @@ +from abc import ABC, abstractmethod +from typing import Optional + +from pydantic import BaseModel, Field + + +class Workflow(BaseModel): + """ + 工作流信息 + """ + name: Optional[str] = Field(None, description="工作流名称") + description: Optional[str] = Field(None, description="工作流描述") + timer: Optional[str] = Field(None, description="定时器") + state: Optional[str] = Field(None, description="状态") + current_action: Optional[str] = Field(None, description="当前执行动作") + result: Optional[str] = Field(None, description="任务执行结果") + run_count: Optional[int] = Field(0, description="已执行次数") + actions: Optional[list] = Field([], description="任务列表") + add_time: Optional[str] = Field(None, description="创建时间") + last_time: Optional[str] = Field(None, description="最后执行时间") + + +class Action(BaseModel): + """ + 动作信息 + """ + name: Optional[str] = Field(None, description="动作名称") + description: Optional[str] = Field(None, description="动作描述") + + +class ActionContext(BaseModel, ABC): + """ + 动作上下文 + """ + pass diff --git a/database/versions/279a949d81b6_2_1_1.py b/database/versions/279a949d81b6_2_1_1.py new file mode 100644 index 00000000..dce3b5ab --- /dev/null +++ b/database/versions/279a949d81b6_2_1_1.py @@ -0,0 +1,24 @@ +"""2.1.1 + +Revision ID: 279a949d81b6 +Revises: ca5461f314f2 +Create Date: 2025-02-14 19:02:24.989349 + +""" + +from app.chain.torrents import TorrentsChain + +# revision identifiers, used by Alembic. +revision = '279a949d81b6' +down_revision = 'ca5461f314f2' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + # 清理一次缓存 + TorrentsChain().clear_torrents() + + +def downgrade() -> None: + pass diff --git a/version.py b/version.py index c61d8acf..2488b068 100644 --- a/version.py +++ b/version.py @@ -1,2 +1,2 @@ -APP_VERSION = 'v2.2.8-1' -FRONTEND_VERSION = 'v2.2.8-1' +APP_VERSION = 'v2.2.9' +FRONTEND_VERSION = 'v2.2.9'