mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-16 02:00:21 +08:00
add version control and more verbose error return
This commit is contained in:
parent
37f0cbdb00
commit
258bad19ee
@ -5,6 +5,9 @@ FROM python:3.12-slim-bullseye
|
|||||||
ARG GITHUB_BUILD=false
|
ARG GITHUB_BUILD=false
|
||||||
ENV GITHUB_BUILD=${GITHUB_BUILD}
|
ENV GITHUB_BUILD=${GITHUB_BUILD}
|
||||||
|
|
||||||
|
ARG VERSION
|
||||||
|
ENV VERSION=${VERSION}
|
||||||
|
|
||||||
ENV HOME=/root
|
ENV HOME=/root
|
||||||
ENV \
|
ENV \
|
||||||
DEBIAN_FRONTEND=noninteractive \
|
DEBIAN_FRONTEND=noninteractive \
|
||||||
|
@ -6,6 +6,8 @@ from typing import Any
|
|||||||
|
|
||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
|
from src.utils import consts
|
||||||
|
|
||||||
|
|
||||||
class LinkRequest(BaseModel):
|
class LinkRequest(BaseModel):
|
||||||
cmd: str = "get"
|
cmd: str = "get"
|
||||||
@ -26,9 +28,14 @@ class Solution(BaseModel):
|
|||||||
response: str
|
response: str
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def empty(cls):
|
def invalid(cls, url: str):
|
||||||
|
"""
|
||||||
|
Return an empty Solution with default values.
|
||||||
|
|
||||||
|
Useful for returning an error response.
|
||||||
|
"""
|
||||||
return cls(
|
return cls(
|
||||||
url="",
|
url=url,
|
||||||
status=HTTPStatus.INTERNAL_SERVER_ERROR,
|
status=HTTPStatus.INTERNAL_SERVER_ERROR,
|
||||||
cookies=[],
|
cookies=[],
|
||||||
userAgent="",
|
userAgent="",
|
||||||
@ -43,19 +50,23 @@ class LinkResponse(BaseModel):
|
|||||||
solution: Solution
|
solution: Solution
|
||||||
startTimestamp: int # noqa: N815 # Ignore to preserve compatibility
|
startTimestamp: int # noqa: N815 # Ignore to preserve compatibility
|
||||||
endTimestamp: int = int(time.time() * 1000) # 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
|
version: str = consts.VERSION
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def invalid(cls):
|
def invalid(cls, url: str):
|
||||||
|
"""
|
||||||
|
Return an invalid LinkResponse with default error values.
|
||||||
|
|
||||||
|
This method is used to generate a response indicating an invalid request.
|
||||||
|
"""
|
||||||
return cls(
|
return cls(
|
||||||
status="error",
|
status="error",
|
||||||
message="Invalid request",
|
message="Invalid request",
|
||||||
solution=Solution.empty(),
|
solution=Solution.invalid(url),
|
||||||
startTimestamp=int(time.time() * 1000),
|
startTimestamp=int(time.time() * 1000),
|
||||||
endTimestamp=int(time.time() * 1000),
|
endTimestamp=int(time.time() * 1000),
|
||||||
version="3.3.21",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NoChromeExtensionError(Exception):
|
class NoChromeExtensionError(Exception):
|
||||||
"""No chrome extention found."""
|
"""No chrome extension found."""
|
||||||
|
@ -1,9 +1,33 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_version_from_env():
|
||||||
|
"""
|
||||||
|
Retrieve the version from the environment variable 'VERSION'.
|
||||||
|
|
||||||
|
This function checks the 'VERSION' environment variable for a value
|
||||||
|
that starts with 'v' and returns the version without the prefix.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str | None: The version string without the 'v' prefix, or None if
|
||||||
|
the 'VERSION' environment variable is not set or does not start
|
||||||
|
with 'v'.
|
||||||
|
|
||||||
|
"""
|
||||||
|
version_env = os.getenv("VERSION")
|
||||||
|
if not version_env or not version_env.startswith("v"):
|
||||||
|
return None
|
||||||
|
|
||||||
|
return version_env.removeprefix("v")
|
||||||
|
|
||||||
|
|
||||||
LOG_LEVEL = os.getenv("LOG_LEVEL") or "INFO"
|
LOG_LEVEL = os.getenv("LOG_LEVEL") or "INFO"
|
||||||
LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
|
LOG_LEVEL = logging.getLevelNamesMapping()[LOG_LEVEL.upper()]
|
||||||
|
|
||||||
|
VERSION = get_version_from_env() or "unknown"
|
||||||
|
|
||||||
|
|
||||||
CHALLENGE_TITLES = [
|
CHALLENGE_TITLES = [
|
||||||
# Cloudflare
|
# Cloudflare
|
||||||
"Just a moment...",
|
"Just a moment...",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user