From 33ef28ae35692d22d7edc322c21c014b5be4dedd Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Mon, 23 Oct 2023 13:17:52 -0400 Subject: [PATCH] disallow viewing of future shows if not an admin --- src/routes/(site)/+error.svelte | 10 +++++++++- .../show/[show_number]/[slug]/[[tab]]/+page.server.ts | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/routes/(site)/+error.svelte b/src/routes/(site)/+error.svelte index f16c67cc2..f53b4f34e 100644 --- a/src/routes/(site)/+error.svelte +++ b/src/routes/(site)/+error.svelte @@ -1,4 +1,12 @@ + +

Oopsie-daisy

-

Something went wrong. Don't worry, we use Sentry!

+ {#if $page.error.message} +

{$page.error.message}

+ {:else} +

Something went wrong. Don't worry, we use Sentry!

+ {/if}
diff --git a/src/routes/(site)/show/[show_number]/[slug]/[[tab]]/+page.server.ts b/src/routes/(site)/show/[show_number]/[slug]/[[tab]]/+page.server.ts index 25225472a..be84492fa 100644 --- a/src/routes/(site)/show/[show_number]/[slug]/[[tab]]/+page.server.ts +++ b/src/routes/(site)/show/[show_number]/[slug]/[[tab]]/+page.server.ts @@ -9,6 +9,7 @@ import { cache } from '$lib/cache/cache'; import { transcript_with_utterances } from '$server/ai/queries.js'; import type { Prisma, Show } from '@prisma/client'; import type { PageServerLoad } from './$types'; +import { error } from '@sveltejs/kit'; export const load: PageServerLoad = async function ({ setHeaders, params, locals, url }) { const { show_number } = params; @@ -48,6 +49,14 @@ export const load: PageServerLoad = async function ({ setHeaders, params, locals } } + // Check if this is a future show + const now = new Date(); + const show_date = new Date(show_raw?.date || ''); + const is_admin = locals?.user?.roles?.includes('admin'); + if (show_date > now && !is_admin) { + throw error(401, `That is a show, but it's in the future! \n\nCome back ${show_date}`); + } + const body_excerpt = await unified() .use(remarkParse) .use(remarkGfm)