23 lines
1,001 B
TypeScript
23 lines
1,001 B
TypeScript
// OVE — /api/ove-directory/scripts/[id]: fetch one full record (including
|
|
// the hash string) by numeric id — the "Get" flow's first hop.
|
|
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
import { dirConfig, dirFetch, jsonError, oveRateCheck, visitorIp } from '@/lib/server/ove-directory'
|
|
|
|
export const dynamic = 'force-dynamic'
|
|
|
|
export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) {
|
|
const wait = oveRateCheck(visitorIp(req))
|
|
if (wait !== null) {
|
|
return jsonError(429, 'RATE_LIMITED', 'Too many directory requests. Try again shortly.')
|
|
}
|
|
if (!dirConfig()) {
|
|
return jsonError(500, 'NOT_CONFIGURED', 'OVE-Directory is not configured on this server.')
|
|
}
|
|
const { id } = await params
|
|
if (!/^\d+$/.test(id) || Number.parseInt(id, 10) < 1) {
|
|
return jsonError(400, 'VALIDATION', 'id must be a positive integer.', 'id')
|
|
}
|
|
const r = await dirFetch(`/v1/scripts/${id}`)
|
|
return NextResponse.json(r.data, { status: r.status })
|
|
}
|