You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.3 KiB
111 lines
3.3 KiB
/** |
|
* Configuration for Nostr services |
|
* Handles environment variables and defaults |
|
*/ |
|
|
|
const DEFAULT_RELAYS = [ |
|
'wss://theforest.nostr1.com', |
|
'wss://thecitadel.nostr1.com', |
|
'wss://nostr.land' |
|
]; |
|
|
|
const PROFILE_RELAYS = [ |
|
'wss://relay.damus.io', |
|
'wss://aggr.nostr.land', |
|
'wss://profiles.nostr1.com', |
|
'wss://relay.primal.net', |
|
'wss://nostr.wine', |
|
'wss://nostr21.com' |
|
]; |
|
|
|
const THREAD_PUBLISH_RELAYS = [ |
|
'wss://thecitadel.nostr1.com' |
|
]; |
|
|
|
const GIF_RELAYS = [ |
|
"wss://relay.damus.io", |
|
"wss://relay.primal.net", |
|
"wss://relay.gifbuddy.lol", |
|
"wss://thecitadel.nostr1.com" |
|
]; |
|
|
|
const RELAY_TIMEOUT = 10000; |
|
|
|
// Fetch limits |
|
const FEED_LIMIT = 100; // Standard limit for feed events per kind |
|
const SINGLE_EVENT_LIMIT = 1; // For fetching a single event |
|
const SMALL_BATCH_LIMIT = 20; // For small batches (interactions, etc.) |
|
const MEDIUM_BATCH_LIMIT = 50; // For medium batches |
|
const LARGE_BATCH_LIMIT = 200; // For large batches (comments, etc.) |
|
const VERY_LARGE_BATCH_LIMIT = 500; // For very large batches |
|
|
|
// Fetch timeouts (in milliseconds) |
|
const SHORT_TIMEOUT = 2000; // Short timeout for cache-heavy operations |
|
const STANDARD_TIMEOUT = 3000; // Standard timeout for most operations |
|
const MEDIUM_TIMEOUT = 5000; // Medium timeout for profile/standard operations |
|
const LONG_TIMEOUT = 10000; // Long timeout for important operations |
|
const SINGLE_RELAY_TIMEOUT = 15000; // Timeout for single relay operations |
|
|
|
export interface NostrConfig { |
|
defaultRelays: string[]; |
|
profileRelays: string[]; |
|
threadTimeoutDays: number; |
|
threadPublishRelays: string[]; |
|
relayTimeout: number; |
|
gifRelays: string[]; |
|
// Fetch limits |
|
feedLimit: number; |
|
singleEventLimit: number; |
|
smallBatchLimit: number; |
|
mediumBatchLimit: number; |
|
largeBatchLimit: number; |
|
veryLargeBatchLimit: number; |
|
// Fetch timeouts |
|
shortTimeout: number; |
|
standardTimeout: number; |
|
mediumTimeout: number; |
|
longTimeout: number; |
|
singleRelayTimeout: number; |
|
} |
|
|
|
function parseRelays(envVar: string | undefined, fallback: string[]): string[] { |
|
if (!envVar) return fallback; |
|
const relays = envVar |
|
.split(',') |
|
.map((r) => r.trim()) |
|
.filter((r) => r.length > 0); |
|
return relays.length > 0 ? relays : fallback; |
|
} |
|
|
|
function parseIntEnv(envVar: string | undefined, fallback: number, min: number = 0): number { |
|
if (!envVar) return fallback; |
|
const parsed = parseInt(envVar, 10); |
|
if (isNaN(parsed) || parsed < min) return fallback; |
|
return parsed; |
|
} |
|
|
|
export function getConfig(): NostrConfig { |
|
return { |
|
defaultRelays: parseRelays(import.meta.env.VITE_DEFAULT_RELAYS, DEFAULT_RELAYS), |
|
profileRelays: PROFILE_RELAYS, |
|
threadTimeoutDays: parseIntEnv(import.meta.env.VITE_THREAD_TIMEOUT_DAYS, 30), |
|
threadPublishRelays: THREAD_PUBLISH_RELAYS, |
|
relayTimeout: RELAY_TIMEOUT, |
|
gifRelays: GIF_RELAYS, |
|
// Fetch limits |
|
feedLimit: parseIntEnv(import.meta.env.VITE_FEED_LIMIT, FEED_LIMIT, 1), |
|
singleEventLimit: SINGLE_EVENT_LIMIT, |
|
smallBatchLimit: SMALL_BATCH_LIMIT, |
|
mediumBatchLimit: MEDIUM_BATCH_LIMIT, |
|
largeBatchLimit: LARGE_BATCH_LIMIT, |
|
veryLargeBatchLimit: VERY_LARGE_BATCH_LIMIT, |
|
// Fetch timeouts |
|
shortTimeout: SHORT_TIMEOUT, |
|
standardTimeout: STANDARD_TIMEOUT, |
|
mediumTimeout: MEDIUM_TIMEOUT, |
|
longTimeout: LONG_TIMEOUT, |
|
singleRelayTimeout: SINGLE_RELAY_TIMEOUT |
|
}; |
|
} |
|
|
|
export const config = getConfig();
|
|
|