47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
|
|
import { ImageResponse } from '@vercel/og';
|
|||
|
|
import { NextRequest } from 'next/server';
|
|||
|
|
|
|||
|
|
export const runtime = 'edge';
|
|||
|
|
|
|||
|
|
export async function GET(req: NextRequest) {
|
|||
|
|
try {
|
|||
|
|
const { searchParams } = new URL(req.url);
|
|||
|
|
const width = parseInt(searchParams.get('width') || '400');
|
|||
|
|
const height = parseInt(searchParams.get('height') || '250');
|
|||
|
|
|
|||
|
|
if (isNaN(width) || isNaN(height) || width <= 0 || height <= 0) {
|
|||
|
|
return new Response('Invalid dimensions', { status: 400 });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return new ImageResponse(
|
|||
|
|
(
|
|||
|
|
<div
|
|||
|
|
style={{
|
|||
|
|
width: '100%',
|
|||
|
|
height: '100%',
|
|||
|
|
display: 'flex',
|
|||
|
|
flexDirection: 'column',
|
|||
|
|
alignItems: 'center',
|
|||
|
|
justifyContent: 'center',
|
|||
|
|
backgroundColor: '#f3f4f6',
|
|||
|
|
color: '#6b7280',
|
|||
|
|
fontSize: Math.min(width, height) / 10,
|
|||
|
|
fontWeight: 'bold',
|
|||
|
|
}}
|
|||
|
|
data-oid="h8zcpwb"
|
|||
|
|
>
|
|||
|
|
<div data-oid="33jg6mz">{`${width} × ${height}`}</div>
|
|||
|
|
</div>
|
|||
|
|
),
|
|||
|
|
|
|||
|
|
{
|
|||
|
|
width,
|
|||
|
|
height,
|
|||
|
|
},
|
|||
|
|
);
|
|||
|
|
} catch (e) {
|
|||
|
|
console.error(e);
|
|||
|
|
return new Response('Failed to generate image', { status: 500 });
|
|||
|
|
}
|
|||
|
|
}
|