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
+25 -21
View File
@@ -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