From 90f4b2c916cdd7f61843c7a2c7f4451d44e18367 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 17 Jun 2022 14:55:34 -0500 Subject: Fix being ratelimited sometimes --- src/lib/api.ts | 19 +++++++++++++++++-- src/lib/sections/Leaderboards.svelte | 4 ++-- src/lib/sections/Zones.svelte | 2 +- src/routes/__error.svelte | 4 ++-- src/routes/auctionprices.svelte | 10 +++++----- src/routes/election.svelte | 4 ++-- src/routes/items.svelte | 4 ++-- src/routes/leaderboards/[name].svelte | 4 ++-- src/routes/leaderboards/index.svelte | 6 +++--- src/routes/loggedin.ts | 4 ++-- src/routes/logout.ts | 4 ++-- src/routes/player/[player]/[profile].svelte | 7 ++++--- src/routes/player/[player]/index.svelte | 4 ++-- src/routes/profile/index.svelte | 6 +++--- src/routes/profile/update.ts | 6 +++--- src/routes/verify.ts | 8 ++++---- 16 files changed, 56 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/lib/api.ts b/src/lib/api.ts index e3559e1..552607c 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,3 +1,18 @@ +import env from './env' + // the trailing slash is required -export const API_URL = 'https://skyblock-api.matdoes.dev/' -// export const API_URL = 'http://localhost:8080/' \ No newline at end of file +const API_URL = 'https://skyblock-api.matdoes.dev/' +// export const API_URL = 'http://localhost:8080/' + +export async function fetchApi(path: string, fetch: (info: RequestInfo, init?: RequestInit | undefined) => Promise, init?: RequestInit | undefined) { + const { SKYBLOCK_STATS_API_KEY } = env() + if (SKYBLOCK_STATS_API_KEY) { + init = init || {} + if (!init.headers) + init.headers = {} + init.headers['key'] = SKYBLOCK_STATS_API_KEY + } + + const response = await fetch(API_URL + path, init) + return response +} \ No newline at end of file diff --git a/src/lib/sections/Leaderboards.svelte b/src/lib/sections/Leaderboards.svelte index 7e32958..817f59a 100644 --- a/src/lib/sections/Leaderboards.svelte +++ b/src/lib/sections/Leaderboards.svelte @@ -1,5 +1,5 @@ -{#await fetch(`${API_URL}player/${data.member.uuid}/${data.profile.uuid}/leaderboards`).then( r => r.json() )} +{#await fetchApi(`player/${data.member.uuid}/${data.profile.uuid}/leaderboards`, fetch).then( r => r.json() )} Loading... {:then leaderboards} {#if leaderboards.length > 0} diff --git a/src/lib/sections/Zones.svelte b/src/lib/sections/Zones.svelte index ef96456..f7e993b 100644 --- a/src/lib/sections/Zones.svelte +++ b/src/lib/sections/Zones.svelte @@ -1,6 +1,6 @@