mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
refactor: streamline API key handling in view increment logic
This commit is contained in:
@@ -15,11 +15,12 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const token = getServerToken(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`, {
|
const viewed = await fetch(`/api/paste/${id}/view`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
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}` : ''
|
Authorization: token ? `Bearer ${token}` : ''
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -33,6 +34,9 @@ export const load: PageServerLoad = async ({ params, fetch, url, cookies }) => {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.error(`Failed to increment view count for paste ${id}: ${await viewed.text()}`);
|
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`);
|
const pasteContent = await fetch(`/api/paste/${id}/raw`);
|
||||||
|
|||||||
Reference in New Issue
Block a user