This commit is contained in:
@@ -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,16 +21,17 @@ 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)
|
||||||
cached_result = get_cached_data(decoded_url, "visit")
|
if not skipCache:
|
||||||
if cached_result:
|
cached_result = get_cached_data(decoded_url, "visit")
|
||||||
return cached_result
|
if cached_result:
|
||||||
|
return cached_result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 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,10 +49,11 @@ 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)
|
||||||
cached_result = get_cached_data(decoded_url, "seo")
|
if not skipCache:
|
||||||
if cached_result:
|
cached_result = get_cached_data(decoded_url, "seo")
|
||||||
return cached_result
|
if cached_result:
|
||||||
|
return cached_result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Call the service function
|
# 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))
|
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,10 +76,11 @@ 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)
|
||||||
cached_result = get_cached_data(decoded_url, "meta")
|
if not skipCache:
|
||||||
if cached_result:
|
cached_result = get_cached_data(decoded_url, "meta")
|
||||||
return cached_result
|
if cached_result:
|
||||||
|
return cached_result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Call the service function
|
# 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))
|
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,10 +103,11 @@ 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)
|
||||||
cached_result = get_cached_data(decoded_url, "pagination")
|
if not skipCache:
|
||||||
if cached_result:
|
cached_result = get_cached_data(decoded_url, "pagination")
|
||||||
return cached_result
|
if cached_result:
|
||||||
|
return cached_result
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Call the service function
|
# Call the service function
|
||||||
|
|||||||
Reference in New Issue
Block a user