2024-07-24 13:57:40 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import time
|
2024-11-24 23:04:19 +00:00
|
|
|
from http import HTTPStatus
|
2024-07-24 13:57:40 +00:00
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
|
|
|
|
|
|
class LinkRequest(BaseModel):
|
|
|
|
cmd: str
|
|
|
|
url: str
|
|
|
|
maxTimeout: int # noqa: N815 # Ignore to preserve compatibility
|
|
|
|
|
|
|
|
|
|
|
|
class ProtectionTriggeredError(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Solution(BaseModel):
|
|
|
|
url: str
|
|
|
|
status: int
|
2024-07-24 15:53:14 +00:00
|
|
|
cookies: list
|
2024-07-24 13:57:40 +00:00
|
|
|
userAgent: str # noqa: N815 # Ignore to preserve compatibility
|
|
|
|
headers: dict[str, Any]
|
|
|
|
response: str
|
|
|
|
|
2024-11-24 23:04:19 +00:00
|
|
|
@classmethod
|
|
|
|
def empty(cls):
|
|
|
|
return cls(
|
|
|
|
url="",
|
|
|
|
status=HTTPStatus.INTERNAL_SERVER_ERROR,
|
|
|
|
cookies=[],
|
|
|
|
userAgent="",
|
|
|
|
headers={},
|
|
|
|
response="",
|
|
|
|
)
|
|
|
|
|
2024-07-24 13:57:40 +00:00
|
|
|
|
|
|
|
class LinkResponse(BaseModel):
|
|
|
|
status: str = "ok"
|
|
|
|
message: str
|
|
|
|
solution: Solution
|
|
|
|
startTimestamp: int # noqa: N815 # Ignore to preserve compatibility
|
|
|
|
endTimestamp: int = int(time.time() * 1000) # noqa: N815 # Ignore to preserve compatibility
|
|
|
|
version: str = "3.3.21" # TODO: Implement versioning
|
|
|
|
|
|
|
|
@classmethod
|
2024-11-24 23:04:19 +00:00
|
|
|
def invalid(cls):
|
2024-07-24 13:57:40 +00:00
|
|
|
return cls(
|
2024-11-24 23:04:19 +00:00
|
|
|
status="error",
|
|
|
|
message="Invalid request",
|
|
|
|
solution=Solution.empty(),
|
|
|
|
startTimestamp=int(time.time() * 1000),
|
|
|
|
endTimestamp=int(time.time() * 1000),
|
|
|
|
version="3.3.21",
|
2024-07-24 13:57:40 +00:00
|
|
|
)
|
2024-07-24 15:16:46 +00:00
|
|
|
|
|
|
|
|
2024-11-24 12:29:06 +00:00
|
|
|
class NoChromeExtensionError(Exception):
|
2024-07-24 15:16:46 +00:00
|
|
|
"""No chrome extention found."""
|