| 1 | /** |
| 2 | * One job's whole log as plain text (`actions/jobs/:job/log.txt`), any |
| 3 | * attempt's, by the id the run page gives the job. For anyone who can see |
| 4 | * the run. |
| 5 | */ |
| 6 | import type { Route } from "./+types/actions-job-log-download"; |
| 7 | import { fileName, jobText } from "../../lib/log-lines"; |
| 8 | import { attachment, refused } from "../../lib/log-download.server"; |
| 9 | import { actions } from "../../lib/services.server"; |
| 10 | import { getViewer } from "../../lib/session.server"; |
| 11 | |
| 12 | export async function loader({ params, context }: Route.LoaderArgs) { |
| 13 | const repo = { namespace: params.owner, name: params.repo }; |
| 14 | const log = await actions.jobLogText(repo, getViewer(context), params.job); |
| 15 | if (!log.ok) return refused(log.error.code === "not_found" ? 404 : 400, log.error.message); |
| 16 | return attachment(jobText(log.value), "text/plain; charset=utf-8", `${fileName(log.value.name)}.txt`); |
| 17 | } |