Add audio attachments with a paperclip composer control and a styled timeline player

Hop-State: A_06FP9RVYP3SNM80AM7SMF98
Hop-Proposal: R_06FP9RTB5CCV1SZR9B7YSY0
Hop-Task: T_06FP9QHMNTRHD9BZ3B4BVMG
Hop-Attempt: AT_06FP9QHMNV944FQ20714908
This commit is contained in:
2026-07-15 01:27:38 -07:00
committed by Hop
parent d1442dc903
commit 7f8a97ffe2
8 changed files with 290 additions and 30 deletions
+5 -7
View File
@@ -3,18 +3,16 @@ import { z } from 'zod';
import { requireAuth } from '@/lib/auth';
import { createUpload, StuffboxApiError } from '@/lib/stuffbox/client';
import { getStuffboxAccess } from '@/lib/stuffbox/tokens';
import { ALLOWED_MEDIA_TYPES, MAX_IMAGE_SIZE, MAX_AUDIO_SIZE, MAX_VIDEO_SIZE } from '@/lib/media/upload-policy';
const uploadSchema = z.object({
filename: z.string().min(1).max(255),
mimeType: z.enum([
'image/jpeg', 'image/png', 'image/gif', 'image/webp',
'video/mp4', 'video/webm', 'video/quicktime',
]),
size: z.number().int().positive().max(100 * 1024 * 1024),
mimeType: z.enum(ALLOWED_MEDIA_TYPES),
size: z.number().int().positive().max(Math.max(MAX_VIDEO_SIZE, MAX_AUDIO_SIZE)),
sha256: z.string().regex(/^[a-f0-9]{64}$/).optional(),
}).superRefine((upload, context) => {
if (upload.mimeType.startsWith('image/') && upload.size > 10 * 1024 * 1024) {
context.addIssue({ code: 'too_big', maximum: 10 * 1024 * 1024, origin: 'number', inclusive: true, path: ['size'], message: 'Images must be 10MB or smaller' });
if (upload.mimeType.startsWith('image/') && upload.size > MAX_IMAGE_SIZE) {
context.addIssue({ code: 'too_big', maximum: MAX_IMAGE_SIZE, origin: 'number', inclusive: true, path: ['size'], message: 'Images must be 10MB or smaller' });
}
});
+8 -13
View File
@@ -4,11 +4,7 @@ import { requireAuth } from '@/lib/auth';
import { getStorageSession, createStorageSession } from '@/lib/storage/session';
import { uploadWithStorageCredentials } from '@/lib/storage/s3';
import { v4 as uuidv4 } from 'uuid';
const MAX_IMAGE_SIZE = 10 * 1024 * 1024; // 10MB for images
const MAX_VIDEO_SIZE = 100 * 1024 * 1024; // 100MB for videos
const ALLOWED_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
const ALLOWED_VIDEO_TYPES = ['video/mp4', 'video/webm', 'video/quicktime'];
import { getMaxMediaSize, getMediaKind } from '@/lib/media/upload-policy';
export async function POST(req: NextRequest) {
try {
@@ -24,20 +20,19 @@ export async function POST(req: NextRequest) {
}
// Validate file type
const isImage = ALLOWED_IMAGE_TYPES.includes(file.type);
const isVideo = ALLOWED_VIDEO_TYPES.includes(file.type);
if (!isImage && !isVideo) {
const mediaKind = getMediaKind(file.type);
if (mediaKind === 'unsupported') {
return NextResponse.json({
error: 'Invalid file type. Allowed: JPEG, PNG, GIF, WebP, MP4, WebM, MOV'
error: 'Invalid file type. Upload an image, video, MP3, M4A, AAC, WAV, OGG, or FLAC file.'
}, { status: 400 });
}
// Validate file size based on type
const maxSize = isVideo ? MAX_VIDEO_SIZE : MAX_IMAGE_SIZE;
if (file.size > maxSize) {
const maxSize = getMaxMediaSize(file.type);
if (maxSize !== null && file.size > maxSize) {
return NextResponse.json({
error: `File too large. Maximum size: ${isVideo ? '100MB' : '10MB'}`
error: `File too large. Maximum size: ${mediaKind === 'image' ? '10MB' : '100MB'}`
}, { status: 400 });
}