g1t/apps/web/app/routes/repo/actions-artifact.ts
| 1 | import type { Route } from "./+types/actions-artifact"; |
| 2 | import { readArtifact } from "../../lib/artifacts.server"; |
| 3 | import { actions } from "../../lib/services.server"; |
| 4 | import { getViewer } from "../../lib/session.server"; |
| 5 | |
| 6 | /** One artifact of a run, for anyone who can see the run. */ |
| 7 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 8 | const seen = await actions.run({ namespace: params.owner, name: params.repo }, getViewer(context), params.id); |
| 9 | if (!seen.ok) throw new Response("Not found.", { status: 404 }); |
| 10 | const bytes = await readArtifact(params.id, params.name); |
| 11 | if (!bytes) throw new Response("That artifact is gone: they are kept for 14 days.", { status: 404 }); |
| 12 | return new Response(bytes.buffer as ArrayBuffer, { |
| 13 | headers: { |
| 14 | "content-type": "application/gzip", |
| 15 | "content-disposition": `attachment; filename="${params.name.replace(/"/g, "")}.tar.gz"`, |
| 16 | }, |
| 17 | }); |
| 18 | } |