-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path+page.ts
27 lines (20 loc) · 1.08 KB
/
+page.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { PageLoad } from './$types';
import { HolodexApiClient, VideoStatus } from 'holodex.js';
import { fetchLastLiveData, fetchLiveUpcomingData } from '../utils';
import { AME_CHANNEL_ID, FREECHAT_REGEX } from '../const';
export const load: PageLoad = (async ({ params: { } }) => {
const channelId = AME_CHANNEL_ID; // the channel ID used for fetching all of the app's info
const client = new HolodexApiClient({ apiKey: '4c00fb7c-68f8-4fd7-8bd5-475783f233f6' });
let data = async () => {
let currentLiveAndUpcoming = await fetchLiveUpcomingData(client, channelId);
let pastVideo = await fetchLastLiveData(client, channelId);
let liveVideo = currentLiveAndUpcoming.find(video => video.status === VideoStatus.Live);
let nextVideo = currentLiveAndUpcoming
.sort((a, b) => a.scheduledStart.getTime() - b.scheduledStart.getTime())
.filter(video => !FREECHAT_REGEX.test(video.title))
.find(video => video.status === VideoStatus.Upcoming);
let title = "Amedoko - Home";
return { pastVideo, liveVideo, nextVideo, title };
};
return await data();
}) satisfies PageLoad;