aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-01-13 19:06:54 -0800
committerFuwn <[email protected]>2024-01-13 19:06:54 -0800
commit2094433fcd7ea9e3b7d44fd3972cbd8b1653237d (patch)
tree642b6570f746db8d6957e1f31f71ee771fe64fdc
parentrefactor(utility): move helpers to utility (diff)
downloaddue.moe-2094433fcd7ea9e3b7d44fd3972cbd8b1653237d.tar.xz
due.moe-2094433fcd7ea9e3b7d44fd3972cbd8b1653237d.zip
feat(schedule): include last season
-rw-r--r--src/lib/AniList/schedule.ts30
-rw-r--r--src/lib/Tools/Schedule/Tool.svelte2
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']) => {