mirror of
https://github.com/calibrain/shelfmark.git
synced 2026-04-21 14:29:26 -04:00
Adding support for an external CloudFlare bypasser service and introducing a new Docker image build with a dedicated target. Key Changes - Added `cloudflare_bypasser_external.py` for external bypasser integration. - Updated Docker Compose files to support the new service. - Introduced a new Docker target for building a separate image for the external bypasser. - Refactored relevant modules to utilize the external bypasser when configured. - Documentation and configuration updates to reflect new options and Docker targets. Impact - Users can now choose between internal and external CloudFlare bypassing. - New Docker image and target streamline deployment of the external bypasser. - Improved modularity and maintainability. - No breaking changes for existing workflows. Testing - Manual and E2E tests performed for both bypasser modes. - Docker Compose setups and new image build verified for development and production. Notes Please review the new configuration options and Docker targets. Update your environment and deployment scripts as needed. Feedback and suggestions are welcome!
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from logger import setup_logger
|
|
from typing import Optional
|
|
import requests
|
|
|
|
try:
|
|
from env import EXT_BYPASSER_PATH, EXT_BYPASSER_TIMEOUT, EXT_BYPASSER_URL
|
|
except ImportError:
|
|
raise RuntimeError("Failed to import environment variables. Are you using an `extbp` image?")
|
|
|
|
logger = setup_logger(__name__)
|
|
|
|
|
|
def get_bypassed_page(url: str) -> Optional[str]:
|
|
"""Fetch HTML content from a URL using an External Cloudflare Resolver.
|
|
|
|
Args:
|
|
url: Target URL
|
|
Returns:
|
|
str: HTML content if successful, None otherwise
|
|
"""
|
|
if not EXT_BYPASSER_URL or not EXT_BYPASSER_PATH:
|
|
logger.error("Wrong External Bypass configuration. Please check your environment configuration.")
|
|
return None
|
|
ext_url = f"{EXT_BYPASSER_URL}{EXT_BYPASSER_PATH}"
|
|
headers = {"Content-Type": "application/json"}
|
|
data = {
|
|
"cmd": "request.get",
|
|
"url": url,
|
|
"maxTimeout": EXT_BYPASSER_TIMEOUT
|
|
}
|
|
response = requests.post(ext_url, headers=headers, json=data)
|
|
response.raise_for_status()
|
|
logger.debug(f"External Bypass response for '{url}': {response.json()['status']} - {response.json()['message']}")
|
|
return response.json()['solution']['response']
|