]> git.mxchange.org Git - fba.git/commitdiff
Ops!
authorRoland Häder <roland@mxchange.org>
Wed, 17 May 2023 17:56:27 +0000 (19:56 +0200)
committerRoland Häder <roland@mxchange.org>
Wed, 17 May 2023 17:59:07 +0000 (19:59 +0200)
api.py

diff --git a/api.py b/api.py
index 8069c60584242c9dcf093e94f043496b5bbacb9e..30e06bdcdad875e96b92e72cd6c2d5150ab790b2 100644 (file)
--- a/api.py
+++ b/api.py
@@ -15,7 +15,7 @@ templates = Jinja2Templates(directory=".")
 def info():
     fba.c.execute("SELECT (SELECT count(domain) FROM instances), (SELECT count(domain) FROM instances WHERE software IN ('pleroma', 'mastodon', 'misskey', 'gotosocial', 'friendica')), (SELECT count(blocker) FROM blocks)")
     known, indexed, blocks = fba.c.fetchone()
-    fba.c.close()
+
     return {
         "known_instances": known,
         "indexed_instances": indexed,
@@ -36,7 +36,6 @@ def top(blocked: int = None, blockers: int = None):
             raise HTTPException(status_code=400, detail="Too many results")
         fba.c.execute("SELECT blocker, count(blocker) FROM blocks WHERE block_level = 'reject' group by blocker ORDER BY count(blocker) DESC LIMIT ?", (blockers,))
     scores = fba.c.fetchall()
-    fba.c.close()
 
     scoreboard = []
     print(scores)
@@ -63,7 +62,6 @@ def blocked(domain: str = None, reason: str = None, reverse: str = None):
     else:
         fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks WHERE reason like ? AND reason != '' ORDER BY first_added asc", ("%"+reason+"%",))
     blocks = fba.c.fetchall()
-    fba.c.close()
 
     result = {}
     for blocker, blocked, block_level, reason, first_added, last_seen in blocks:
@@ -82,7 +80,7 @@ def index(request: Request, blockers: int = None, blocked: int = None):
     elif blockers != None:
         scores = get(f"http://127.0.0.1:{fba.config['base_url']}{fba.config['base_url']}/top?blockers={blockers}")
     elif blocked != None:
-        scores = get(f"http://127.0.0.1:{fba.config['base_url']}{fba.config['base_url']}/top?blocked={blocked}")
+        scores = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/top?blocked={blocked}")
     if scores != None:
         if not scores.ok:
             raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
@@ -96,16 +94,16 @@ def index(request: Request, domain: str = None, reason: str = None, reverse: str
     info = None
     blocks = None
     if domain == None and reason == None and reverse == None:
-        info = get(f"http://127.0.0.1:{fba.config['base_url']}{fba.config['base_url']}/info")
+        info = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/info")
         if not info.ok:
             raise HTTPException(status_code=info.status_code, detail=info.text)
         info = info.json()
     elif domain != None:
-        blocks = get(f"http://127.0.0.1:{fba.config['base_url']}{fba.config['base_url']}/api?domain={domain}")
+        blocks = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?domain={domain}")
     elif reason != None:
-        blocks = get(f"http://127.0.0.1:{fba.config['base_url']}{fba.config['base_url']}/api?reason={reason}")
+        blocks = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?reason={reason}")
     elif reverse != None:
-        blocks = get(f"http://127.0.0.1:{fba.config['base_url']}{fba.config['base_url']}/api?reverse={reverse}")
+        blocks = get(f"http://127.0.0.1:{fba.config['port']}{fba.config['base_url']}/api?reverse={reverse}")
     if blocks != None:
         if not blocks.ok:
             raise HTTPException(status_code=blocks.status_code, detail=blocks.text)
@@ -133,10 +131,11 @@ def mutual(domains: list[str] = Query()):
         },
     )
     res = fba.c.fetchone()
-    fba.c.close()
+
     if res is not None:
         # Blocks found
         return responses.JSONResponse(status_code=418, content={})
+
     # No known blocks
     return responses.JSONResponse(status_code=200, content={})
 
@@ -151,7 +150,6 @@ def rss(request: Request, domain: str = None):
         fba.c.execute("SELECT blocker, blocked, block_level, reason, first_added, last_seen FROM blocks ORDER BY first_added DESC LIMIT 50")
 
     blocks = fba.c.fetchall()
-    fba.c.close()
 
     result = []
     for blocker, blocked, block_level, reason, first_added, last_seen in blocks: