aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-11-09 21:32:21 -0800
committerFuwn <[email protected]>2023-11-09 21:32:21 -0800
commitbd1de955e870313d7fe6cc743f1a512512490674 (patch)
treecced846b6aa75a03bcd9b06d6ad059d6eb8fb377
parentfix(media): remove rest of ignored (diff)
downloaddue.moe-bd1de955e870313d7fe6cc743f1a512512490674.tar.xz
due.moe-bd1de955e870313d7fe6cc743f1a512512490674.zip
refactor(media): collection to common template
-rw-r--r--src/lib/AniList/media.ts56
1 files changed, 26 insertions, 30 deletions
diff --git a/src/lib/AniList/media.ts b/src/lib/AniList/media.ts
index 0dfcecf6..7fd52645 100644
--- a/src/lib/AniList/media.ts
+++ b/src/lib/AniList/media.ts
@@ -63,6 +63,30 @@ export const flattenLists = (lists: { name: string; entries: { media: Media }[]
return Array.from(new Set(flattenedList.filter((media) => !ignoredMediaIds.includes(media.id))));
};
+const collectionQueryTemplate = (type: Type, userId: number, includeCompleted: boolean) =>
+ `{
+ MediaListCollection(
+ userId: ${userId},
+ type: ${type === Type.Anime ? 'ANIME' : 'MANGA'}
+ ${includeCompleted ? '' : ', status_not_in: [ COMPLETED ]'}) {
+ lists {
+ name entries {
+ media {
+ id status type episodes chapters format
+ title { romaji english native }
+ nextAiringEpisode { episode timeUntilAiring }
+ mediaListEntry {
+ progress progressVolumes status
+ score(format: POINT_100) startedAt { year }
+ }
+ startDate { year }
+ coverImage { extraLarge }
+ }
+ }
+ }
+ }
+}`;
+
export const mediaListCollection = async (
anilistAuthorisation: AniListAuthorisation,
userIdentity: UserIdentity,
@@ -115,22 +139,7 @@ export const mediaListCollection = async (
Accept: 'application/json'
},
body: JSON.stringify({
- query: `{ MediaListCollection(userId: ${userIdentity.id}, type: ${
- type === Type.Anime ? 'ANIME' : 'MANGA'
- }${includeCompleted ? '' : ', status_not_in: [ COMPLETED ]'}) {
- lists { name entries { media {
- id status type episodes chapters format
- title { romaji english native }
- nextAiringEpisode { episode timeUntilAiring }
- mediaListEntry {
- progress progressVolumes status
- score(format: POINT_100) startedAt { year }
- }
- startDate { year }
- coverImage { extraLarge }
- } } }
- }
- }`
+ query: collectionQueryTemplate(type, userIdentity.id, includeCompleted)
})
})
).json();
@@ -159,20 +168,7 @@ export const publicMediaListCollection = async (userId: number, type: Type): Pro
Accept: 'application/json'
},
body: JSON.stringify({
- query: `{ MediaListCollection(userId: ${userId}, type: ${
- type === Type.Anime ? 'ANIME' : 'MANGA'
- }, status_not_in: [ COMPLETED ]) { lists { name entries { media {
- id
- status
- type
- episodes
- format
- title { romaji english native }
- nextAiringEpisode { episode timeUntilAiring }
- mediaListEntry { progress status }
- startDate { year }
- } } } }
- }`
+ query: collectionQueryTemplate(type, userId, false)
})
})
).json();