Something went wrong. Try again.
data endpoint for entity 90008 (aka. a website)
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475import { env } from '$env/dynamic/private';import SGDB from 'steamgriddb';import { readFile, writeFile } from 'node:fs/promises';import { get, writable } from 'svelte/store';
const STEAM_ID = '76561198106829949';const GET_PLAYER_SUMMARY_ENDPOINT = `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${env.STEAM_API_KEY}&steamids=${STEAM_ID}&format=json`;const LAST_GAME_FILE = `${env.WEBSITE_DATA_DIR}/last_game.json`;
type LastGame = { name: string; link: string; icon: string; pfp: string; when: number; playing: boolean;};
const steamgriddbClient = writable<SGDB | null>(null);const lastGame = writable<LastGame | null>(null);
export const steamReadLastGame = async () => { try { const data = await readFile(LAST_GAME_FILE, 'utf8'); lastGame.set(JSON.parse(data)); } catch (why) { console.log('could not read last game: ', why); lastGame.set(null); }};
export const steamUpdateNowPlaying = async () => { let griddbClient = get(steamgriddbClient); if (griddbClient === null) { griddbClient = new SGDB(env.STEAMGRIDDB_API_KEY); steamgriddbClient.set(griddbClient); } try { const profile = (await (await fetch(GET_PLAYER_SUMMARY_ENDPOINT)).json()).response.players[0]; if (!profile.gameid) { lastGame.update((t) => { if (t !== null) { t.playing = false; } return t; }); return; } const icons = await griddbClient.getIconsBySteamAppId(profile.gameid, ['official', 'custom']); //console.log(icons) const game: LastGame = { name: profile.gameextrainfo, link: `https://store.steampowered.com/app/${profile.gameid}`, icon: icons[0].thumb.toString(), pfp: profile.avatarmedium, when: Date.now(), playing: true }; lastGame.set(game); await writeFile(LAST_GAME_FILE, JSON.stringify(game), 'utf8'); } catch (why) { console.log('could not fetch steam: ', why); lastGame.update((t) => { if (t !== null) { t.playing = false; } return t; }); }};
export const getLastGame = () => { return get(lastGame);};