Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.
| Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2 | 1 | import { redirect } from "react-router"; |
| 2 | ||
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 3 | import type { Route } from "./+types/actions-artifact"; |
| Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2 | 4 | import { addresses } from "../../lib/addresses.server"; |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 5 | import { readArtifact } from "../../lib/artifacts.server"; |
| 6 | import { actions } from "../../lib/services.server"; | |
| 7 | import { getViewer } from "../../lib/session.server"; | |
| 8 | ||
| Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2 | 9 | /** |
| 10 | * One artifact of a run, for anyone who can see the run: a redirect to a | |
| 11 | * link the API signed for a few minutes, or, for one an older runner kept | |
| 12 | * in KV, its bytes. | |
| 13 | */ | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 14 | export async function loader({ params, context }: Route.LoaderArgs) { |
| Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2 | 15 | const repo = { namespace: params.owner, name: params.repo }; |
| 16 | const viewer = getViewer(context); | |
| 17 | const found = await actions.artifactDownload(repo, viewer, { run: params.id, name: params.name }); | |
| 18 | if (found.ok && found.value.blob) { | |
| 19 | throw redirect(`${addresses().api}/actions/toolkit/blobs/${found.value.blob}`); | |
| 20 | } | |
| 21 | const seen = await actions.run(repo, viewer, params.id); | |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 22 | if (!seen.ok) throw new Response("Not found.", { status: 404 }); |
| 23 | const bytes = await readArtifact(params.id, params.name); | |
| Actions: OIDC tokens, the toolkit's cache and artifact services, and artifacts in R2 | 24 | if (!bytes) throw new Response("That artifact is gone: it expired or was deleted.", { status: 404 }); |
| Actions: workflow_run, workflow.completed, artifacts on the run page, Node 24 | 25 | return new Response(bytes.buffer as ArrayBuffer, { |
| 26 | headers: { | |
| 27 | "content-type": "application/gzip", | |
| 28 | "content-disposition": `attachment; filename="${params.name.replace(/"/g, "")}.tar.gz"`, | |
| 29 | }, | |
| 30 | }); | |
| 31 | } |