Files
sfera-new/src/app/api/placeholder/[...params]/route.ts

50 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ params: string[] }> }
) {
try {
const resolvedParams = await params
const [width, height] = resolvedParams.params[0]?.split('/') || ['400', '400']
const searchParams = request.nextUrl.searchParams
const text = searchParams.get('text') || 'Image'
// Создаем простое SVG изображение
const svg = `
<svg width="${width}" height="${height}" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#f0f0f0"/>
<text x="50%" y="50%" text-anchor="middle" dominant-baseline="middle"
font-family="Arial, sans-serif" font-size="16" fill="#666">
${text} ${width}x${height}
</text>
</svg>
`
return new NextResponse(svg, {
headers: {
'Content-Type': 'image/svg+xml',
'Cache-Control': 'public, max-age=31536000'
}
})
} catch (error) {
console.error('Placeholder API error:', error)
// Возвращаем простое SVG в случае ошибки
const svg = `
<svg width="400" height="400" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#f0f0f0"/>
<text x="50%" y="50%" text-anchor="middle" dominant-baseline="middle"
font-family="Arial, sans-serif" font-size="16" fill="#666">
No Image
</text>
</svg>
`
return new NextResponse(svg, {
headers: {
'Content-Type': 'image/svg+xml'
}
})
}
}