// Mirrors the lexicons (lexicons/wiki.lichen.*.json); enforced by // tests/lib/limits-lexicon.test.ts. User-facing strings carry both units: // `graphemes` is the limit a person experiences, `bytes` is wire safety. export const LIMITS = { wiki: { name: { graphemes: 256, bytes: 2560 }, language: 16, description: { graphemes: 300, bytes: 3000 }, sidebar: 100_000, // appview-only, no lexicon constraint }, note: { slug: { graphemes: 256, bytes: 2560 }, title: { graphemes: 256, bytes: 2560 }, }, revision: { diff: 1_000_000, // bytes; a machine-generated patch has no grapheme limit message: { graphemes: 1024, bytes: 10240 }, blobCount: 32, }, image: { bytes: 2 * 1024 * 1024, }, blobProxy: { timeoutMs: 10_000, maxBytes: 2 * 1024 * 1024, }, page: { home: 3, explore: 12, searchDefault: 6, searchMax: 12, }, snippetRadius: 60, profileCacheHours: 24, // TTL for negatively cached failures (handle IS NULL), so they retry sooner. profileCacheFailureMinutes: 15, sessionMaxAgeSecs: 604800, // 7 days rateLimit: { upload: { limit: 10, windowMs: 60_000 }, blobProxy: { limit: 60, windowMs: 60_000 }, login: { limit: 5, windowMs: 60_000 }, search: { limit: 30, windowMs: 60_000 }, export: { limit: 3, windowMs: 60_000 }, }, // Bun buffers a request body before any handler sees it, so this is the only // ceiling that applies before allocation. Sits above zipImport's compressed // cap, the largest body any route accepts, with room for multipart framing. maxRequestBodyBytes: 16 * 1024 * 1024, // /-/export fetches every attachment from its owning PDS inside one request. // The notes always export; attachments are best-effort within these bounds, // and whatever was skipped is listed in _export_warnings.txt. export: { maxAttachments: 100, maxAttachmentBytes: 64 * 1024 * 1024, // Wall clock for the attachment phase, checked between fetches — a fetch // already in flight still gets its own blobProxy.timeoutMs on top. deadlineMs: 30_000, }, historyPageSize: 25, linkSuggestLimit: 20, snapshotCap: 25, zipImport: { // Compressed upload cap (cheap, checked before reading the body). Not // sufficient alone — DEFLATE ratios reach ~1000:1 — so the streaming // inflate also enforces maxUncompressedBytes as it decompresses. maxCompressedBytes: 10 * 1024 * 1024, maxUncompressedBytes: 50 * 1024 * 1024, maxZipEntries: 500, maxMdFiles: 100, }, cacheTtl: { ogCard: 3600, // 1h sitemap: 3600, // 1h manifest: 3600, // 1h blobLocal: 86400, // 1d blobImmutable: 31536000, // 1y cookie: 31536000, // 1y }, } as const;