Add src/app/api/upload-video/route.ts
This commit is contained in:
72
src/app/api/upload-video/route.ts
Normal file
72
src/app/api/upload-video/route.ts
Normal file
@@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user