chore: улучшение архитектуры

This commit is contained in:
protokey committed 2026-09-08 18:16:05 +04:00
1 parent 0f60aa9046
commit 6b1935d78a
4 files changed
+82 -62

No files matched your search

View File
Whitespace-only changes.
+47
View File
@@ -0,0 +1,47 @@
from playwright.async_api import Page
from engine.schemas import ActionRequest
_actions: dict = {}
def register(fun) -> None:
_actions[fun.__name__] = fun
return fun
@register
async def fill(page: Page, act: ActionRequest) -> str | None:
...
@register
async def mouse_move(page: Page, act: ActionRequest) -> str | None:
...
@register
async def click(page: Page, act: ActionRequest) -> str | None:
...
@register
async def wait_for(page: Page, act: ActionRequest) -> str | None:
try:
assert act.selector
await page.wait_for_selector(act.selector, timeout=act.timeout * 1000)
except Exception as e:
return str(e)
else:
return None
async def execute(page: Page, actions: list[ActionRequest]) -> list[str]:
actions_result = []
for act in actions:
try:
await _actions[act.type](page, act)
except Exception as e:
actions_result.append({"type": act.type, "ok": "false", "error": str(e)})
break
return actions_result
+17
View File
@@ -0,0 +1,17 @@
from pydantic import BaseModel
class ActionRequest(BaseModel):
type: str
selector: str | None = None
value: str | None = None
timeout: int | None = None
class SolveRequest(BaseModel):
url: str
proxy: str
actions: list[ActionRequest]
timeout: int | None = None
screen: str = "1280x720"
user_agent: str | None = None