mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-05 18:48:41 +00:00
32 lines
919 B
TypeScript
32 lines
919 B
TypeScript
import type { PageServerLoad } from './$types';
|
|
import type { Paste } from '$lib/types/paste';
|
|
import { getShiki } from '$lib/server/shiki';
|
|
|
|
export const load: PageServerLoad = async ({ params, fetch }) => {
|
|
const { id } = params;
|
|
|
|
const paste = await fetch(`/api/paste/${id}`);
|
|
if (paste.status === 404) {
|
|
return {
|
|
status: 404,
|
|
error: { message: 'Paste not found' }
|
|
};
|
|
}
|
|
const pasteData = (await paste.json()) as Paste;
|
|
const pasteContent = await fetch(`/api/paste/raw/${id}`);
|
|
const pasteOptions = await fetch('/api/paste/create/options');
|
|
const options = await pasteOptions.json();
|
|
const content = await pasteContent.text();
|
|
|
|
let highlighted = '';
|
|
if (pasteData && content) {
|
|
const shiki = await getShiki();
|
|
highlighted = shiki.codeToHtml(content, {
|
|
lang: pasteData.syntax || 'plaintext',
|
|
theme: 'github-dark'
|
|
});
|
|
}
|
|
|
|
return { paste: pasteData, content, options, highlighted };
|
|
};
|