32 lines
936 B
TypeScript
32 lines
936 B
TypeScript
|
|
export type StorageConfig = {
|
||
|
|
accessKeyId?: string
|
||
|
|
bucket: string
|
||
|
|
endpoint?: string
|
||
|
|
forcePathStyle: boolean
|
||
|
|
region: string
|
||
|
|
secretAccessKey?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export function loadStorageConfigFromEnv(env: NodeJS.ProcessEnv = process.env): StorageConfig {
|
||
|
|
return {
|
||
|
|
accessKeyId: normalizeOptionalString(env.S3_ACCESS_KEY_ID),
|
||
|
|
bucket: env.S3_BUCKET ?? "image-platform",
|
||
|
|
endpoint: normalizeOptionalString(env.S3_ENDPOINT),
|
||
|
|
forcePathStyle: parseBoolean(env.S3_FORCE_PATH_STYLE, true),
|
||
|
|
region: env.S3_REGION ?? "us-east-1",
|
||
|
|
secretAccessKey: normalizeOptionalString(env.S3_SECRET_ACCESS_KEY),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function normalizeOptionalString(value: string | undefined) {
|
||
|
|
return value && value.trim().length > 0 ? value : undefined
|
||
|
|
}
|
||
|
|
|
||
|
|
function parseBoolean(value: string | undefined, fallback: boolean) {
|
||
|
|
if (value === undefined) {
|
||
|
|
return fallback
|
||
|
|
}
|
||
|
|
|
||
|
|
return ["1", "true", "yes"].includes(value.toLowerCase())
|
||
|
|
}
|