main: second iter

Signed-off-by: nfel <nfilsaraee@gmail.com>
This commit is contained in:
2025-12-27 22:41:36 +03:30
parent 8a7842e263
commit 9a7e627329
33 changed files with 4865 additions and 81 deletions
+58
View File
@@ -0,0 +1,58 @@
import { NextRequest, NextResponse } from 'next/server';
import { uploadFileToS3, generateFileKey } from '@/lib/s3';
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get('file') as File;
const folder = formData.get('folder') as string || 'audio';
if (!file) {
return NextResponse.json({ error: 'No file provided' }, { status: 400 });
}
// Validate file type (audio only)
const allowedTypes = [
'audio/mpeg',
'audio/mp3',
'audio/wav',
'audio/ogg',
'audio/flac',
'audio/aac',
'audio/m4a',
];
if (!allowedTypes.includes(file.type)) {
return NextResponse.json(
{ error: 'Invalid file type. Only audio files are allowed.' },
{ status: 400 }
);
}
// Validate file size (max 50MB for audio)
const maxSize = 50 * 1024 * 1024; // 50MB
if (file.size > maxSize) {
return NextResponse.json(
{ error: 'File too large. Maximum size is 50MB.' },
{ status: 400 }
);
}
// Generate unique key
const key = generateFileKey(folder, file.name);
// Upload to S3
const url = await uploadFileToS3({
file,
key,
contentType: file.type,
});
return NextResponse.json({ url, key }, { status: 200 });
} catch (error) {
console.error('Audio upload error:', error);
return NextResponse.json(
{ error: 'Failed to upload audio file' },
{ status: 500 }
);
}
}
+50
View File
@@ -0,0 +1,50 @@
import { NextRequest, NextResponse } from 'next/server';
import { uploadFileToS3, generateFileKey } from '@/lib/s3';
export async function POST(request: NextRequest) {
try {
const formData = await request.formData();
const file = formData.get('file') as File;
const folder = formData.get('folder') as string || 'uploads';
if (!file) {
return NextResponse.json({ error: 'No file provided' }, { status: 400 });
}
// Validate file type (images only)
const allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/webp', 'image/gif'];
if (!allowedTypes.includes(file.type)) {
return NextResponse.json(
{ error: 'Invalid file type. Only images are allowed.' },
{ status: 400 }
);
}
// Validate file size (max 5MB)
const maxSize = 5 * 1024 * 1024; // 5MB
if (file.size > maxSize) {
return NextResponse.json(
{ error: 'File too large. Maximum size is 5MB.' },
{ status: 400 }
);
}
// Generate unique key
const key = generateFileKey(folder, file.name);
// Upload to S3
const url = await uploadFileToS3({
file,
key,
contentType: file.type,
});
return NextResponse.json({ url, key }, { status: 200 });
} catch (error) {
console.error('Upload error:', error);
return NextResponse.json(
{ error: 'Failed to upload file' },
{ status: 500 }
);
}
}