Files
zeekayandHanzo Dev fdabd21f40 legal: cleanly AGPL-3.0, Hanzo copyright added; drop minio from comments
No commercial licence anywhere: the ee/ carve-out, ee/LICENSE.md and the
retitled commercial text are gone from main. What is left is plain AGPL-3.0.

Adds Hanzo AI, Inc. copyright for our modifications. Papermark's line stays:
AGPL-3.0 s5 requires preserving upstream copyright notices, and removing it
is the exact swap that created the exposure we are clearing.

Storage comments referenced minio; we use hanzoai/s3.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-03 20:58:08 -07:00

61 lines
1.9 KiB
TypeScript

/**
* Object storage configuration.
*
* One bucket, resolved once from the environment. Any S3-compatible endpoint
* works — point NEXT_PRIVATE_UPLOAD_ENDPOINT at hanzoai/s3.
*/
export interface StorageConfig {
bucket: string;
advancedBucket?: string;
region: string;
accessKeyId: string;
secretAccessKey: string;
endpoint?: string;
distributionHost?: string;
advancedDistributionHost?: string;
distributionKeyId?: string;
distributionKeyContents?: string;
lambdaFunctionName?: string;
}
const DEFAULT_REGION = "us-east-1";
function required(name: string): string {
const value = process.env[name];
if (!value) {
throw new Error(`Missing environment variable: ${name}`);
}
return value;
}
function optional(name: string): string | undefined {
return process.env[name] || undefined;
}
/**
* Reads the storage configuration from the environment.
*
* Throws if a required variable is unset — an upload route that cannot name
* its bucket must fail at the boundary, not write somewhere unintended.
*/
export function getStorageConfig(): StorageConfig {
return {
bucket: required("NEXT_PRIVATE_UPLOAD_BUCKET"),
advancedBucket: optional("NEXT_PRIVATE_ADVANCED_UPLOAD_BUCKET"),
region: optional("NEXT_PRIVATE_UPLOAD_REGION") ?? DEFAULT_REGION,
accessKeyId: required("NEXT_PRIVATE_UPLOAD_ACCESS_KEY_ID"),
secretAccessKey: required("NEXT_PRIVATE_UPLOAD_SECRET_ACCESS_KEY"),
endpoint: optional("NEXT_PRIVATE_UPLOAD_ENDPOINT"),
distributionHost: optional("NEXT_PRIVATE_UPLOAD_DISTRIBUTION_HOST"),
advancedDistributionHost: optional(
"NEXT_PRIVATE_ADVANCED_UPLOAD_DISTRIBUTION_HOST",
),
distributionKeyId: optional("NEXT_PRIVATE_UPLOAD_DISTRIBUTION_KEY_ID"),
distributionKeyContents: optional(
"NEXT_PRIVATE_UPLOAD_DISTRIBUTION_KEY_CONTENTS",
),
lambdaFunctionName: optional("NEXT_PRIVATE_LAMBDA_FUNCTION_NAME"),
};
}