Skip to content
17 linesCodeBlameRaw
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 */
6import type { Route } from "./+types/actions-job-log-download";
7import { fileName, jobText } from "../../lib/log-lines";
8import { attachment, refused } from "../../lib/log-download.server";
9import { actions } from "../../lib/services.server";
10import { getViewer } from "../../lib/session.server";
11
12export 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}