mirror of
https://github.com/svemagie/indiekit-endpoint-activitypub.git
synced 2026-04-02 15:44:58 +02:00
Reader now resolves ActivityPub links internally instead of navigating to external instances. Actor links open the profile view, post links open a new post detail view with thread context (parent chain + replies). External links in post content get rich preview cards (title, description, image, favicon) fetched via unfurl.js at ingest time with fire-and-forget async processing and concurrency limiting. New files: post-detail controller, og-unfurl module, lookup-cache, link preview template/CSS, client-side link interception JS. Includes SSRF protection for OG fetching and GoToSocial URL support.
39 lines
931 B
JavaScript
39 lines
931 B
JavaScript
/**
|
|
* Simple in-memory LRU cache for lookupObject results
|
|
* Max 100 entries, 5-minute TTL
|
|
* @module lookup-cache
|
|
*/
|
|
|
|
const lookupCache = new Map();
|
|
const CACHE_MAX_SIZE = 100;
|
|
const CACHE_TTL_MS = 5 * 60 * 1000;
|
|
|
|
/**
|
|
* Get a cached lookup result
|
|
* @param {string} url - URL key
|
|
* @returns {*} Cached data or null
|
|
*/
|
|
export function getCached(url) {
|
|
const entry = lookupCache.get(url);
|
|
if (!entry) return null;
|
|
if (Date.now() - entry.timestamp > CACHE_TTL_MS) {
|
|
lookupCache.delete(url);
|
|
return null;
|
|
}
|
|
return entry.data;
|
|
}
|
|
|
|
/**
|
|
* Store a lookup result in cache
|
|
* @param {string} url - URL key
|
|
* @param {*} data - Data to cache
|
|
*/
|
|
export function setCache(url, data) {
|
|
// Evict oldest entry if at max size
|
|
if (lookupCache.size >= CACHE_MAX_SIZE) {
|
|
const firstKey = lookupCache.keys().next().value;
|
|
lookupCache.delete(firstKey);
|
|
}
|
|
lookupCache.set(url, { data, timestamp: Date.now() });
|
|
}
|