integrated the forum plugin
This commit is contained in:
parent
4a0214f020
commit
46cd28ba54
5 changed files with 122 additions and 4 deletions
20
app.py
20
app.py
|
|
@ -8,6 +8,8 @@ from http.server import HTTPServer
|
|||
|
||||
from db import init_db, get_setting, set_setting
|
||||
from handlers import dispatch_request
|
||||
import handlers as handlers_mod
|
||||
import templates as templates_mod
|
||||
import gateway
|
||||
from gateway import GatewayState, GatewayHandler
|
||||
|
||||
|
|
@ -31,6 +33,7 @@ def find_available_port(start=8080, max_attempts=20, host="127.0.0.1"):
|
|||
for port in range(start, start + max_attempts):
|
||||
try:
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
s.bind((host, port))
|
||||
return port
|
||||
except OSError:
|
||||
|
|
@ -97,6 +100,7 @@ def rns_request_handler(path, data, request_id, link_id, remote_identity, reques
|
|||
def start_gateway(reticulum, bind_host="127.0.0.1"):
|
||||
GatewayState.reticulum = reticulum
|
||||
GatewayState.local_dispatch = dispatch_request
|
||||
HTTPServer.allow_reuse_address = True
|
||||
server = HTTPServer((bind_host, gateway.GATEWAY_PORT), GatewayHandler)
|
||||
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
||||
thread.start()
|
||||
|
|
@ -271,6 +275,22 @@ def main():
|
|||
allow=RNS.Destination.ALLOW_ALL,
|
||||
)
|
||||
|
||||
# Initialize forum plugin if available
|
||||
forum = None
|
||||
try:
|
||||
from tinyweb_forum import ForumPlugin
|
||||
from db import get_site_name
|
||||
forum = ForumPlugin(DATA_DIR, identity, reticulum, site_name=get_site_name())
|
||||
if get_setting("forum_enabled", "0") == "1":
|
||||
forum.enable()
|
||||
templates_mod.FORUM_ENABLED = True
|
||||
handlers_mod.forum_plugin = forum
|
||||
print(f"Forum plugin: {'enabled' if forum.is_enabled() else 'available (enable in settings)'}")
|
||||
except ImportError:
|
||||
print("Forum plugin not installed (pip install tinyweb[forum])")
|
||||
except Exception as e:
|
||||
print(f"Forum plugin error: {e}")
|
||||
|
||||
# Brief delay to ensure all interfaces (especially TCP) are fully ready
|
||||
time.sleep(2)
|
||||
destination.announce()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue