- Bloc Link Preview : colle une URL → carte avec titre, description, image, favicon - API /api/link-preview : extraction OpenGraph + meta tags - API /api/image-proxy : contourne le hotlinking (Referer spoofing) - Métadonnées persistées en HTML (data-preview JSON) — pas de refetch au reload - Texte indexable : titre + description + URL inclus pour recherche/embeddings - Modal propre pour saisir l'URL (plus de prompt()) - Slash menu + smart paste 'Coller comme carte aperçu' - i18n FR/EN complet - Fix: bouton calendrier retiré du sélecteur de vue
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export async function GET(req: NextRequest) {
|
|
const url = req.nextUrl.searchParams.get('url')
|
|
if (!url) return NextResponse.json({ error: 'Missing url' }, { status: 400 })
|
|
|
|
try {
|
|
const parsed = new URL(url)
|
|
if (!['http:', 'https:'].includes(parsed.protocol)) {
|
|
return NextResponse.json({ error: 'Invalid protocol' }, { status: 400 })
|
|
}
|
|
|
|
const controller = new AbortController()
|
|
const timeout = setTimeout(() => controller.abort(), 5000)
|
|
|
|
const res = await fetch(url, {
|
|
signal: controller.signal,
|
|
headers: {
|
|
'User-Agent': 'Mozilla/5.0 (compatible; MementoBot/1.0)',
|
|
'Accept': 'image/*',
|
|
'Referer': parsed.origin,
|
|
},
|
|
})
|
|
clearTimeout(timeout)
|
|
|
|
if (!res.ok) return NextResponse.json({ error: 'Fetch failed' }, { status: 502 })
|
|
|
|
const contentType = res.headers.get('content-type') || 'image/jpeg'
|
|
if (!contentType.startsWith('image/')) {
|
|
return NextResponse.json({ error: 'Not an image' }, { status: 400 })
|
|
}
|
|
|
|
const buffer = await res.arrayBuffer()
|
|
return new NextResponse(buffer, {
|
|
headers: {
|
|
'Content-Type': contentType,
|
|
'Cache-Control': 'public, s-maxage=604800',
|
|
},
|
|
})
|
|
} catch {
|
|
return NextResponse.json({ error: 'Failed' }, { status: 502 })
|
|
}
|
|
}
|