mirror of
https://github.com/ThePhaseless/Byparr.git
synced 2025-03-15 09:50:20 +08:00
adjustments
This commit is contained in:
parent
35fce85fcf
commit
518cf1de42
30
main.py
30
main.py
@ -31,25 +31,23 @@ async def read_item(request: LinkRequest):
|
|||||||
logger.info(f"Request: {request}")
|
logger.info(f"Request: {request}")
|
||||||
start_time = int(time.time() * 1000)
|
start_time = int(time.time() * 1000)
|
||||||
browser = await new_browser()
|
browser = await new_browser()
|
||||||
try:
|
page = await browser.get(request.url)
|
||||||
page = await browser.get(request.url)
|
await page.bring_to_front()
|
||||||
await page.bring_to_front()
|
timeout = request.maxTimeout
|
||||||
|
if timeout == 0:
|
||||||
|
timeout = None
|
||||||
|
|
||||||
challenged = await asyncio.wait_for(
|
challenged = await asyncio.wait_for(bypass_cloudflare(page), timeout=timeout)
|
||||||
bypass_cloudflare(page), timeout=request.maxTimeout
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(f"Got webpage: {request.url}")
|
logger.info(f"Got webpage: {request.url}")
|
||||||
|
|
||||||
response = await LinkResponse.create(
|
response = await LinkResponse.create(
|
||||||
page=page,
|
page=page,
|
||||||
start_timestamp=start_time,
|
start_timestamp=start_time,
|
||||||
challenged=challenged,
|
challenged=challenged,
|
||||||
)
|
)
|
||||||
except asyncio.TimeoutError:
|
|
||||||
logger.fatal("Couldn't complete the request")
|
browser.stop()
|
||||||
finally:
|
|
||||||
browser.stop()
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +20,8 @@ test_websites = [
|
|||||||
def test_bypass(website: str):
|
def test_bypass(website: str):
|
||||||
response = client.post(
|
response = client.post(
|
||||||
"/v1",
|
"/v1",
|
||||||
json=LinkRequest(url=website, maxTimeout=60, cmd="request.get").model_dump(),
|
json=LinkRequest(
|
||||||
|
url=website, maxTimeout=60 * len(test_websites), cmd="request.get"
|
||||||
|
).model_dump(),
|
||||||
)
|
)
|
||||||
assert response.status_code == HTTPStatus.OK
|
assert response.status_code == HTTPStatus.OK
|
||||||
|
Loading…
x
Reference in New Issue
Block a user