wired up mesh subscriptions + search

- Subscriptions now use Reticulum destination hashes instead of HTTP URLs
- All subscription syncing happens over encrypted RNS links (rns_client.py)
- Add remote_pages table for synced content from subscriptions
- Search results now include pages from synced subscriptions, grouped by source
- Remove HTTP dependency from subscription handlers
This commit is contained in:
lichenblankie 2026-03-25 22:51:22 -07:00
parent 4b4e7e8081
commit 7ccaf93404
3 changed files with 201 additions and 56 deletions

37
db.py
View file

@ -47,12 +47,27 @@ def init_db():
db.execute(
"CREATE TABLE IF NOT EXISTS subscriptions ("
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
" url TEXT UNIQUE NOT NULL,"
" dest_hash TEXT UNIQUE NOT NULL,"
" name TEXT DEFAULT '',"
" auto_sync INTEGER DEFAULT 0,"
" last_sync TEXT DEFAULT ''"
")"
)
db.execute(
"CREATE TABLE IF NOT EXISTS remote_pages ("
" id INTEGER PRIMARY KEY AUTOINCREMENT,"
" subscription_id INTEGER NOT NULL,"
" url TEXT NOT NULL,"
" title TEXT,"
" note TEXT DEFAULT '',"
" FOREIGN KEY (subscription_id) REFERENCES subscriptions(id) ON DELETE CASCADE,"
" UNIQUE(subscription_id, url)"
")"
)
db.execute(
"CREATE VIRTUAL TABLE IF NOT EXISTS remote_pages_fts "
"USING fts5(title, url, note, content=remote_pages, content_rowid=id)"
)
db.executescript("""
CREATE TRIGGER IF NOT EXISTS pages_ai AFTER INSERT ON pages BEGIN
INSERT INTO pages_fts(rowid, title, body, url, note)
@ -68,7 +83,27 @@ def init_db():
INSERT INTO pages_fts(rowid, title, body, url, note)
VALUES (new.id, new.title, new.body, new.url, new.note);
END;
CREATE TRIGGER IF NOT EXISTS remote_pages_ai AFTER INSERT ON remote_pages BEGIN
INSERT INTO remote_pages_fts(rowid, title, url, note)
VALUES (new.id, new.title, new.url, new.note);
END;
CREATE TRIGGER IF NOT EXISTS remote_pages_ad AFTER DELETE ON remote_pages BEGIN
INSERT INTO remote_pages_fts(remote_pages_fts, rowid, title, url, note)
VALUES ('delete', old.id, old.title, old.url, old.note);
END;
CREATE TRIGGER IF NOT EXISTS remote_pages_au AFTER UPDATE ON remote_pages BEGIN
INSERT INTO remote_pages_fts(remote_pages_fts, rowid, title, url, note)
VALUES ('delete', old.id, old.title, old.url, old.note);
INSERT INTO remote_pages_fts(rowid, title, url, note)
VALUES (new.id, new.title, new.url, new.note);
END;
""")
# Migrate old subscriptions table if needed
cols = [row[1] for row in db.execute("PRAGMA table_info(subscriptions)").fetchall()]
if "url" in cols and "dest_hash" not in cols:
db.execute("ALTER TABLE subscriptions RENAME COLUMN url TO dest_hash")
db.commit()
db.commit()
db.close()