Files
wehub-resource-sync 6ede33ccdb
Build and Push Docker Images / create_manifest (web, surfsense-web, , cpu) (push) Has been cancelled
Build and Push Docker Images / finalize_release (push) Has been cancelled
Obsidian Plugin Lint / lint (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-24.04-arm, linux/arm64, arm64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_web, cpu, ./surfsense_web/Dockerfile, web, surfsense-web, ubuntu-latest, linux/amd64, amd64, , runner, false, cpu) (push) Has been cancelled
Build and Push Docker Images / compute_version (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cpu, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, , production, false, cpu) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu126, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda126, production, true, cuda126) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-24.04-arm, linux/arm64, arm64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / build (./surfsense_backend, cu128, ./surfsense_backend/Dockerfile, backend, surfsense-backend, ubuntu-latest, linux/amd64, amd64, -cuda, production, true, cuda) (push) Has been cancelled
Build and Push Docker Images / verify_digests (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, , cpu) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda, cuda) (push) Has been cancelled
Build and Push Docker Images / create_manifest (backend, surfsense-backend, -cuda126, cuda126) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:33:44 +08:00

55 lines
1.9 KiB
Python

"""Env-resolved captcha-solver config (one app-wide config; no per-connector).
Resolved from :data:`app.config.config` only, mirroring ``03b``'s single
``PROXY_PROVIDER`` model. Off by default: ``captcha_enabled()`` is ``False``
unless both ``CAPTCHA_SOLVING_ENABLED=TRUE`` and an API key are present, so a
misconfigured deployment (flag on, key missing) never attempts a paid solve.
"""
from dataclasses import dataclass
from app.config import config
@dataclass(frozen=True)
class CaptchaConfig:
"""Immutable snapshot of the captcha-solver settings for one crawl."""
enabled: bool
solving_site: str
api_key: str | None
max_attempts_per_url: int
timeout_s: int
captcha_type_default: str
v3_min_score: float
v3_action: str
def get_captcha_config() -> CaptchaConfig:
"""Build a :class:`CaptchaConfig` from the current process config/env."""
api_key = config.CAPTCHA_SOLVER_API_KEY
flag_on = config.CAPTCHA_SOLVING_ENABLED
return CaptchaConfig(
# Effective-enabled requires a key too: a flag with no key would only
# produce ``ErrWrongAPIKey`` per attempt (and still risk an IP ban from
# the solver), so treat key-less config as disabled.
enabled=bool(flag_on and api_key),
solving_site=config.CAPTCHA_SOLVER_PROVIDER,
api_key=api_key,
max_attempts_per_url=config.CAPTCHA_MAX_ATTEMPTS_PER_URL,
timeout_s=config.CAPTCHA_SOLVE_TIMEOUT_S,
captcha_type_default=config.CAPTCHA_TYPE_DEFAULT,
v3_min_score=config.CAPTCHA_V3_MIN_SCORE,
v3_action=config.CAPTCHA_V3_ACTION,
)
def captcha_enabled() -> bool:
"""Cheap gate: is captcha solving effectively configured (flag + key)?
Callers check this before building the ``page_action`` or capturing the
crawl's proxy endpoint for the solver, so the stealth tier stays unchanged
when solving is off.
"""
return bool(config.CAPTCHA_SOLVING_ENABLED and config.CAPTCHA_SOLVER_API_KEY)