]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 13 Jun 2023 23:43:23 +0000 (01:43 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 13 Jun 2023 23:43:23 +0000 (01:43 +0200)
- added config key "rss_limit" (default: 50)

api.py
config.defaults.json

diff --git a/api.py b/api.py
index 33d09f514e1b948865f8396eda8abc9e2d9ef299..da4a2ee65396846933cc0a80a5449e6c8027c52c 100644 (file)
--- a/api.py
+++ b/api.py
@@ -236,10 +236,11 @@ def top(request: Request, domain: str = None, reason: str = None, reverse: str =
             raise HTTPException(status_code=response.status_code, detail=response.text)
 
         blocklist = response.json()
+
         for block_level in blocklist:
             for block in blocklist[block_level]:
                 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"))
+                block["last_seen"]  = datetime.utcfromtimestamp(block["last_seen"]).strftime(config.get("timestamp_format"))
 
     return templates.TemplateResponse("views/top.html", {
         "request": request,
@@ -256,18 +257,25 @@ def rss(request: Request, domain: str = None):
         domain = tidyup.domain(domain)
 
         wildchar = "*." + ".".join(domain.split(".")[-domain.count("."):])
-        punycode = domain.encode('idna').decode('utf-8')
-        fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_seen DESC LIMIT 50",
-                  (domain, "*." + domain, wildchar, fba.get_hash(domain), punycode, "*." + punycode))
+        punycode = domain.encode("idna").decode("utf-8")
+
+        fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks WHERE blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? OR blocked = ? ORDER BY first_seen DESC LIMIT ?", [
+            domain,
+            "*." + domain, wildchar,
+            fba.get_hash(domain),
+            punycode,
+            "*." + punycode,
+            config.get("rss_limit")
+        ])
     else:
-        fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks ORDER BY first_seen DESC LIMIT 50")
+        fba.cursor.execute("SELECT blocker, blocked, block_level, reason, first_seen, last_seen FROM blocks ORDER BY first_seen DESC LIMIT ?", [config.get("rss_limit")])
 
     result = fba.cursor.fetchall()
 
     blocklist = []
     for blocker, blocked, block_level, reason, first_seen, last_seen in result:
         first_seen = utils.format_datetime(datetime.fromtimestamp(first_seen))
-        if reason is None or reason == '':
+        if reason is None or reason == "":
             reason = "No reason provided."
         else:
             reason = "Provided reason: '" + reason + "'"
index f78a756f313348de2854e86dfc7d36e33a4e0166..e32a39dbb4591d102c1ef9fb0651ea19940be0b6 100644 (file)
@@ -19,5 +19,6 @@
     "recheck_block"     : 43200,
     "misskey_limit"     : 100,
     "error_log_cleanup" : 604800,
-    "write_error_log"   : "true"
+    "write_error_log"   : "true",
+    "rss_limit"         : 50
 }