Download frontend/src/app/api/share/[...path]/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/share/%5B...path%5D/route.ts
- Command line
-
hf download 'hf://spaces/new-arc/vector/frontend/src/app/api/share/[...path]/route.ts'
-
curl -L -o route.ts https://huggingface.co/spaces/new-arc/vector/resolve/main/frontend/src/app/api/share/%5B...path%5D/route.ts
1.38 kB
| import { createProxyResponse, fetchBackend } from "@/server/backend-api"; | |
| // Share tokens, clip IDs, and the fixed "clips"/"file" segments are all URL-safe; | |
| // anything else (".." traversal, encoded slashes) must not reach the backend URL. | |
| const SAFE_PATH_SEGMENT = /^[A-Za-z0-9_-]+$/; | |
| export async function GET( | |
| request: Request, | |
| { params }: { params: Promise<{ path: string[] }> }, | |
| ) { | |
| const { path } = await params; | |
| if (path.length === 0 || !path.every((segment) => SAFE_PATH_SEGMENT.test(segment))) { | |
| return Response.json({ detail: "Shared result not found" }, { status: 404 }); | |
| } | |
| const download = new URL(request.url).searchParams.get("download") === "true"; | |
| const upstream = await fetchBackend(`/tasks/shared/${path.join("/")}${download ? "?download=true" : ""}`, { | |
| method: "GET", | |
| // Close the backend stream even when the client leaves before headers arrive. | |
| signal: request.signal, | |
| extraHeaders: { | |
| ...(request.headers.get("accept") | |
| ? { Accept: request.headers.get("accept") as string } | |
| : {}), | |
| ...(request.headers.get("range") | |
| ? { Range: request.headers.get("range") as string } | |
| : {}), | |
| ...(request.headers.get("if-range") | |
| ? { "If-Range": request.headers.get("if-range") as string } | |
| : {}), | |
| }, | |
| cache: "no-store", | |
| }); | |
| return createProxyResponse(upstream); | |
| } | |