feat: enable S3 video uploads and update related configurations

- Added support for self-hosted S3 video uploads with new environment variables: OPENFRAME_ENABLE_S3_VIDEO_UPLOADS and OPENFRAME_MAX_VIDEO_UPLOAD_BYTES.
- Updated .env.example and .env.docker.example to reflect new configuration options.
- Enhanced Content Security Policy to include origins for S3-compatible storage.
- Updated dependencies for AWS SDK to support new features.
- Refactored upload logic to accommodate both Bunny and S3 upload providers.
- Updated documentation to clarify the usage of direct uploads and S3 configurations.
- Closes #11
This commit is contained in:
yusufipk
2026-05-27 17:04:39 +02:00
parent b6de3a29aa
commit 4bf6e821af
57 changed files with 2707 additions and 436 deletions
+58
View File
@@ -1,3 +1,5 @@
import { logError } from '@/lib/logger';
function readBooleanEnv(name: string, defaultValue: boolean): boolean {
const value = process.env[name];
if (!value) return defaultValue;
@@ -9,6 +11,20 @@ function readBooleanEnv(name: string, defaultValue: boolean): boolean {
return defaultValue;
}
let warnedAboutConflictingUploadFlags = false;
function warnIfConflictingDirectUploadFlags(): void {
if (warnedAboutConflictingUploadFlags) return;
if (!isS3VideoUploadsFeatureEnabled() || !isBunnyUploadsFeatureEnabled()) return;
if (!hasR2Config() || !hasBunnyUploadsConfig()) return;
warnedAboutConflictingUploadFlags = true;
logError(
'OPENFRAME_ENABLE_S3_VIDEO_UPLOADS and OPENFRAME_ENABLE_BUNNY_UPLOADS are both enabled with valid config. S3 video uploads take precedence; disable Bunny uploads for self-hosted deployments.',
new Error('Conflicting direct upload feature flags')
);
}
export function isStripeFeatureEnabled() {
return readBooleanEnv('OPENFRAME_ENABLE_STRIPE', true);
}
@@ -32,10 +48,52 @@ export function hasBunnyUploadsConfig() {
);
}
export function isS3VideoUploadsFeatureEnabled() {
return readBooleanEnv('OPENFRAME_ENABLE_S3_VIDEO_UPLOADS', false);
}
export function hasR2Config() {
return Boolean(
process.env.R2_ACCESS_KEY_ID &&
process.env.R2_SECRET_ACCESS_KEY &&
process.env.R2_BUCKET_NAME &&
(process.env.R2_ENDPOINT || process.env.R2_ACCOUNT_ID)
);
}
export function isS3VideoUploadsEnabled() {
warnIfConflictingDirectUploadFlags();
return isS3VideoUploadsFeatureEnabled() && hasR2Config();
}
export function isBunnyUploadsEnabled() {
if (isS3VideoUploadsEnabled()) {
return false;
}
return isBunnyUploadsFeatureEnabled() && hasBunnyUploadsConfig();
}
export function isDirectFileUploadEnabled() {
return isS3VideoUploadsEnabled() || isBunnyUploadsEnabled();
}
export function getMaxVideoUploadBytes(): bigint {
const raw = process.env.OPENFRAME_MAX_VIDEO_UPLOAD_BYTES?.trim();
if (!raw) {
return BigInt(5) * BigInt(1024) * BigInt(1024) * BigInt(1024);
}
try {
const parsed = BigInt(raw);
if (parsed <= BigInt(0)) {
return BigInt(5) * BigInt(1024) * BigInt(1024) * BigInt(1024);
}
return parsed;
} catch {
return BigInt(5) * BigInt(1024) * BigInt(1024) * BigInt(1024);
}
}
export function isInviteCodeRequired() {
return readBooleanEnv('OPENFRAME_REQUIRE_INVITE_CODE', true);
}