Add frontend
This commit is contained in:
22
frontend/src/routes/scripts/[id]/+page.server.ts
Normal file
22
frontend/src/routes/scripts/[id]/+page.server.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { error } from '@sveltejs/kit';
|
||||
import { fetchScriptById, fetchLogs } from '$lib/api';
|
||||
import type { Log } from '$lib/api';
|
||||
|
||||
export async function load({ params }) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const script = await fetchScriptById(parseInt(id));
|
||||
const logs: Log[] = (await fetchLogs(script.id)).sort(
|
||||
(a, b) => new Date(b.created_at!).getTime() - new Date(a.created_at!).getTime()
|
||||
);
|
||||
|
||||
if (!script) {
|
||||
throw error(404, 'Script not found');
|
||||
}
|
||||
|
||||
return { script, logs };
|
||||
} catch (err) {
|
||||
throw error(500, 'Failed to fetch script data - ' + err);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user