]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 6 Jun 2023 10:33:47 +0000 (12:33 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 6 Jun 2023 10:33:47 +0000 (12:33 +0200)
- moved timestamp formatting to configuration file
- added navigation back to /

api.py
config.defaults.json
templates/index.html

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,
index 02a7c741b90e0a4339bb498045f130c083128451..d99a6daab32a024a63e4829968ea4be024a66d53 100644 (file)
@@ -7,6 +7,7 @@
     "connection_timeout": 30,
     "read_timeout"      : 5,
     "hostname"          : "fba.ryona.agency",
+    "timestamp_format"  : "%Y-%m-%d %H:%M",
     "nodeinfo_connection_timeout": 3,
     "nodeinfo_read_timeout"      : 2,
     "bot_enabled"       : false,
index 857c820268d9d29a9d0996392267afc8fed59465..f5f73ad6ae5a56ac21b197b1a577e447b1661a8e 100644 (file)
@@ -48,9 +48,6 @@
             text-decoration: none;
             font-size: 0.8em;
         }
-        .info {
-            margin-top: 25px;
-        }
         input[type="text"], input[type="submit"] {
             padding: 5px;
             border-radius: 5px;
                 </table>
             </div>
         {% endfor %}
+        <h2>Infos:</h2>
+        <p>
+            <a href="{{base_url}}/">Index</a> /
+            source code: <a href="https://git.mxchange.org/?p=fba.git;a=summary" rel="source" target="_blank">git.mxchange.org</a><br /><br />
+            {{info.slogan}}
+        </p>
     {% else %}
         <h1>Enter a Domain</h1>
         <form>
             <input type="text" name="domain" placeholder="example.com" required="required" />
             <input type="submit" value="Submit" />
         </form>
+
         <h1>Enter a Reason</h1>
         <form>
             <input type="text" name="reason" placeholder="free speech" required="required" />
             <input type="submit" value="Submit" />
         </form>
+
         <h1>Reverse search</h1>
         <form>
             <input type="text" name="reverse" placeholder="example.com" required="required" />
             <input type="submit" value="Submit" />
         </form>
+
+        <h1>Scoreboards:</h1>
         <p>
             <a href="{{base_url}}/scoreboard?blockers=50">top 50 defederating</a> /
             <a href="{{base_url}}/scoreboard?blocked=50">defederated instances</a> /
             <a href="{{base_url}}/scoreboard?software=50">used software</a> /
             <a href="{{base_url}}/scoreboard?originator=10">originators</a>
         </p>
-        <div class="info">
+
+        <h2>Infos:</h2>
+        <p>
             known instances: {{info.known_instances}}<br/>
             indexed instances: {{info.indexed_instances}}<br/>
             blocks recorded: {{info.blocks_recorded}}<br/>
             errorous instances: {{info.errorous_instances}}<br/>
             source code: <a href="https://git.mxchange.org/?p=fba.git;a=summary" rel="source" target="_blank">git.mxchange.org</a><br /><br />
             {{info.slogan}}
-        </div>
+        </p>
     {% endif %}
 </body>
 </html>