mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: paste creation; paste viewing; more langs supported; jwt settings class; paste settings class; data validation on paste metadata modification
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { getShiki } from '$lib/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();
|
||||
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 };
|
||||
};
|
||||
Reference in New Issue
Block a user