Repository Public
1/** Server-side configuration. Never import this from a client component. */2import path from "node:path";34function req(name: string): string {5 const v = process.env[name];6 if (!v) throw new Error(`Missing environment variable ${name}`);7 return v;8}9const opt = (name: string) => process.env[name] || undefined;10const int = (name: string, def: number) => { const v = opt(name); if (!v) return def; const n = Number(v); if (!Number.isFinite(n) || n < 0) throw new Error(`${name} must be a positive number`); return n; };11const MB = 1024 * 1024;1213export const env = {14 get databaseUrl() { return req("DATABASE_URL"); },15 /** Public origin of the site. WebAuthn's expected origin and (by default) its RP ID derive from it. */16 get appUrl() { return (opt("APP_URL") ?? "http://localhost:8690").replace(/\/$/, ""); },17 /** WebAuthn RP ID: the site's host name by default; may be a registrable parent domain (e.g. spboucher.ai). */18 get rpId() { return opt("WEBAUTHN_RP_ID") ?? new URL(this.appUrl).hostname; },19 get appSecret() { const s = req("APP_SECRET"); if (s.length < 32) throw new Error("APP_SECRET must be at least 32 characters"); return s; },20 get isProd() { return process.env.NODE_ENV === "production"; },21 get ownerEmail() { return opt("OWNER_EMAIL"); },22 get ownerName() { return opt("OWNER_NAME") ?? "Propriétaire"; },2324 // Storage25 get storageDriver() { return opt("STORAGE_DRIVER") ?? "local"; },26 /** Mount point of the private library volume (never under public/). */27 get storageRoot() { return path.resolve(/*turbopackIgnore: true*/ req("STORAGE_ROOT")); },28 /** Scratch space for uploads in progress and processing; same volume as the library keeps moves atomic. */29 get tmpDir() { return path.resolve(/*turbopackIgnore: true*/ opt("TMP_DIR") ?? path.join(/*turbopackIgnore: true*/ this.storageRoot, ".tmp")); },3031 // Upload limits32 get maxFileBytes() { return int("UPLOAD_MAX_FILE_MB", 2048) * MB; },33 get maxChunkBytes() { return int("UPLOAD_MAX_CHUNK_MB", 16) * MB; },34 get maxFilesPerBatch() { return int("UPLOAD_MAX_FILES", 500); },35 /** Total size the library may reach (originals + renditions + artwork). 0 = no quota. */36 get libraryQuotaBytes() { return int("LIBRARY_QUOTA_GB", 0) * 1024 * MB; },37 get archiveMaxEntries() { return int("ARCHIVE_MAX_ENTRIES", 2000); },38 get archiveMaxTotalBytes() { return int("ARCHIVE_MAX_TOTAL_MB", 20480) * MB; },39 get archiveMaxRatio() { return int("ARCHIVE_MAX_RATIO", 100); },40 /** Incomplete uploads and finished import rows older than this are purged by the worker. */41 get uploadRetentionDays() { return int("UPLOAD_RETENTION_DAYS", 30); },4243 // Renditions44 /** auto: AAC rendition at import for codecs some browsers cannot decode, and on demand otherwise. never: originals only. */45 get renditions(): "auto" | "never" { const v = opt("RENDITIONS") ?? "auto"; if (v !== "auto" && v !== "never") throw new Error("RENDITIONS must be auto or never"); return v; },46 get renditionBitrateK() { return int("RENDITION_BITRATE_KBPS", 256); },47 /** DSD (DSF/DFF) is kept as is; a playable rendition is produced only when this is explicitly true. */48 get transcodeDsd() { return opt("TRANSCODE_DSD") === "true"; },49 get ffmpeg() { return opt("FFMPEG_PATH") ?? "ffmpeg"; },50 get ffprobe() { return opt("FFPROBE_PATH") ?? "ffprobe"; },5152 // Lyrics (speech-to-text on the node, optional)53 /** off: feature hidden. manual: an administrator asks for lyrics. auto: also queued for every new import. */54 get lyrics(): "off" | "manual" | "auto" { const v = opt("LYRICS") ?? "off"; if (v !== "off" && v !== "manual" && v !== "auto") throw new Error("LYRICS must be off, manual or auto"); return v; },55 /** Python of a virtualenv that has mlx-whisper installed. */56 get lyricsPython() { return opt("LYRICS_PYTHON"); },57 get lyricsModel() { return opt("LYRICS_MODEL") ?? "mlx-community/whisper-large-v3-turbo"; },5859 get backupDir() { return opt("BACKUP_DIR"); },6061 /** Apple app identifiers (TeamID.bundleId, comma-separated) allowed to use this site's passkeys natively. */62 get appleAppIds() { return (opt("APPLE_APP_IDS") ?? "3YM54G49SN.ai.spboucher.spmusic,3YM54G49SN.ai.spboucher.spmusic.ios").split(",").map((s) => s.trim()).filter(Boolean); },63};64