auto-discovery toggle, auto-prune with customizable retention

This commit is contained in:
lichenblankie 2026-06-05 01:00:47 +00:00
parent 7ebf35b137
commit f8f9cb6337
4 changed files with 115 additions and 4 deletions

View file

@ -484,10 +484,28 @@ class ForumHandlers:
)
synced_items = f"<ul>{synced_items}</ul>" if synced_items else "<p>No instances synced yet.</p>"
auto_discover = self.fdb.get_setting("forum_auto_discover", "1")
auto_discover_checked = " checked" if auto_discover == "1" else ""
retention_days = self.fdb.get_setting("forum_retention_days", "30")
return self._respond(
f"<h1>forum moderation</h1>"
f"<p>{msg}</p>"
f"<p><em>Forum instances on the mesh are discovered and synced automatically.</em></p>"
f"<h2>auto-discovery</h2>"
f'<form method="post" action="/forum/auto_discover">'
f'{self._csrf_field()}'
f'<label><input type="checkbox" name="enabled" value="1"{auto_discover_checked}>'
f" automatically discover and sync with other forum instances on the mesh</label><br><br>"
f'<button>save</button>'
f"</form>"
f"<h2>storage</h2>"
f'<form method="post" action="/forum/storage">'
f'{self._csrf_field()}'
f'<label>Keep threads for '
f'<input name="retention_days" value="{esc(retention_days)}" size="4"> days</label>'
f"<br><small>Older threads are pruned automatically (default: 30). Set to 0 to keep everything.</small><br><br>"
f'<button>save</button>'
f"</form>"
f"<h2>blocked instances</h2>"
f"{blocked_items}"
f'<form method="post" action="/forum/block">'
@ -556,6 +574,22 @@ class ForumHandlers:
self.fdb.set_setting("keyword_filters", keywords)
return self.handle_moderation("Filters saved.")
def handle_auto_discover(self, body):
enabled = "1" if body.get("enabled") else "0"
self.fdb.set_setting("forum_auto_discover", enabled)
if self.sync:
self.sync.set_auto_discover(enabled == "1")
return self.handle_moderation(f"Auto-discovery {'enabled' if enabled == '1' else 'disabled'}.")
def handle_storage(self, body):
days = body.get("retention_days", ["30"])[0].strip()
try:
days = max(0, int(days))
except ValueError:
return self.handle_moderation("Invalid retention days.")
self.fdb.set_setting("forum_retention_days", str(days))
return self.handle_moderation(f"Storage retention set to {days} days.")
def handle_sync_add(self, body):
instance = body.get("instance", [""])[0].strip().replace("<", "").replace(">", "")
name = body.get("name", [""])[0].strip()
@ -726,6 +760,10 @@ class ForumHandlers:
return self._with_csrf(self.handle_sync_add(body), csrf_token)
elif sub == "/unsync":
return self._with_csrf(self.handle_unsync(body), csrf_token)
elif sub == "/auto_discover":
return self._with_csrf(self.handle_auto_discover(body), csrf_token)
elif sub == "/storage":
return self._with_csrf(self.handle_storage(body), csrf_token)
return self._with_csrf(self._error(404), csrf_token)