implement resulting url endpoint
Build and Push Docker Images / build-and-push (push) Has been cancelled
Build and Push Docker Images / build-and-push (push) Has been cancelled
This commit is contained in:
@@ -9,7 +9,8 @@ from app.services.browser import (
|
||||
extract_meta_tags_service,
|
||||
detect_pagination_service,
|
||||
capture_outgoing_calls_service,
|
||||
fetch_json_service
|
||||
fetch_json_service,
|
||||
get_resulting_url_service
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
@@ -182,4 +183,33 @@ async def fetch_json(url: str, skipCache: bool = False, x_api_key: Optional[str]
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"Error fetching JSON for URL {decoded_url}: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
|
||||
@router.get("/resulting-url")
|
||||
async def get_resulting_url(url: str, skipCache: bool = False, x_api_key: Optional[str] = Header(None)):
|
||||
"""Get the resulting URL after navigation (handles redirects)"""
|
||||
# Validate API key
|
||||
if not x_api_key or x_api_key != API_KEY:
|
||||
raise HTTPException(status_code=401, detail="Invalid API key")
|
||||
|
||||
# Decode URL if it's encoded
|
||||
decoded_url = unquote(url)
|
||||
|
||||
# Check cache first (unless skipCache is True)
|
||||
if not skipCache:
|
||||
cached_result = get_cached_data(decoded_url, "resulting_url")
|
||||
if cached_result:
|
||||
return cached_result
|
||||
|
||||
try:
|
||||
# Call the service function
|
||||
result = await get_resulting_url_service(decoded_url)
|
||||
|
||||
# Save to cache
|
||||
if(result["status"] == "success"):
|
||||
save_to_cache(decoded_url, "resulting_url", result)
|
||||
|
||||
return result
|
||||
except Exception as e:
|
||||
print(f"Error getting resulting URL for {decoded_url}: {e}")
|
||||
raise HTTPException(status_code=500, detail=str(e))
|
||||
Reference in New Issue
Block a user