diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/api.ts | 19 | ||||
-rw-r--r-- | src/lib/sections/Leaderboards.svelte | 4 | ||||
-rw-r--r-- | src/lib/sections/Zones.svelte | 2 |
3 files changed, 20 insertions, 5 deletions
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<Response>, 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 @@ <script lang="ts"> - import { API_URL } from '$lib/api' + import { fetchApi } from '$lib/api' import type { CleanMemberProfile } from '$lib/APITypes' import Emoji from '$lib/Emoji.svelte' @@ -8,7 +8,7 @@ export let data: CleanMemberProfile </script> -{#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 @@ <script lang="ts"> import type { CleanMemberProfile } from '$lib/APITypes' - import { cleanId, toRomanNumerals } from '$lib/utils' + import { cleanId } from '$lib/utils' export let data: CleanMemberProfile |