allow skipping cache
Build and Push Docker Images / build-and-push (push) Successful in 27s

This commit is contained in:
2025-05-06 12:33:17 +02:00
parent 707ad9457d
commit ebfda3f155
+13 -9
View File
@@ -13,7 +13,7 @@ from app.services.browser import (
router = APIRouter() router = APIRouter()
@router.get("/") @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 # Validate API key
if not x_api_key or x_api_key != API_KEY: if not x_api_key or x_api_key != API_KEY:
raise HTTPException(status_code=401, detail="Invalid API key") raise HTTPException(status_code=401, detail="Invalid API key")
@@ -21,7 +21,8 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None)):
# Decode URL if it's encoded # Decode URL if it's encoded
decoded_url = unquote(url) decoded_url = unquote(url)
# Check cache first # Check cache first (unless skipCache is True)
if not skipCache:
cached_result = get_cached_data(decoded_url, "visit") cached_result = get_cached_data(decoded_url, "visit")
if cached_result: if cached_result:
return cached_result return cached_result
@@ -30,7 +31,7 @@ async def visit_url(url: str, x_api_key: Optional[str] = Header(None)):
# Call the service function # Call the service function
result = await visit_url_service(decoded_url) 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) save_to_cache(decoded_url, "visit", result)
return 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)) raise HTTPException(status_code=500, detail=str(e))
@router.get("/seo") @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""" """Extract SEO information from a website"""
# Validate API key # Validate API key
if not x_api_key or x_api_key != API_KEY: if not x_api_key or x_api_key != API_KEY:
@@ -48,7 +49,8 @@ async def extract_seo(url: str, x_api_key: Optional[str] = Header(None)):
# Decode URL if it's encoded # Decode URL if it's encoded
decoded_url = unquote(url) decoded_url = unquote(url)
# Check cache first # Check cache first (unless skipCache is True)
if not skipCache:
cached_result = get_cached_data(decoded_url, "seo") cached_result = get_cached_data(decoded_url, "seo")
if cached_result: if cached_result:
return cached_result return cached_result
@@ -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)) raise HTTPException(status_code=500, detail=str(e))
@router.get("/meta") @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""" """Extract meta tags from a website"""
# Validate API key # Validate API key
if not x_api_key or x_api_key != API_KEY: if not x_api_key or x_api_key != API_KEY:
@@ -74,7 +76,8 @@ async def extract_meta_tags(url: str, x_api_key: Optional[str] = Header(None)):
# Decode URL if it's encoded # Decode URL if it's encoded
decoded_url = unquote(url) decoded_url = unquote(url)
# Check cache first # Check cache first (unless skipCache is True)
if not skipCache:
cached_result = get_cached_data(decoded_url, "meta") cached_result = get_cached_data(decoded_url, "meta")
if cached_result: if cached_result:
return cached_result return cached_result
@@ -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)) raise HTTPException(status_code=500, detail=str(e))
@router.get("/pagination") @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""" """Detect pagination on a website and determine the pagination pattern"""
# Validate API key # Validate API key
if not x_api_key or x_api_key != API_KEY: if not x_api_key or x_api_key != API_KEY:
@@ -100,7 +103,8 @@ async def detect_pagination(url: str, x_api_key: Optional[str] = Header(None)):
# Decode URL if it's encoded # Decode URL if it's encoded
decoded_url = unquote(url) decoded_url = unquote(url)
# Check cache first # Check cache first (unless skipCache is True)
if not skipCache:
cached_result = get_cached_data(decoded_url, "pagination") cached_result = get_cached_data(decoded_url, "pagination")
if cached_result: if cached_result:
return cached_result return cached_result