19 lines
706 B
TypeScript
19 lines
706 B
TypeScript
import { NextRequest } from 'next/server'
|
|
import { getServerSession } from 'next-auth'
|
|
import { authOptions } from '@/lib/auth'
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const session = await getServerSession(authOptions)
|
|
if (!session) return new Response('Non authentifié', { status: 401 })
|
|
|
|
const url = req.nextUrl.searchParams.get('url')
|
|
if (!url) return new Response('url requis', { status: 400 })
|
|
|
|
const res = await fetch(url)
|
|
if (!res.ok) return new Response('Fetch failed', { status: 502 })
|
|
|
|
const buffer = await res.arrayBuffer()
|
|
const contentType = res.headers.get('content-type') ?? 'image/jpeg'
|
|
return new Response(buffer, { headers: { 'Content-Type': contentType } })
|
|
}
|