diff --git a/app/actions/__init__.py b/app/actions/__init__.py index 00546036..c9855cb5 100644 --- a/app/actions/__init__.py +++ b/app/actions/__init__.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod from pydantic.main import BaseModel -from app.schemas import ActionContext +from app.schemas import ActionContext, ActionParams class BaseAction(BaseModel, ABC): @@ -21,5 +21,5 @@ class BaseAction(BaseModel, ABC): pass @abstractmethod - async def execute(self, params: dict, context: ActionContext) -> ActionContext: + async def execute(self, params: ActionParams, context: ActionContext) -> ActionContext: raise NotImplementedError diff --git a/app/actions/add_download.py b/app/actions/add_download.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/add_subscribe.py b/app/actions/add_subscribe.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/fetch_medias.py b/app/actions/fetch_medias.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/fetch_rss.py b/app/actions/fetch_rss.py new file mode 100644 index 00000000..e152785e --- /dev/null +++ b/app/actions/fetch_rss.py @@ -0,0 +1,33 @@ +from typing import Optional + +from pydantic import Field + +from app.actions import BaseAction +from app.schemas import ActionParams, ActionContext + + +class FetchRssParams(ActionParams): + """ + 获取RSS资源列表参数 + """ + url: str = Field(None, description="RSS地址") + proxy: Optional[bool] = Field(False, description="是否使用代理") + timeout: Optional[int] = Field(15, description="超时时间") + headers: Optional[dict] = Field(None, description="请求头") + recognize: Optional[bool] = Field(False, description="是否识别") + + +class FetchRssAction(BaseAction): + """ + 获取RSS资源列表 + """ + @property + def name(self) -> str: + return "获取RSS资源列表" + + @property + def description(self) -> str: + return "请求RSS地址获取数据,并解析为资源列表" + + async def execute(self, params: FetchRssParams, context: ActionContext) -> ActionContext: + pass diff --git a/app/actions/filter_medias.py b/app/actions/filter_medias.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/filter_torrents.py b/app/actions/filter_torrents.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/search_torrents.py b/app/actions/search_torrents.py new file mode 100644 index 00000000..550808e2 --- /dev/null +++ b/app/actions/search_torrents.py @@ -0,0 +1,34 @@ +from typing import Optional + +from pydantic import Field + +from app.actions import BaseAction +from app.schemas import ActionParams, ActionContext + + +class SearchTorrentsParams(ActionParams): + """ + 搜索站点资源参数 + """ + name: str = Field(None, description="资源名称") + year: Optional[int] = Field(None, description="年份") + type: Optional[str] = Field(None, description="资源类型 (电影/电视剧)") + season: Optional[int] = Field(None, description="季度") + recognize: Optional[bool] = Field(False, description="是否识别") + + +class SearchTorrentsAction(BaseAction): + """ + 搜索站点资源 + """ + + @property + def name(self) -> str: + return "搜索站点资源" + + @property + def description(self) -> str: + return "根据关键字搜索站点种子资源" + + async def execute(self, params: SearchTorrentsParams, context: ActionContext) -> ActionContext: + pass diff --git a/app/actions/send_event.py b/app/actions/send_event.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/send_message.py b/app/actions/send_message.py new file mode 100644 index 00000000..e69de29b diff --git a/app/actions/transfer_file.py b/app/actions/transfer_file.py new file mode 100644 index 00000000..e69de29b diff --git a/app/schemas/workflow.py b/app/schemas/workflow.py index bc080172..32df0cd9 100644 --- a/app/schemas/workflow.py +++ b/app/schemas/workflow.py @@ -1,8 +1,9 @@ -from abc import ABC, abstractmethod -from typing import Optional +from typing import Optional, List, Tuple from pydantic import BaseModel, Field +from app.schemas import Context, MediaInfo, FileItem, Site, Subscribe, Notification + class Workflow(BaseModel): """ @@ -28,8 +29,22 @@ class Action(BaseModel): description: Optional[str] = Field(None, description="动作描述") -class ActionContext(BaseModel, ABC): +class ActionContext(BaseModel): """ - 动作上下文 + 动作基础上下文,各动作通用数据 + """ + content: Optional[str] = Field(None, description="文本类内容") + torrents: Optional[List[Context]] = Field([], description="资源列表") + medias: Optional[List[MediaInfo]] = Field([], description="媒体列表") + fileitems: Optional[List[FileItem]] = Field([], description="文件列表") + downloads: Optional[List[Tuple[str, str]]] = Field([], description="下载任务列表") + sites: Optional[List[Site]] = Field([], description="站点列表") + subscribes: Optional[List[Subscribe]] = Field([], description="订阅列表") + messages: Optional[List[Notification]] = Field([], description="消息列表") + + +class ActionParams(BaseModel): + """ + 动作基础参数 """ pass