]> git.mxchange.org Git - fba.git/blobdiff - api.py
Continued:
[fba.git] / api.py
diff --git a/api.py b/api.py
index ec2e193ba444857e0443f368fdc887fed08bf752..b2079c4f7ba3eee9feb8df78ec812299671621f3 100644 (file)
--- a/api.py
+++ b/api.py
@@ -182,17 +182,15 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str
     if domain == "" or reason == "" or reverse == "":
         return fastapi.responses.RedirectResponse("/")
 
-    info = None
-    blocks = None
+    response = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/info.json")
 
-    if domain == None and reason == None and reverse == None:
-        info = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/info.json")
+    if not response.ok:
+        raise HTTPException(status_code=response.status_code, detail=response.text)
 
-        if not info.ok:
-            raise HTTPException(status_code=info.status_code, detail=info.text)
+    info = response.json()
+    blocks = None
 
-        info = info.json()
-    elif domain != None:
+    if domain != None:
         blocks = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/index.json?domain={domain}")
     elif reason != None:
         blocks = requests.get(f"http://{config.get('host')}:{config.get('port')}{config.get('base_url')}/api/index.json?reason={reason}")
@@ -205,8 +203,8 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str
         blocks = blocks.json()
         for block_level in blocks:
             for block in blocks[block_level]:
-                block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime('%Y-%m-%d %H:%M')
-                block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime('%Y-%m-%d %H:%M')
+                block["first_seen"] = datetime.utcfromtimestamp(block["first_seen"]).strftime(config.get("timestamp_format"))
+                block["last_seen"] = datetime.utcfromtimestamp(block["last_seen"]).strftime(config.get("timestamp_format"))
 
     return templates.TemplateResponse("index.html", {
         "request": request,