Download frontend/src/app/api/admin/runtime-settings/route.ts from new-arc/vector: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/app/api/admin/runtime-settings/route.ts
- Command line
-
hf download hf://spaces/new-arc/vector/frontend/src/app/api/admin/runtime-settings/route.ts
-
curl -L -o route.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/app/api/admin/runtime-settings/route.ts
1.38 kB
| import { NextResponse } from "next/server"; | |
| import { createTextProxyResponse, fetchBackend } from "@/server/backend-api"; | |
| import { getServerSession } from "@/server/session"; | |
| async function requireAdmin() { | |
| const session = await getServerSession(); | |
| if (!session?.user?.id) { | |
| return { error: NextResponse.json({ error: "Unauthorized" }, { status: 401 }) }; | |
| } | |
| const isAdmin = Boolean((session.user as { is_admin?: boolean }).is_admin); | |
| if (!isAdmin) { | |
| return { error: NextResponse.json({ error: "Forbidden" }, { status: 403 }) }; | |
| } | |
| return { session }; | |
| } | |
| export async function GET() { | |
| const adminCheck = await requireAdmin(); | |
| if (adminCheck.error) { | |
| return adminCheck.error; | |
| } | |
| const upstream = await fetchBackend("/admin/runtime-settings", { | |
| method: "GET", | |
| userId: adminCheck.session.user.id, | |
| cache: "no-store", | |
| }); | |
| return createTextProxyResponse(upstream); | |
| } | |
| export async function PATCH(request: Request) { | |
| const adminCheck = await requireAdmin(); | |
| if (adminCheck.error) { | |
| return adminCheck.error; | |
| } | |
| const body = await request.text(); | |
| const upstream = await fetchBackend("/admin/runtime-settings", { | |
| method: "PATCH", | |
| userId: adminCheck.session.user.id, | |
| extraHeaders: { "Content-Type": "application/json" }, | |
| body, | |
| cache: "no-store", | |
| }); | |
| return createTextProxyResponse(upstream); | |
| } | |