From: Roland Häder Date: Tue, 6 Jun 2023 10:33:47 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c344a2397dac06a0901fc733e0df1ec64f33e635;p=fba.git Continued: - moved timestamp formatting to configuration file - added navigation back to / --- diff --git a/api.py b/api.py index ec2e193..b2079c4 100644 --- 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, diff --git a/config.defaults.json b/config.defaults.json index 02a7c74..d99a6da 100644 --- a/config.defaults.json +++ b/config.defaults.json @@ -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, diff --git a/templates/index.html b/templates/index.html index 857c820..f5f73ad 100644 --- a/templates/index.html +++ b/templates/index.html @@ -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; @@ -112,22 +109,32 @@ {% endfor %} +

Infos:

+

+ Index / + source code: git.mxchange.org

+ {{info.slogan}} +

{% else %}

Enter a Domain

+

Enter a Reason

+

Reverse search

+ +

Scoreboards:

top 50 defederating / defederated instances / @@ -135,14 +142,16 @@ used software / originators

-
+ +

Infos:

+

known instances: {{info.known_instances}}
indexed instances: {{info.indexed_instances}}
blocks recorded: {{info.blocks_recorded}}
errorous instances: {{info.errorous_instances}}
source code: git.mxchange.org

{{info.slogan}} -

+

{% endif %}