return result
+@router.get(config.get("base_url") + "/api/domain.json", response_class=JSONResponse)
+def api_domain(domain: str):
+ # Tidy up domain name
+ domain = tidyup.domain(domain)
+
+ if not utils.is_domain_wanted(domain):
+ raise HTTPException(status_code=500, detail=f"domain='{domain}' is not wanted")
+
+ # Fetch domain data
+ database.cursor.execute("SELECT * FROM instances WHERE domain = ? LIMIT 1", [domain])
+ domain_data = database.cursor.fetchone()
+
+ if domain_data is None:
+ raise HTTPException(status_code=404, detail=f"domain='{domain}' not found")
+
+ return domain_data
+
@router.get(config.get("base_url") + "/api/mutual.json", response_class=JSONResponse)
def api_mutual(domains: list[str] = Query()):
"""Return 200 if federation is open between the two, 4xx otherwise"""
"bw": "*." + domains[1],
},
)
- response = database.cursor.fetchone()
- if response is not None:
+ if database.cursor.fetchone() is not None:
# Blocks found
return JSONResponse(status_code=418, content={})
raise HTTPException(status_code=500, detail=f"amount='{amount}' is to big")
info = response.json()
- response = None
blocklist = list()
if mode == "block_level" and not blocks.is_valid_level(value):
response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/top.json?mode={mode}&value={value}&amount={amount}")
- if response is not None:
+ if response is not None and response.ok:
blocklist = response.json()
found = 0
if not utils.is_domain_wanted(domain):
raise HTTPException(status_code=500, detail=f"domain='{domain}' is not wanted")
- # Fetch domain data
- database.cursor.execute("SELECT * FROM instances WHERE domain = ? LIMIT 1", [domain])
- domain_data = database.cursor.fetchone()
+ response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/domain.json?domain={domain}")
- if domain_data is None:
- raise HTTPException(status_code=404, detail=f"domain='{domain}' not found")
+ domain_data = dict()
+ if response is not None and response.ok:
+ domain_data = response.json()
# Format timestamps
format = config.get("timestamp_format")