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
+36
View File
@@ -15,6 +15,41 @@ function resolveBunnyCdnHostname(): string | null {
const bunnyCdnHostname = resolveBunnyCdnHostname();
const isDev = process.env.NODE_ENV === 'development';
function resolveR2ConnectOrigins(): string[] {
const origins = new Set<string>();
for (const raw of [
process.env.R2_ENDPOINT?.trim(),
process.env.R2_PRESIGN_ENDPOINT?.trim(),
process.env.R2_PUBLIC_BASE_URL?.trim(),
]) {
if (!raw) continue;
try {
origins.add(new URL(raw).origin);
} catch {
// Ignore invalid custom endpoints in CSP generation.
}
}
const accountId = process.env.R2_ACCOUNT_ID?.trim();
const bucket = process.env.R2_BUCKET_NAME?.trim();
if (accountId) {
origins.add(`https://${accountId}.r2.cloudflarestorage.com`);
if (bucket) {
origins.add(`https://${bucket}.${accountId}.r2.cloudflarestorage.com`);
}
origins.add('https://*.r2.cloudflarestorage.com');
}
// Docker/MinIO self-hosted defaults. Keep unconditional because CSP is
// compiled at build time and build env may not include runtime self-hosted
// variables.
origins.add('http://localhost:9000');
origins.add('http://127.0.0.1:9000');
return [...origins];
}
// Build Content-Security-Policy from resolved config
const cdnOrigin = bunnyCdnHostname ? `https://${bunnyCdnHostname}` : '';
@@ -23,6 +58,7 @@ const connectSrcParts = [
'https://video.bunnycdn.com',
'https://www.youtube.com',
cdnOrigin,
...resolveR2ConnectOrigins(),
// Allow Next.js HMR websocket in development
...(isDev ? ['ws://localhost:* wss://localhost:*'] : []),
].filter(Boolean);