diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/AniList/schedule.ts | 30 | ||||
| -rw-r--r-- | src/lib/Tools/Schedule/Tool.svelte | 2 |
2 files changed, 30 insertions, 2 deletions
diff --git a/src/lib/AniList/schedule.ts b/src/lib/AniList/schedule.ts index 63a40c8d..0db130ec 100644 --- a/src/lib/AniList/schedule.ts +++ b/src/lib/AniList/schedule.ts @@ -54,9 +54,12 @@ const schedulePage = async ( }) ).json(); +type Season = 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL'; + export const scheduleMediaListCollection = async ( year: number, - season: 'WINTER' | 'SPRING' | 'SUMMER' | 'FALL' + season: Season, + includeLastSeason = false ) => { const scheduledMedia = []; let page = 1; @@ -73,5 +76,30 @@ export const scheduleMediaListCollection = async ( for (const candidate of currentPage.data.Page.media) scheduledMedia.push(candidate); + if (includeLastSeason) { + const lastSeason = { + WINTER: 'FALL', + SPRING: 'WINTER', + SUMMER: 'SPRING', + FALL: 'SUMMER' + }[season]; + + const lastSeasonYear = season === 'WINTER' ? year - 1 : year; + + let page = 1; + let currentPage = await schedulePage(page, lastSeasonYear, lastSeason as Season); + + for (const candidate of currentPage.data.Page.media) scheduledMedia.push(candidate); + + while (currentPage['data']['Page']['pageInfo']['hasNextPage']) { + for (const candidate of currentPage.data.Page.media) scheduledMedia.push(candidate); + + page += 1; + currentPage = await schedulePage(page, lastSeasonYear, lastSeason as Season); + } + + for (const candidate of currentPage.data.Page.media) scheduledMedia.push(candidate); + } + return scheduledMedia as Partial<Media[]>; }; diff --git a/src/lib/Tools/Schedule/Tool.svelte b/src/lib/Tools/Schedule/Tool.svelte index 534dac5d..736023ed 100644 --- a/src/lib/Tools/Schedule/Tool.svelte +++ b/src/lib/Tools/Schedule/Tool.svelte @@ -28,7 +28,7 @@ onMount(async () => { subsPleasePromise = fetch(`/api/subsplease?tz=${timeZone}`).then((r) => r.json()); - scheduledMediaPromise = scheduleMediaListCollection(new Date().getFullYear(), season()); + scheduledMediaPromise = scheduleMediaListCollection(new Date().getFullYear(), season(), true); }); const shiftSubsPleaseSchedule = (schedule: SubsPlease['schedule']) => { |