fix
This commit is contained in:
+10
-1
@@ -5,12 +5,15 @@ export interface Config {
|
||||
port: number;
|
||||
storageDir: string;
|
||||
maxFileSize: number;
|
||||
fileTtlMs: number;
|
||||
rateLimitEnabled: boolean;
|
||||
rateLimitMax: number;
|
||||
rateLimitWindowMs: number;
|
||||
trustProxy: boolean;
|
||||
}
|
||||
|
||||
const DEFAULT_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 1 week
|
||||
|
||||
const SIZE_UNITS: Record<string, number> = {
|
||||
B: 1,
|
||||
K: 1 << 10,
|
||||
@@ -49,9 +52,14 @@ export function loadConfig(env: Record<string, string | undefined> = process.env
|
||||
}
|
||||
const host = env.HOST ?? "0.0.0.0";
|
||||
const storageDir = resolve(env.STORAGE_DIR ?? "./storage");
|
||||
const maxFileSize = parseSize(env.MAX_FILE_SIZE ?? "5GB");
|
||||
const maxFileSize = parseSize(env.MAX_FILE_SIZE ?? "10GB");
|
||||
if (maxFileSize < 1024) throw new Error("MAX_FILE_SIZE must be at least 1KB");
|
||||
|
||||
const fileTtlMs = Number(env.FILE_TTL_MS ?? String(DEFAULT_TTL_MS));
|
||||
if (!Number.isInteger(fileTtlMs) || fileTtlMs < 1) {
|
||||
throw new Error(`Invalid FILE_TTL_MS: ${env.FILE_TTL_MS}`);
|
||||
}
|
||||
|
||||
const rateLimitMax = Number(env.RATE_LIMIT_MAX ?? "300");
|
||||
if (!Number.isInteger(rateLimitMax) || rateLimitMax < 1) {
|
||||
throw new Error(`Invalid RATE_LIMIT_MAX: ${env.RATE_LIMIT_MAX}`);
|
||||
@@ -66,6 +74,7 @@ export function loadConfig(env: Record<string, string | undefined> = process.env
|
||||
port,
|
||||
storageDir,
|
||||
maxFileSize,
|
||||
fileTtlMs,
|
||||
rateLimitEnabled: boolFromEnv(env.RATE_LIMIT_ENABLED, true),
|
||||
rateLimitMax,
|
||||
rateLimitWindowMs,
|
||||
|
||||
Reference in New Issue
Block a user