import { MainLayout } from "@components/layouts/main.tsx";
import { PageProps } from "fresh";
import { AccessDeniedError } from "@lib/errors.ts";
import { getLogs, Log } from "@lib/log/index.ts";
import { formatDate } from "@lib/string.ts";
import { renderMarkdown } from "@lib/markdown.ts";
import { define } from "../../../utils.ts";
const renderLog = (t: unknown) =>
renderMarkdown(`\`\`\`js
${typeof t === "string" ? t : JSON.stringify(t, null, 2).trim()}
\`\`\``);
export const handler = define.handlers({
async GET(ctx) {
const logs = await getLogs();
if (!("session" in ctx.state)) {
throw new AccessDeniedError();
}
return {
data: {
logs: logs.map((l) => {
return {
...l,
html: l.args.map(renderLog).join("
"),
};
}),
},
};
},
});
function LogLine(
{ log }: {
log: Log & { html?: string };
},
) {
return (