From f44c9c40b3035a50aa2c2a25ae7d3140ddcd460e Mon Sep 17 00:00:00 2001 From: bender Date: Sun, 8 Mar 2026 08:39:36 +0000 Subject: [PATCH] Add src/app/api/upload-video/route.ts --- src/app/api/upload-video/route.ts | 72 +++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/app/api/upload-video/route.ts diff --git a/src/app/api/upload-video/route.ts b/src/app/api/upload-video/route.ts new file mode 100644 index 0000000..86ee5bf --- /dev/null +++ b/src/app/api/upload-video/route.ts @@ -0,0 +1,72 @@ +import { NextRequest, NextResponse } from 'next/server'; + +const MAX_FILE_SIZE = 500 * 1024 * 1024; // 500MB +const ALLOWED_FORMATS = ['video/mp4', 'video/mpeg', 'video/quicktime', 'video/x-msvideo']; + +export async function POST(request: NextRequest) { + try { + const formData = await request.formData(); + const file = formData.get('file') as File; + const title = formData.get('title') as string; + const description = formData.get('description') as string; + + // Validation + if (!file) { + return NextResponse.json( + { message: 'No file provided' }, + { status: 400 } + ); + } + + if (!title || title.trim().length === 0) { + return NextResponse.json( + { message: 'Video title is required' }, + { status: 400 } + ); + } + + if (file.size > MAX_FILE_SIZE) { + return NextResponse.json( + { message: `File size exceeds ${MAX_FILE_SIZE / 1024 / 1024}MB limit` }, + { status: 413 } + ); + } + + if (!ALLOWED_FORMATS.includes(file.type)) { + return NextResponse.json( + { message: 'Invalid file format. Supported: MP4, MPEG, MOV, AVI' }, + { status: 415 } + ); + } + + // TODO: Implement actual file storage + // This could be: + // 1. Cloud storage (AWS S3, Google Cloud Storage, etc.) + // 2. Local file system (with proper permissions) + // 3. Database blob storage + // 4. CDN integration + + // For now, return success response + return NextResponse.json( + { + success: true, + message: 'Video uploaded successfully', + video: { + title, + description, + fileName: file.name, + fileSize: file.size, + mimeType: file.type, + uploadedAt: new Date().toISOString(), + }, + }, + { status: 201 } + ); + } catch (error) { + console.error('Video upload error:', error); + return NextResponse.json( + { message: 'Internal server error' }, + { status: 500 } + ); + } +}