forked from WikiDeck/wikideck
Default UA unchanged; the testnet sets a contact URL in deploy/night only. Testnet wallet password moves to an env var. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 lines
871 B
TypeScript
14 lines
871 B
TypeScript
// User-Agent for Wikimedia API requests. Wikimedia asks automated clients to identify
|
|
// themselves with contact information; operators can opt in with WIKIDECK_USER_AGENT.
|
|
// Unset (or blank), each caller keeps its historical default string unchanged.
|
|
export const ARTICLE_USER_AGENT = 'Wikideck/0.1 (experimental Wikipedia article cards)';
|
|
export const ENRICHMENT_USER_AGENT = 'Wikideck/0.1 (Wikipedia off-chain page enrichment)';
|
|
const MAX_LENGTH = 256;
|
|
|
|
export function wikimediaUserAgent(fallback: string, env: Record<string, string | undefined> = process.env): string {
|
|
const configured = env.WIKIDECK_USER_AGENT?.trim();
|
|
// Reject header-injection/control characters and oversized values; fall back to the default.
|
|
if (!configured || configured.length > MAX_LENGTH || !/^[\x20-\x7e]+$/.test(configured)) return fallback;
|
|
return configured;
|
|
}
|