From ebfda3f155e37ee63443928266a3b2eab9d54318 Mon Sep 17 00:00:00 2001 From: Bram Kelchtermans Date: Tue, 6 May 2025 12:33:17 +0200 Subject: [PATCH] allow skipping cache --- Dockers/puppeteer-api/app/routes/browser.py | 46 +++++++++++---------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Dockers/puppeteer-api/app/routes/browser.py b/Dockers/puppeteer-api/app/routes/browser.py index db35f04..ca56df3 100644 --- a/Dockers/puppeteer-api/app/routes/browser.py +++ b/Dockers/puppeteer-api/app/routes/browser.py @@ -13,7 +13,7 @@ from app.services.browser import ( router = APIRouter() @router.get("/") -async def visit_url(url: str, x_api_key: Optional[str] = Header(None)): +async def visit_url(url: str, skipCache: bool = False, x_api_key: Optional[str] = Header(None)): # Validate API key if not x_api_key or x_api_key != API_KEY: raise HTTPException(status_code=401, detail="Invalid API key") @@ -21,16 +21,17 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None)): # Decode URL if it's encoded decoded_url = unquote(url) - # Check cache first - cached_result = get_cached_data(decoded_url, "visit") - if cached_result: - return cached_result + # Check cache first (unless skipCache is True) + if not skipCache: + cached_result = get_cached_data(decoded_url, "visit") + if cached_result: + return cached_result try: # Call the service function result = await visit_url_service(decoded_url) - # Save to cache + # Save to cache (even if we skipped reading from it) save_to_cache(decoded_url, "visit", result) return result @@ -39,7 +40,7 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None)): raise HTTPException(status_code=500, detail=str(e)) @router.get("/seo") -async def extract_seo(url: str, x_api_key: Optional[str] = Header(None)): +async def extract_seo(url: str, skipCache: bool = False, x_api_key: Optional[str] = Header(None)): """Extract SEO information from a website""" # Validate API key if not x_api_key or x_api_key != API_KEY: @@ -48,10 +49,11 @@ async def extract_seo(url: str, x_api_key: Optional[str] = Header(None)): # Decode URL if it's encoded decoded_url = unquote(url) - # Check cache first - cached_result = get_cached_data(decoded_url, "seo") - if cached_result: - return cached_result + # Check cache first (unless skipCache is True) + if not skipCache: + cached_result = get_cached_data(decoded_url, "seo") + if cached_result: + return cached_result try: # Call the service function @@ -65,7 +67,7 @@ async def extract_seo(url: str, x_api_key: Optional[str] = Header(None)): raise HTTPException(status_code=500, detail=str(e)) @router.get("/meta") -async def extract_meta_tags(url: str, x_api_key: Optional[str] = Header(None)): +async def extract_meta_tags(url: str, skipCache: bool = False, x_api_key: Optional[str] = Header(None)): """Extract meta tags from a website""" # Validate API key if not x_api_key or x_api_key != API_KEY: @@ -74,10 +76,11 @@ async def extract_meta_tags(url: str, x_api_key: Optional[str] = Header(None)): # Decode URL if it's encoded decoded_url = unquote(url) - # Check cache first - cached_result = get_cached_data(decoded_url, "meta") - if cached_result: - return cached_result + # Check cache first (unless skipCache is True) + if not skipCache: + cached_result = get_cached_data(decoded_url, "meta") + if cached_result: + return cached_result try: # Call the service function @@ -91,7 +94,7 @@ async def extract_meta_tags(url: str, x_api_key: Optional[str] = Header(None)): raise HTTPException(status_code=500, detail=str(e)) @router.get("/pagination") -async def detect_pagination(url: str, x_api_key: Optional[str] = Header(None)): +async def detect_pagination(url: str, skipCache: bool = False, x_api_key: Optional[str] = Header(None)): """Detect pagination on a website and determine the pagination pattern""" # Validate API key if not x_api_key or x_api_key != API_KEY: @@ -100,10 +103,11 @@ async def detect_pagination(url: str, x_api_key: Optional[str] = Header(None)): # Decode URL if it's encoded decoded_url = unquote(url) - # Check cache first - cached_result = get_cached_data(decoded_url, "pagination") - if cached_result: - return cached_result + # Check cache first (unless skipCache is True) + if not skipCache: + cached_result = get_cached_data(decoded_url, "pagination") + if cached_result: + return cached_result try: # Call the service function