adjustments

This commit is contained in:
Thephaseless 2024-09-13 18:48:31 +00:00
parent 35fce85fcf
commit 518cf1de42
2 changed files with 17 additions and 17 deletions

30
main.py
View File

@ -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

View File

@ -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