From 06cc45c4debf253469db26646ee02cdc877aad85 Mon Sep 17 00:00:00 2001 From: dusk Date: Tue, 19 Nov 2024 01:28:50 +0300 Subject: [PATCH] fix: put steamgriddb client behind store --- src/lib/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/lib/index.ts b/src/lib/index.ts index 97f23c6..d8e54f8 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -59,10 +59,15 @@ export const lastFmGetNowPlaying: () => Promise = async () => } } -const steamgriddbClient = new SGDB(env.STEAMGRIDDB_API_KEY); +const steamgriddbClient = writable(null); const cachedLastGame = writable<{game: LastGame | null, since: number}>({game: null, since: 0}) export type LastGame = {name: string, link: string, icon: string, pfp: string} export const steamGetNowPlaying: () => Promise = async () => { + var griddbClient = get(steamgriddbClient) + if (griddbClient === null) { + griddbClient = new SGDB(env.STEAMGRIDDB_API_KEY) + steamgriddbClient.set(griddbClient) + } var cached = get(cachedLastGame) if (Date.now() - cached.since < 10 * 1000) { return cached.game @@ -73,7 +78,7 @@ export const steamGetNowPlaying: () => Promise = async () => { if (!profile.gameid) { throw "no game is being played" } - var icons = await steamgriddbClient.getIconsBySteamAppId(profile.gameid, ['official']) + var icons = await griddbClient.getIconsBySteamAppId(profile.gameid, ['official']) console.log(icons) var game = { name: profile.gameextrainfo,