Merge branch 'test-reticulum-hash' of https://git.derickphan.com/lichenblankie/tinyweb into test-reticulum-hash

This commit is contained in:
lichenblankie 2026-03-30 22:50:02 +00:00
commit 67fc2f7649

View file

@ -338,12 +338,29 @@ def handle_search(query):
)
def handle_add_form(msg=""):
def handle_add_form(msg="", action_type="index"):
if action_type == "subscribe":
return _respond(
f"<h1>subscribe</h1>"
f"<p>Subscribe to a friend's TinyWeb instance to sync their index</p>"
f'<form method="post" action="/subscriptions/add">'
f'{_csrf_field()}'
f'<input name="dest_hash" placeholder="destination hash (32 hex chars)" size="50"><br><br>'
f'<button type="submit">subscribe</button>'
f"</form>"
f"<p><small>or <a href=\"/add\">add a single site</a></small></p>"
f"<p>{msg}</p>"
f'<a href="/">back</a>'
)
return _respond(
f"<h1>add url</h1>"
f"<p>Add a site via URL or Reticulum destination hash</p>"
f'<form method="post" action="/add">'
f'{_csrf_field()}'
f'<select name="action_type" onchange="this.form.action = this.value === \'subscribe\' ? \'/subscriptions/add\' : \'/add\'">'
f'<option value="/add" selected>Add site (index)</option>'
f'<option value="/subscriptions/add">Subscribe to instance</option>'
f'</select><br><br>'
f'<input name="url" placeholder="https://example.com" size="50"><br>'
f'<small>or</small><br>'
f'<input name="reticulum_dest" placeholder="reticulum destination hash (32 hex chars)" size="50"><br><br>'
@ -351,6 +368,7 @@ def handle_add_form(msg=""):
f'<input name="tags" placeholder="tags (comma-separated, e.g. solarpunk, mesh)" size="50"><br><br>'
f'<button type="submit">index</button>'
f"</form>"
f"<p><small>or <a href=\"/subscriptions\">manage subscriptions</a></small></p>"
f"<p>{msg}</p>"
f'<a href="/">back</a>'
)
@ -921,6 +939,7 @@ def handle_subscriptions(msg=""):
f'<input name="dest_hash" placeholder="destination hash" size="40"> '
f'<button>subscribe</button>'
f'</form>'
f'<p><small>or <a href="/add?type=subscribe">subscribe to an instance</a></small></p>'
f'<p>{msg}</p>'
f'<hr>{listing}'
f'<br><a href="/">back</a>'
@ -1286,7 +1305,8 @@ def _dispatch_inner(data):
if path == "/":
return handle_search(query)
elif path == "/add":
return handle_add_form()
action_type = query.get("type", ["index"])[0]
return handle_add_form(action_type=action_type if action_type == "subscribe" else "index")
elif path == "/pages":
return handle_pages(query)
elif path.startswith("/edit/"):