| 17 | }) |
| 18 | |
| 19 | export async function GET(req: NextRequest) { |
| 20 | const { searchParams } = new URL(req.url) |
| 21 | const id = searchParams.get('id') |
| 22 | if (!id) return new Response('Missing id', { status: 400 }) |
| 23 | |
| 24 | const value = await redis.get<number[]>(`reactions:${id}`) |
| 25 | if (!value) { |
| 26 | await redis.set(getKey(id), [0, 0, 0, 0]) |
| 27 | } |
| 28 | |
| 29 | const { success } = await ratelimit.limit(getKey(id) + `_${req.ip ?? ''}`) |
| 30 | if (!success) { |
| 31 | return new Response('Too Many Requests', { |
| 32 | status: 429, |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | return NextResponse.json(value ?? [0, 0, 0, 0]) |
| 37 | } |
| 38 | |
| 39 | export async function PATCH(req: NextRequest) { |
| 40 | const { searchParams } = new URL(req.url) |