mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
feat: Implement robust error/not-found pages & UI components
- Introduce dedicated error pages for dashboard and video routes - Add specific not-found pages for dashboard, projects, videos, and settings - Implement global `not-found.tsx` for general unhandled routes - Integrate root and dashboard layouts with ErrorBoundary and Suspense - Add new UI components: Accordion, Hover Card, Menubar, Navigation Menu, Select, Tabs - Update Navbar to utilize the new Navigation Menu component - Enhance `button` component with a `link` variant for better styling - Refine existing UI components (dialog, dropdown, input, etc.) - Update Tailwind config with new colors and animation extensions
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { r2Client, R2_BUCKET_NAME } from '@/lib/r2';
|
||||
import { GetObjectCommand } from '@aws-sdk/client-s3';
|
||||
import { apiErrors } from '@/lib/api-response';
|
||||
|
||||
// Only allow UUID filenames with safe extensions
|
||||
const SAFE_FILENAME = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.[a-z0-9]+$/i;
|
||||
@@ -14,7 +15,7 @@ export async function GET(
|
||||
|
||||
// Validate filename to prevent path traversal
|
||||
if (!SAFE_FILENAME.test(filename)) {
|
||||
return NextResponse.json({ error: 'Invalid filename' }, { status: 400 });
|
||||
return apiErrors.badRequest('Invalid filename');
|
||||
}
|
||||
|
||||
const key = `voice/${filename}`;
|
||||
@@ -27,7 +28,7 @@ export async function GET(
|
||||
);
|
||||
|
||||
if (!response.Body) {
|
||||
return NextResponse.json({ error: 'File not found' }, { status: 404 });
|
||||
return apiErrors.notFound('File');
|
||||
}
|
||||
|
||||
const contentType = response.ContentType || 'audio/webm';
|
||||
@@ -47,12 +48,9 @@ export async function GET(
|
||||
} catch (error: unknown) {
|
||||
const errorName = error instanceof Error ? error.name : '';
|
||||
if (errorName === 'NoSuchKey') {
|
||||
return NextResponse.json({ error: 'File not found' }, { status: 404 });
|
||||
return apiErrors.notFound('File');
|
||||
}
|
||||
console.error('Error serving audio:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to retrieve audio' },
|
||||
{ status: 500 }
|
||||
);
|
||||
return apiErrors.internalError('Failed to retrieve audio');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { auth } from '@/lib/auth';
|
||||
import { r2Client, R2_BUCKET_NAME } from '@/lib/r2';
|
||||
import { PutObjectCommand } from '@aws-sdk/client-s3';
|
||||
import { randomUUID } from 'crypto';
|
||||
import { rateLimit } from '@/lib/rate-limit';
|
||||
import { apiErrors, successResponse } from '@/lib/api-response';
|
||||
|
||||
const MAX_FILE_SIZE = 10 * 1024 * 1024; // 10MB
|
||||
const ALLOWED_TYPES = ['audio/webm', 'audio/ogg', 'audio/mp4', 'audio/mpeg', 'audio/wav'];
|
||||
@@ -17,30 +17,24 @@ export async function POST(request: Request) {
|
||||
// Require authentication
|
||||
const session = await auth();
|
||||
if (!session?.user?.id) {
|
||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
||||
return apiErrors.unauthorized();
|
||||
}
|
||||
|
||||
const formData = await request.formData();
|
||||
const file = formData.get('audio') as File | null;
|
||||
|
||||
if (!file) {
|
||||
return NextResponse.json({ error: 'No audio file provided' }, { status: 400 });
|
||||
return apiErrors.badRequest('No audio file provided');
|
||||
}
|
||||
|
||||
if (file.size > MAX_FILE_SIZE) {
|
||||
return NextResponse.json(
|
||||
{ error: 'File too large. Maximum size is 10MB.' },
|
||||
{ status: 400 }
|
||||
);
|
||||
return apiErrors.badRequest('File too large. Maximum size is 10MB.');
|
||||
}
|
||||
|
||||
// Check content type
|
||||
const contentType = file.type || 'audio/webm';
|
||||
if (!ALLOWED_TYPES.includes(contentType)) {
|
||||
return NextResponse.json(
|
||||
{ error: `Unsupported audio format: ${contentType}` },
|
||||
{ status: 400 }
|
||||
);
|
||||
return apiErrors.badRequest(`Unsupported audio format: ${contentType}`);
|
||||
}
|
||||
|
||||
// Generate unique filename
|
||||
@@ -65,12 +59,9 @@ export async function POST(request: Request) {
|
||||
// Return the URL through our proxy endpoint
|
||||
const voiceUrl = `/api/upload/audio/${filename}`;
|
||||
|
||||
return NextResponse.json({ url: voiceUrl }, { status: 201 });
|
||||
return successResponse({ url: voiceUrl }, 201);
|
||||
} catch (error) {
|
||||
console.error('Error uploading audio:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to upload audio' },
|
||||
{ status: 500 }
|
||||
);
|
||||
return apiErrors.internalError('Failed to upload audio');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user