]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 23 May 2023 04:05:26 +0000 (06:05 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 23 May 2023 04:05:26 +0000 (06:05 +0200)
- proper URLs with base_url
- all JSON replies now start with /api/

api.py
index.html

diff --git a/api.py b/api.py
index 897c2691b33cdaef980837f58b74e7d48ca8e297..0174a8d8b06b8a85300ef261ee5260b7db453653 100644 (file)
--- a/api.py
+++ b/api.py
@@ -12,7 +12,7 @@ import fba
 app = FastAPI(docs_url=fba.config["base_url"] + "/docs", redoc_url=fba.config["base_url"] + "/redoc")
 templates = Jinja2Templates(directory=".")
 
-@app.get(fba.config["base_url"] + "/info")
+@app.get(fba.config["base_url"] + "/api/info")
 def info():
     fba.cursor.execute("SELECT (SELECT COUNT(domain) FROM instances), (SELECT COUNT(domain) FROM instances WHERE software IN ('pleroma', 'mastodon', 'misskey', 'gotosocial', 'friendica', 'bookwyrm', 'takahe')), (SELECT COUNT(blocker) FROM blocks), (SELECT COUNT(domain) FROM instances WHERE last_status_code IS NOT NULL)")
     known, indexed, blocks, errorous = fba.cursor.fetchone()
@@ -25,7 +25,7 @@ def info():
         "slogan"            : fba.config["slogan"]
     }
 
-@app.get(fba.config["base_url"] + "/top")
+@app.get(fba.config["base_url"] + "/api/top")
 def top(blocked: int = None, blockers: int = None, reference: int = None, software: int = None):
     if blocked != None:
         if blocked > 500:
@@ -98,13 +98,13 @@ def index(request: Request, blockers: int = None, blocked: int = None, reference
     scores = None
 
     if blockers != None and blockers > 0:
-        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blockers={blockers}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api/top?blockers={blockers}")
     elif blocked != None and blocked > 0:
-        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api/top?blocked={blocked}")
     elif reference != None and reference > 0:
-        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?reference={reference}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api/top?reference={reference}")
     elif software != None and software > 0:
-        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?software={software}")
+        res = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api/top?software={software}")
     else:
         raise HTTPException(status_code=400, detail="No filter specified")
 
@@ -133,7 +133,7 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str
     blocks = None
 
     if domain == None and reason == None and reverse == None:
-        info = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/info")
+        info = requests.get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api/info")
 
         if not info.ok:
             raise HTTPException(status_code=info.status_code, detail=info.text)
index 4ba34131d8e6793706a2c79bac551b69e1dfe767..7ac1bdf6a7f53aa7201c5d653499bdae09113ac6 100644 (file)
@@ -99,9 +99,9 @@
                         <td>{{loop.index}}</td>
                         <td>
                             {% if software %}
-                            {{entry['domain']}}
+                                {{entry['domain']}}
                             {% else %}
-                                <b><a href="../?{% if blockers %}reverse{% elif blocked %}domain{% endif %}={{entry['domain']}}" rel="nofollow noopener noreferrer">{{entry['domain']}}</a></b>&nbsp;
+                                <b><a href="{{base_url}}/?{% if blockers %}reverse{% elif blocked or reference %}domain{% endif %}={{entry['domain']}}" rel="nofollow noopener noreferrer">{{entry['domain']}}</a></b>&nbsp;
                                 <a class="listlink" href="https://{{entry['domain']}}" rel="external" target="_blank">↗</a>
                             {% endif %}
                         </td>
                         <tr>
                             <td>
                                 <b><a href="https://{{block['blocker']}}" rel="nofollow noopener noreferrer">{{block['blocker']}}</a></b>
-                                {% if reason or domain %}<a class="listlink" href="./?reverse={{block['blocker']}}">↘</a>{% endif %}
+                                {% if reason or domain %}<a class="listlink" href="{{base_url}}/?reverse={{block['blocker']}}">↘</a>{% endif %}
                             </td>
                             <td>
                                 <b><a href="https://{{domain or block['blocked']}}" rel="nofollow noopener noreferrer">{{block['blocked']}}</a></b>
-                                {% if reason or reverse %}<a class="listlink" href="./?domain={{domain or block['blocked']}}">↘</a>{% endif %}
+                                {% if reason or reverse %}<a class="listlink" href="{{base_url}}/?domain={{domain or block['blocked']}}">↘</a>{% endif %}
                             </td>
                             <td>{{block['reason']}}</td>
                             <td>{{block['first_added']}}</td>
             <input type="submit" value="Submit" />
         </form>
         <p>
-            <a href="./scoreboard?blockers=50">top 50 defederating</a> /
-            <a href="./scoreboard?blocked=50">defederated instances</a> /
-            <a href="./scoreboard?reference=50">referencing instances</a> /
-            <a href="./scoreboard?software=50">used software</a>
+            <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?reference=50">referencing instances</a> /
+            <a href="{{base_url}}/scoreboard?software=50">used software</a>
         </p>
         <div class="info">
             known instances: {{info.known_instances}}<br/>