]> git.mxchange.org Git - fba.git/commitdiff
API now only returns block levels that are used
authorEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Thu, 14 Apr 2022 18:26:19 +0000 (20:26 +0200)
committerEnju Aihara <9839590-EnjuAihara@users.noreply.gitlab.com>
Thu, 14 Apr 2022 18:26:19 +0000 (20:26 +0200)
api.py

diff --git a/api.py b/api.py
index c6b9a338d40a1b7b40d5afffdd4063afffd15b15..0b01a2517aaa78650865ef9f5d3c8bc831e563d2 100644 (file)
--- a/api.py
+++ b/api.py
@@ -26,37 +26,20 @@ def blocked(domain: str):
     blocks = c.fetchall()
     conn.close()
 
-    result = {
-        "reject": [],
-        "media_removal": [],
-        "federated_timeline_removal": [],
-        "media_nsfw": [],
-        "quarantined_instances": [],
-        "report_removal": [],
-        "followers_only": [],
-        "accept": [],
-        "avatar_removal": [],
-        "banner_removal": [],
-        "reject_deletes": [],
-    }
-
-    reasons = {
-        "reject": {},
-        "media_removal": {},
-        "federated_timeline_removal": {},
-        "media_nsfw": {},
-        "quarantined_instances": {},
-        "report_removal": {},
-        "followers_only": {},
-        "accept": {},
-        "avatar_removal": {},
-        "banner_removal": {},
-        "reject_deletes": {},
-    }
+    result = {}
+    reasons = {}
 
     for domain, block_level, reason in blocks:
-        result[block_level].append(domain)
-        reasons[block_level][domain] = reason
-
-    return result | {"reasons": reasons}
+        if block_level in result:
+            result[block_level].append(domain)
+        else:
+            result[block_level] = [domain]
+            
+        if reason != "":
+            if block_level in reasons:
+                reasons[block_level][domain] = reason
+            else:
+                reasons[block_level] = {domain: reason}
+
+    return {"blocks": result, "reasons": reasons}