From ccdb0009343ff445e2f90e50225527fcd4461a3d Mon Sep 17 00:00:00 2001 From: whoswhip Date: Fri, 9 Jan 2026 20:13:17 -0500 Subject: [PATCH] refactor: streamline API key handling in view increment logic --- SharpbinV3.Client/src/routes/[id]/+page.server.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/SharpbinV3.Client/src/routes/[id]/+page.server.ts b/SharpbinV3.Client/src/routes/[id]/+page.server.ts index 4966181..d82ef3a 100644 --- a/SharpbinV3.Client/src/routes/[id]/+page.server.ts +++ b/SharpbinV3.Client/src/routes/[id]/+page.server.ts @@ -15,11 +15,12 @@ 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(`/api/paste/${id}/view`, { method: 'POST', headers: { - 'X-Internal-API-Key': env.VIEW_INTERNAL_API_KEY ?? env.View_HMAC_Internal_API_Key ?? '', + 'X-Internal-API-Key': apiKey, Authorization: token ? `Bearer ${token}` : '' } }); @@ -33,6 +34,9 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => { } else { console.error(`Failed to increment view count for paste ${id}: ${await viewed.text()}`); + if (apiKey === '') { + console.error('The API key for internal requests is not set. Please configure it in the environment variables.'); + } } const pasteContent = await fetch(`/api/paste/${id}/raw`);