import { navidromeFetch } from '@/lib/navidrome'

export async function GET(
  request: Request,
  { params }: { params: Promise<{ id: string }> }
) {
  const { id } = await params
  const { searchParams } = new URL(request.url)
  const size = searchParams.get('size') || '300'

  try {
    const res = await navidromeFetch('getCoverArt.view', { id, size })
    const contentType = res.headers.get('content-type') || 'image/jpeg'

    return new Response(res.body, {
      headers: {
        'Content-Type': contentType,
        'Cache-Control': 'public, max-age=604800',
      },
    })
  } catch (error) {
    console.error('Cover art error:', error)
    return new Response('Cover art failed', { status: 502 })
  }
}
