-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
122 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import { TORU_API_URL } from '$lib/consts'; | ||
import Logger from '$lib/logger'; | ||
|
||
import type { PageLoad } from './$types'; | ||
import type { ToruData } from '$components/experiments/toru'; | ||
|
||
export const load = (async ({ fetch }) => { | ||
let nowPlayingData: ToruData | undefined = undefined; | ||
export const load = (({ fetch }) => { | ||
const nowPlayingData = fetch(`${TORU_API_URL}/kiosion?res=json&cover_size=medium`) | ||
.then((res) => { | ||
if (!res.ok) { | ||
throw new Error('Failed to fetch now playing data'); | ||
} | ||
|
||
try { | ||
const toruRes = await fetch( | ||
'https://toru.kio.dev/api/v1/kiosion?res=json&cover_size=large' | ||
); | ||
return res | ||
.json() | ||
.then((data) => data.data) | ||
.catch((e) => { | ||
throw new Error('Failed to parse now playing data', e); | ||
}); | ||
}) | ||
.catch((e) => { | ||
Logger.error(e); | ||
|
||
if (toruRes.ok) { | ||
nowPlayingData = await toruRes.json().then((data) => data.data); | ||
} | ||
// eslint-disable-next-line no-empty | ||
} catch {} | ||
return undefined; | ||
}) satisfies Promise<ToruData | undefined>; | ||
|
||
return { fetch, nowPlayingData }; | ||
}) satisfies PageLoad; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters