aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-04-18 09:01:52 +0000
committerFuwn <[email protected]>2026-04-18 09:01:52 +0000
commitf5fef7b623639399e81b284f56f9e85454cc76c2 (patch)
tree2ddcfff1256d1a2ff9711349fa1296e275892bf8
parentfix(user): pass actual description to badge preview alt text (diff)
downloaddue.moe-f5fef7b623639399e81b284f56f9e85454cc76c2.tar.xz
due.moe-f5fef7b623639399e81b284f56f9e85454cc76c2.zip
fix(media): guard publicMediaListCollection against missing AniList data
The public variant of mediaListCollection chained data.MediaListCollection .lists with no null check, so any AniList error response (rate limit, private list, nonexistent user) threw a TypeError. Mirror the guard used by the authenticated sibling: if any of data, MediaListCollection, or lists is missing, return an empty array. The function currently has no in-tree callers; noting that it may be a candidate for removal in a follow-up.
-rw-r--r--src/lib/Data/AniList/media.ts35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/lib/Data/AniList/media.ts b/src/lib/Data/AniList/media.ts
index 099d4182..b9e0ef3f 100644
--- a/src/lib/Data/AniList/media.ts
+++ b/src/lib/Data/AniList/media.ts
@@ -429,23 +429,24 @@ export const mediaListCollection = async (
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, {}),
- }),
- })
- ).json()
- )["data"]["MediaListCollection"]["lists"],
- );
+): Promise<Media[]> => {
+ const response = await (
+ await fetch("https://graphql.anilist.co", {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ Accept: "application/json",
+ },
+ body: JSON.stringify({
+ query: collectionQueryTemplate(type, userId, {}),
+ }),
+ })
+ ).json();
+
+ if (!response?.data?.MediaListCollection?.lists) return [];
+
+ return flattenLists(response.data.MediaListCollection.lists);
+};
const countMedian = (guesses: number[]) => {
guesses.sort((a: number, b: number) => a - b);