added public/private toggle

This commit is contained in:
lichenblankie 2026-04-12 02:31:34 +00:00
parent 30bc61212f
commit 4064a46c8a

View file

@ -364,7 +364,8 @@ def handle_add_form(msg="", action_type="index"):
f'{_csrf_field()}' f'{_csrf_field()}'
f'<input name="url" placeholder="https://example.com" size="50"><br><br>' f'<input name="url" placeholder="https://example.com" size="50"><br><br>'
f'<input name="note" placeholder="why are you saving this? (optional)" size="50"><br><br>' f'<input name="note" placeholder="why are you saving this? (optional)" size="50"><br><br>'
f'<input name="tags" placeholder="tags (comma-separated, e.g. solarpunk, mesh)" size="50"><br><br>' f'<input name="tags" placeholder="tags (comma-separated, e.g. solarpunk, mesh)" size="50"><br>'
f'<small>tag: private to exclude from sharing</small><br><br>'
f'<button type="submit">index</button>' f'<button type="submit">index</button>'
f"</form>" f"</form>"
f"<p>{msg}</p>" f"<p>{msg}</p>"
@ -426,7 +427,7 @@ def handle_add_submit(body):
f'<label>Title:</label><br>' f'<label>Title:</label><br>'
f'<input name="manual_title" size="50" placeholder="page title" required><br><br>' f'<input name="manual_title" size="50" placeholder="page title" required><br><br>'
f'<label>Description:</label><br>' f'<label>Description:</label><br>'
f'<textarea name="manual_description" rows="4" cols="50" placeholder="what is this site about?" required></textarea><br><br>' f'<textarea name="manual_description" rows="4" cols="50" placeholder="what is this site about? (optional)"></textarea><br><br>'
f'<button type="submit">save manually</button>' f'<button type="submit">save manually</button>'
f"</form>" f"</form>"
f'<a href="/">back</a>' f'<a href="/">back</a>'
@ -444,8 +445,8 @@ def handle_add_manual_submit(body):
if not url: if not url:
return handle_add_form("URL is required.") return handle_add_form("URL is required.")
if not manual_title or not manual_desc: if not manual_title:
return handle_add_form("Title and description are required for manual entry.") return handle_add_form("Title is required for manual entry.")
db = get_db() db = get_db()
try: try:
@ -603,7 +604,8 @@ def handle_edit_form(page_id, msg=""):
f'<label>Note (why you saved this):</label><br>' f'<label>Note (why you saved this):</label><br>'
f'<input name="note" value="{esc(row["note"])}" size="50"><br><br>' f'<input name="note" value="{esc(row["note"])}" size="50"><br><br>'
f'<label>Tags (comma-separated):</label><br>' f'<label>Tags (comma-separated):</label><br>'
f'<input name="tags" value="{esc(tags)}" size="50"><br><br>' f'<input name="tags" value="{esc(tags)}" size="50"> '
f'<small>(tag: private to keep private)</small><br><br>'
f'<button type="submit">save</button>' f'<button type="submit">save</button>'
f"</form>" f"</form>"
f"<p>{msg}</p>" f"<p>{msg}</p>"
@ -768,7 +770,8 @@ def handle_style_form(msg=""):
f'<input name="site_name" value="{esc(name)}" placeholder="tinyweb" size="30"><br><br>' f'<input name="site_name" value="{esc(name)}" placeholder="tinyweb" size="30"><br><br>'
f"<h2>sharing</h2>" f"<h2>sharing</h2>"
f'<label><input type="checkbox" name="sharing_enabled" value="1"{checked}>' f'<label><input type="checkbox" name="sharing_enabled" value="1"{checked}>'
f" share your site list publicly at /api/sites</label><br><br>" f" share your site list publicly at /api/sites</label><br>"
f"<small>Note: pages tagged: private will not be shared.</small><br><br>"
f"<h2>mesh network</h2>" f"<h2>mesh network</h2>"
f"<p>Connect to a Reticulum transport node to reach other peers.</p>" f"<p>Connect to a Reticulum transport node to reach other peers.</p>"
f"<small>Default: reticulum.derickphan.com:4242</small><br>" f"<small>Default: reticulum.derickphan.com:4242</small><br>"
@ -974,6 +977,8 @@ def handle_api_sites(query=None):
sites = [] sites = []
for r in rows: for r in rows:
tags = _get_page_tags(r["id"], db) tags = _get_page_tags(r["id"], db)
if "private" in tags:
continue # Skip pages tagged private from sharing
sites.append({ sites.append({
"url": r["url"], "title": r["title"], "note": r["note"], "url": r["url"], "title": r["title"], "note": r["note"],
"tags": tags, "last_modified": r["last_modified"] or "", "tags": tags, "last_modified": r["last_modified"] or "",
@ -981,7 +986,10 @@ def handle_api_sites(query=None):
# Include list of all current URLs so subscriber can detect deletions (limited) # Include list of all current URLs so subscriber can detect deletions (limited)
all_urls = None all_urls = None
if not since: if not since:
all_urls = [r["url"] for r in db.execute("SELECT url FROM pages LIMIT ?", (MAX_API_SITES,)).fetchall()] all_url_rows = db.execute(
"SELECT p.id, p.url FROM pages ORDER BY id DESC LIMIT ?", (MAX_API_SITES,)
).fetchall()
all_urls = [r["url"] for r in all_url_rows if "private" not in _get_page_tags(r["id"], db)]
finally: finally:
return_db(db) return_db(db)
data = {"name": get_site_name(), "sites": sites} data = {"name": get_site_name(), "sites": sites}