30 lines
820 B
TypeScript
30 lines
820 B
TypeScript
import { errorResponse } from "@/lib/security/http";
|
|
import { limitRequest, trustedClientAddress } from "@/lib/security/rate-limit";
|
|
import { connection } from "next/server";
|
|
|
|
import {
|
|
AdminAuthorizationError,
|
|
requireAdmin,
|
|
} from "@/lib/auth/server";
|
|
import {
|
|
createRedisEventResponse,
|
|
} from "@/lib/events/redis-stream";
|
|
|
|
export async function GET(request: Request) {
|
|
await connection();
|
|
try {
|
|
await requireAdmin();
|
|
} catch (cause) {
|
|
if (cause instanceof AdminAuthorizationError) {
|
|
return Response.json({ error: "unauthorized" }, { status: 401 });
|
|
}
|
|
throw cause;
|
|
}
|
|
try {
|
|
await limitRequest("stream-open", trustedClientAddress(request.headers), 60);
|
|
return await createRedisEventResponse("admin", request.signal);
|
|
} catch (cause) {
|
|
return errorResponse(cause);
|
|
}
|
|
}
|