mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2026-09-24 06:10:14 +01:00
FlareSolverr hardcodes the solution status ("todo: fix, selenium not
provides this info"), so clients built against it never see anything else.
Byparr handed back the real navigation code on the branch without a
challenge and 200 on the branch with one, which is neither honest nor
compatible. Always report 200.
Move the challenge handling into src/challenge.py and the response bodies
into src/content.py, leaving endpoints.py with the routes and navigation.
That also confines the import of playwright_captcha's private detection
module to a single file, so a patch release can only break one import
instead of the app and the test module at once.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
38 lines
2.0 KiB
Markdown
38 lines
2.0 KiB
Markdown
# Copilot Instructions
|
|
|
|
## Project overview
|
|
|
|
- FastAPI service that mimics FlareSolverr-style API for bypassing anti-bot pages using invisible_playwright.
|
|
- Entry point: main app in main.py; routes and request flow in src/endpoints.py, challenge handling in src/challenge.py, response bodies in src/content.py, models in src/models.py.
|
|
- Browser lifecycle is owned by get_browser() in src/utils.py, which yields a page and context for each request.
|
|
|
|
## Architecture and data flow
|
|
|
|
- Request flow: POST /v1 -> read_item() -> page.goto() -> wait for load states -> detect the interstitial -> click its checkbox until it clears -> return LinkResponse.
|
|
- Challenge detection uses detect_cloudflare_challenge() from playwright_captcha; the challenge is over when its markup goes, not when a solver says so.
|
|
- Health check hits /v1 internally with <https://google.com> and fails if status is not OK.
|
|
- Logging: LogRequest middleware logs only POST /v1 timing and outcome; other paths pass through.
|
|
|
|
## Key modules and patterns
|
|
|
|
- Models use Pydantic v2 with camelCase aliasing for responses (see src/models.py).
|
|
- LinkResponse.invalid() is the standard error response shape; keep fields consistent with FlareSolverr style.
|
|
- get_camoufox() constructs AsyncCamoufox with addons and optional proxy config from env vars.
|
|
|
|
## Config and environment
|
|
|
|
- Core env vars in src/consts.py: HOST, PORT, PROXY_SERVER, PROXY_USERNAME, PROXY_PASSWORD, LOG_LEVEL, VERSION.
|
|
- VERSION strips leading "v" for tag-style values.
|
|
|
|
## Developer workflows
|
|
|
|
- Local run: uv sync && uv run main.py
|
|
- Init mode: uv run main.py --init (pre-warms health check via browser setup)
|
|
- Tests: uv sync --group test && uv run pytest --retries 5
|
|
- Docker troubleshooting: docker build --target test .
|
|
|
|
## Tests and external dependencies
|
|
|
|
- tests/main_test.py calls real websites; tests are network-dependent and may be skipped based on upstream status.
|
|
- HTTP client tests use starlette.testclient + httpx; avoid mocking unless needed for local-only changes.
|