feat: integrate MinIO for video storage, add video routes, and update README with API documentation

This commit is contained in:
2025-12-07 17:10:00 +00:00
parent 93b5e289f3
commit bd3d17c192
6 changed files with 256 additions and 0 deletions

45
Backend/utils/minio.ts Normal file
View File

@@ -0,0 +1,45 @@
import { Client } from 'minio';
const endpoint = process.env.MINIO_ENDPOINT ?? 'localhost';
const port = Number(process.env.MINIO_PORT ?? 9000);
const useSSL = (process.env.MINIO_USE_SSL ?? 'false').toLowerCase() === 'true';
const accessKey = process.env.MINIO_ACCESS_KEY;
const secretKey = process.env.MINIO_SECRET_KEY;
if (!accessKey || !secretKey) {
throw new Error('MINIO_ACCESS_KEY and MINIO_SECRET_KEY must be set');
}
export const minioBucket = process.env.MINIO_BUCKET ?? 'videos';
export const minioPresignedExpirySeconds = Number(process.env.MINIO_PRESIGNED_EXPIRY_SECONDS ?? 60 * 10);
export const minioClient = new Client({
endPoint: endpoint,
port,
useSSL,
accessKey,
secretKey,
});
let ensureBucketPromise: Promise<void> | null = null;
export const ensureMinioBucket = async (): Promise<void> => {
if (ensureBucketPromise) {
return ensureBucketPromise;
}
ensureBucketPromise = (async () => {
const exists = await minioClient.bucketExists(minioBucket);
if (!exists) {
await minioClient.makeBucket(minioBucket, process.env.MINIO_REGION ?? 'us-east-1');
}
})();
try {
await ensureBucketPromise;
} catch (error) {
ensureBucketPromise = null;
throw error;
}
};