From 23f18ff13e0a8c612d04727de2ccfadf2d13ff7c Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 1 Oct 2026 22:48:11 -0700 Subject: Shared note links open on the post, with names and faces The server renders /nevent1 and /note1 pages with the thread inlined (post, root, replies, kind 0s) and Open Graph tags; the client seeds its thread cache from it and opens the thread on the first paint. Without it, a pending frame holds the screen instead of the front door. Profile lookups ask our relays and the profile indexes at once, streamed, instead of one after the other behind five-second waits. A thread opened straight from a link has no Back button. Co-Authored-By: Claude Opus 5.5 --- feed/server.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'feed/server.js') diff --git a/feed/server.js b/feed/server.js index 2cf26a1..12ff850 100644 --- a/feed/server.js +++ b/feed/server.js @@ -1,12 +1,39 @@ +import { SimplePool } from 'nostr-tools/pool'; import { startFeedCache } from './service.js'; import { snapshotResponse } from './cache.js'; +import { NOTE_PATH, buildThread, createThreadCache, createIndexSource, notePageResponse } from './note-page.js'; const cache = await startFeedCache(); +// SimplePool verifies signatures and matches filters before accepting events. +const pool = new SimplePool(); +// Every relay's answer, or maxWait — but an ask by id is done the moment +// every id has turned up, rather than waiting out the slowest relay. +const query = (relays, filter, maxWait) => new Promise((resolve) => { + const got = new Map(); + let done = false, sub = null; + const finish = () => { if (done) return; done = true; try { sub && sub.close(); } catch {} resolve([...got.values()]); }; + sub = pool.subscribeManyEose(relays, filter, { + maxWait, + onevent(e) { + got.set(e.id, e); + if (filter.ids && filter.ids.every((id) => got.has(id))) finish(); + }, + onclose: finish, + }); + if (done) try { sub.close(); } catch {} +}); +const threads = createThreadCache({ build: (ref) => buildThread(ref, query) }); +const index = createIndexSource(process.env.INDEX_URL || 'http://bitcoin-wallet/index.html'); const server = Bun.serve({ hostname: process.env.HOST || '127.0.0.1', port: Number(process.env.PORT || 8792), - fetch(req) { - if (new URL(req.url).pathname !== '/api/feed') return new Response('Not found', { status: 404 }); - return snapshotResponse(cache, req); + idleTimeout: 30, + async fetch(req) { + const path = new URL(req.url).pathname; + if (path === '/api/feed') return snapshotResponse(cache, req); + if (NOTE_PATH.test(path) && ['GET', 'HEAD'].includes(req.method)) { + try { return await notePageResponse(req, { index, threads }); } catch { return new Response('Unavailable', { status: 502 }); } + } + return new Response('Not found', { status: 404 }); }, }); console.log(`Public feed cache listening on ${server.url}`); -- cgit v1.2.3