fix connection test

This commit is contained in:
2025-10-27 20:15:07 +01:00
parent 1a6c37d264
commit 66cc2fdfcb
2 changed files with 259 additions and 9 deletions

View File

@@ -35,6 +35,9 @@ class NetworkDiagnostics(BaseModel):
..., description="Overall internet connectivity status"
)
dns_working: bool = Field(..., description="DNS resolution status")
aniworld_reachable: bool = Field(
..., description="Aniworld.to connectivity status"
)
tests: List[NetworkTestResult] = Field(
..., description="Individual network tests"
)
@@ -109,19 +112,20 @@ async def test_host_connectivity(
)
@router.get("/network", response_model=NetworkDiagnostics)
@router.get("/network")
async def network_diagnostics(
auth: Optional[dict] = Depends(require_auth),
) -> NetworkDiagnostics:
) -> Dict:
"""Run network connectivity diagnostics.
Tests DNS resolution and connectivity to common services.
Tests DNS resolution and connectivity to common services including
aniworld.to.
Args:
auth: Authentication token (optional)
Returns:
NetworkDiagnostics with test results
Dict with status and diagnostics data
Raises:
HTTPException: If diagnostics fail
@@ -132,11 +136,12 @@ async def network_diagnostics(
# Check DNS
dns_working = await check_dns()
# Test connectivity to various hosts
# Test connectivity to various hosts including aniworld.to
test_hosts = [
("google.com", 80),
("cloudflare.com", 80),
("github.com", 443),
("aniworld.to", 443),
]
# Run all tests concurrently
@@ -148,17 +153,35 @@ async def network_diagnostics(
# Determine overall internet connectivity
internet_connected = any(result.reachable for result in test_results)
logger.info(
f"Network diagnostics complete: "
f"DNS={dns_working}, Internet={internet_connected}"
# Check if aniworld.to is reachable
aniworld_result = next(
(r for r in test_results if r.host == "aniworld.to"),
None
)
aniworld_reachable = (
aniworld_result.reachable if aniworld_result else False
)
return NetworkDiagnostics(
logger.info(
f"Network diagnostics complete: "
f"DNS={dns_working}, Internet={internet_connected}, "
f"Aniworld={aniworld_reachable}"
)
# Create diagnostics data
diagnostics_data = NetworkDiagnostics(
internet_connected=internet_connected,
dns_working=dns_working,
aniworld_reachable=aniworld_reachable,
tests=test_results,
)
# Return in standard format expected by frontend
return {
"status": "success",
"data": diagnostics_data.model_dump(),
}
except Exception as e:
logger.exception("Failed to run network diagnostics")
raise HTTPException(