Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions app/api/artworks/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ async function uploadFileToStorage(file: File) {
const timestamp = Date.now()
const sanitizedName = file.name.replaceAll(' ', '_')
const publicUrl = `https://mock-storage.com/artworks/${timestamp}-${sanitizedName}`
const thumbnailUrl = publicUrl.replace(/\.(jpg|jpeg|png|gif|webp)$/i, '_thumb.$1')

const thumbnailUrl = publicUrl.replace(
/\.(jpg|jpeg|png|gif|webp)$/i,
'_thumb.$1'
)

return { publicUrl, thumbnailUrl }
}

Expand Down Expand Up @@ -79,25 +82,19 @@ export async function POST(req: Request) {
// Extract required fields
const file = formData.get('file') as File | null
const title = formData.get('title') as string

// Extract optional fields
const description = formData.get('description') as string | null
const tools_used = formData.get('tools_used') as string | null
const project_type = formData.get('project_type') as string | null

// Validation
if (!file) {
return NextResponse.json(
{ error: 'File is required.' },
{ status: 400 }
)
return NextResponse.json({ error: 'File is required.' }, { status: 400 })
}

if (!title || title.trim().length === 0) {
return NextResponse.json(
{ error: 'Title is required.' },
{ status: 400 }
)
return NextResponse.json({ error: 'Title is required.' }, { status: 400 })
}

if (title.length > 500) {
Expand Down Expand Up @@ -145,7 +142,8 @@ export async function POST(req: Request) {
thumbnail_url,
status: 'PENDING' as const,
user_id: session.user.id,
submitted_by_name: session.user.username || session.user.name || 'Anonymous',
submitted_by_name:
session.user.username || session.user.name || 'Anonymous',
description: description?.trim() || null,
tools_used: tools_used ? [tools_used] : [],
project_type: project_type || null,
Expand Down Expand Up @@ -174,6 +172,3 @@ export async function POST(req: Request) {
)
}
}



Loading