feat: reports; improved+simplifed modals; extractError funcction;

refactor: change jwt claims to lowercase; use response dtos for sensitive data
fix: nullify user on token clears; change appsettings.dev View_Internal_API_Key
This commit is contained in:
2026-01-14 19:41:52 -05:00
parent 1da88dba4e
commit 67447d51ae
39 changed files with 2291 additions and 454 deletions
@@ -4,11 +4,23 @@ import { getServerToken } from '$lib/utils/auth';
import { env } from '$env/dynamic/private';
const apiUrl = process.env.VITE_API_URL || 'http://localhost:5050';
const apiKey =
env.NODE_ENV === 'development'
? 'cccdd42d9f2f648493e402f1da7c855ea798ad510e6bb9ea712dd7bed838e58'
: (env.VIEW_INTERNAL_API_KEY ?? env.View_HMAC_Internal_API_Key ?? '');
export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
export const load: PageServerLoad = async ({ params, fetch, url, cookies, parent }) => {
const { id } = params;
const parentData = await parent().catch(() => null);
const token = getServerToken(cookies);
const pasteRes = await fetch(`${apiUrl}/api/paste/${id}`, {
headers: {
Authorization: token ? `Bearer ${token}` : ''
}
});
const pasteRes = await fetch(`${apiUrl}/api/paste/${id}`);
if (pasteRes.status === 404) {
return {
status: 404,
@@ -16,9 +28,6 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
};
}
const token = getServerToken(cookies);
const apiKey = env.VIEW_INTERNAL_API_KEY ?? env.View_HMAC_Internal_API_Key ?? '';
const viewed = await fetch(`${apiUrl}/api/paste/${id}/view`, {
method: 'POST',
headers: {
@@ -29,7 +38,7 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
const pasteData = await pasteRes.json();
const paste = pasteData.paste as Paste;
if (viewed.status === 200) {
const viewJson = await viewed.json();
if (viewJson.success === true && viewJson.message !== 'View already recorded.') {
@@ -51,5 +60,14 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
const options = await pasteOptions.json();
const content = await pasteContent.text();
return { paste, content, options, url: url.href };
return {
paste,
content,
options,
authOptions:
parentData && typeof parentData === 'object' && parentData !== null && 'options' in parentData
? (parentData as { options?: unknown }).options
: null,
url: url.href
};
};