aboutsummaryrefslogtreecommitdiff
path: root/src/lib/AniList/media.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/AniList/media.ts')
-rw-r--r--src/lib/AniList/media.ts76
1 files changed, 30 insertions, 46 deletions
diff --git a/src/lib/AniList/media.ts b/src/lib/AniList/media.ts
index 067db97a..6c0d02c6 100644
--- a/src/lib/AniList/media.ts
+++ b/src/lib/AniList/media.ts
@@ -62,20 +62,15 @@ export interface Media {
}
export const flattenLists = (lists: { name: string; entries: { media: Media }[] }[]) => {
- if (lists === undefined) {
- return [];
- }
+ if (lists === undefined) return [];
const flattenedList: Media[] = [];
const ignoredMediaIds: number[] = [];
- for (const list of lists) {
- if (list.name.toLowerCase().includes('#dueignore')) {
+ for (const list of lists)
+ if (list.name.toLowerCase().includes('#dueignore'))
ignoredMediaIds.push(...list.entries.map((entry) => entry.media.id));
- } else {
- flattenedList.push(...list.entries.map((entry) => entry.media));
- }
- }
+ else flattenedList.push(...list.entries.map((entry) => entry.media));
return flattenedList
.filter((media) => !ignoredMediaIds.includes(media.id))
@@ -120,16 +115,11 @@ export const mediaListCollection = async (
): Promise<Media[]> => {
let currentCacheMinutes;
- settings.subscribe((value) => {
- currentCacheMinutes = value.cacheMinutes;
- });
+ settings.subscribe((value) => (currentCacheMinutes = value.cacheMinutes));
if (String(currentLastPruneAt) === '') {
- if (type === Type.Anime) {
- lastPruneTimes.setKey('anime', new Date().getTime());
- } else {
- lastPruneTimes.setKey('manga', new Date().getTime());
- }
+ if (type === Type.Anime) lastPruneTimes.setKey('anime', new Date().getTime());
+ else lastPruneTimes.setKey('manga', new Date().getTime());
} else {
if (
(new Date().getTime() - Number(currentLastPruneAt)) / 1000 / 60 >
@@ -148,9 +138,7 @@ export const mediaListCollection = async (
}
}
- if (mediaCache !== undefined && mediaCache !== '') {
- return JSON.parse(mediaCache);
- }
+ if (mediaCache !== undefined && mediaCache !== '') return JSON.parse(mediaCache);
const userIdResponse = await (
await fetch('https://graphql.anilist.co', {
@@ -166,37 +154,36 @@ export const mediaListCollection = async (
})
).json();
- if (mediaCache === '') {
- if (type === Type.Anime) {
+ if (mediaCache === '')
+ if (type === Type.Anime)
anime.set(
JSON.stringify(flattenLists(userIdResponse['data']['MediaListCollection']['lists']))
);
- } else {
+ else
manga.set(
JSON.stringify(flattenLists(userIdResponse['data']['MediaListCollection']['lists']))
);
- }
- }
return flattenLists(userIdResponse['data']['MediaListCollection']['lists']);
};
-export const publicMediaListCollection = async (userId: number, type: Type): Promise<Media[]> => {
- const userIdResponse = await (
- await fetch('https://graphql.anilist.co', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Accept: 'application/json'
- },
- body: JSON.stringify({
- query: collectionQueryTemplate(type, userId, false)
- })
- })
- ).json();
-
- return flattenLists(userIdResponse['data']['MediaListCollection']['lists']);
-};
+export const publicMediaListCollection = async (userId: number, type: Type): Promise<Media[]> =>
+ flattenLists(
+ (
+ await (
+ await fetch('https://graphql.anilist.co', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Accept: 'application/json'
+ },
+ body: JSON.stringify({
+ query: collectionQueryTemplate(type, userId, false)
+ })
+ })
+ ).json()
+ )['data']['MediaListCollection']['lists']
+ );
const countMedian = (guesses: number[]) => {
guesses.sort((a: number, b: number) => a - b);
@@ -264,9 +251,7 @@ export const recentMediaActivities = async (
if (activity.progress !== null) {
const progress = Number((activity.progress.match(/\d+$/) || [0])[0]);
- if (progress !== 65535) {
- guesses.push(progress);
- }
+ if (progress !== 65535) guesses.push(progress);
}
});
guesses.sort((a, b) => b - a);
@@ -330,9 +315,8 @@ export const recentMediaActivities = async (
// }
// if (activities['data']['MediaList']['progress'] !== null) {
- if (activities['data']['MediaList']['progress'] > bestGuess) {
+ if (activities['data']['MediaList']['progress'] > bestGuess)
bestGuess = activities['data']['MediaList']['progress'];
- }
// }
return Math.round(bestGuess);