🛡️ Sentinel: Add rate limiting to /api/og endpoint (#47)

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Ralksta
2026-03-27 10:36:25 +01:00
committed by GitHub
parent c8f75e4615
commit 43d5b4d15d
2 changed files with 15 additions and 10 deletions

View File

@@ -7,14 +7,22 @@
*/
import { ImageResponse } from 'next/og';
import { NextRequest } from 'next/server';
import { NextRequest, NextResponse } from 'next/server';
import { getConfig } from '@/lib/config';
import { checkRateLimit, getClientIp } from '@/lib/rate-limit';
export async function GET(request: NextRequest) {
const ip = getClientIp(request);
const { theme, rateLimitRpm } = getConfig();
const { success } = checkRateLimit(`og:${ip}`, rateLimitRpm);
if (!success) {
return new NextResponse('Too many requests', { status: 429 });
}
const { searchParams } = request.nextUrl;
const title = (searchParams.get('title') || 'Gallery').slice(0, 200);
const subtitle = (searchParams.get('subtitle') || '').slice(0, 100);
const { theme } = getConfig();
return new ImageResponse(
<div