aboutsummaryrefslogtreecommitdiffstats
path: root/feed/note-page.js
diff options
context:
space:
mode:
Diffstat (limited to 'feed/note-page.js')
-rw-r--r--feed/note-page.js7
1 files changed, 6 insertions, 1 deletions
diff --git a/feed/note-page.js b/feed/note-page.js
index 89b2f43..36f54fd 100644
--- a/feed/note-page.js
+++ b/feed/note-page.js
@@ -19,6 +19,11 @@ export const NOTE_RELAYS = ['wss://relay.damus.io', 'wss://nos.lol', 'wss://rela
// where kind 0s live when the conversation relays lack them
const PROFILE_RELAYS = ['wss://purplepag.es', 'wss://user.kindpag.es'];
const BUDGET_MS = 500;
+// A link-preview crawler reads the page once and keeps that card (Telegram,
+// 2026-12-04: a fresh post shared at once got the site's card because its
+// thread took longer than BUDGET_MS); it can wait for the real thing.
+export const BOT_BUDGET_MS = 7500; // a reply's thread: 2.5 s + 2.5 s + 2 s of relay asks
+export const isPreviewBot = (ua) => /bot\b|bot\/|crawler|spider|facebookexternalhit|facebookcatalog|whatsapp|telegram|slack|discord|twitter|linkedin|skype|embedly|iframely|mastodon|pleroma|misskey|akkoma|signal|vkshare|redditbot|applebot|bingpreview|google|yandex|duckduck|pinterest|tumblr|snapchat|preview/i.test(String(ua || ''));
const FRESH_MS = 60_000; // a thread younger than this is served as is
const KEEP_MS = 6 * 3600_000; // older, it's still served while a refresh runs
const MAX_THREADS = 500;
@@ -179,7 +184,7 @@ export async function notePageResponse(req, { index, threads }) {
const headers = { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-cache, must-revalidate' };
if (!ref) return new Response(html, { headers });
ref.path = u.pathname.slice(1);
- const data = await threads.get(ref).catch(() => null);
+ const data = await threads.get(ref, isPreviewBot(req.headers.get('user-agent')) ? BOT_BUDGET_MS : undefined).catch(() => null);
const proto = req.headers.get('x-forwarded-proto') || 'https';
const host = req.headers.get('x-forwarded-host') || req.headers.get('host');
return new Response(data ? renderNotePage(html, data, ref, host ? proto + '://' + host : '') : html, { headers });