add new tool: to_captcha
This commit is contained in:
parent
8f86dbbdac
commit
4852345bf6
12 changed files with 716 additions and 35 deletions
35
api/mappers/captcha_mapper.py
Normal file
35
api/mappers/captcha_mapper.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
|
||||
from api.contracts.captcha_schemas import CaptchaActionResponse, CaptchaStatusResponse
|
||||
from api.repositories.task_store import TaskRecord
|
||||
|
||||
|
||||
class CaptchaMapper:
|
||||
@staticmethod
|
||||
def to_status(rec: TaskRecord) -> CaptchaStatusResponse:
|
||||
remaining: float | None = None
|
||||
if rec.captcha_deadline is not None:
|
||||
remaining = max(0.0, rec.captcha_deadline - time.time())
|
||||
return CaptchaStatusResponse(
|
||||
task_id=rec.task_id,
|
||||
state=rec.captcha_state,
|
||||
captcha_kind=rec.captcha_kind,
|
||||
reason=rec.captcha_reason,
|
||||
browser_view_url=rec.captcha_view_url,
|
||||
notified_at=rec.captcha_notified_at,
|
||||
solved_at=rec.captcha_solved_at,
|
||||
deadline=rec.captcha_deadline,
|
||||
extra_seconds=rec.captcha_extra_seconds,
|
||||
remaining_seconds=remaining,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def to_action(rec: TaskRecord, message: str | None = None, accepted: bool = True) -> CaptchaActionResponse:
|
||||
return CaptchaActionResponse(
|
||||
task_id=rec.task_id,
|
||||
state=rec.captcha_state,
|
||||
accepted=accepted,
|
||||
message=message,
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue