Array of AniList manga media IDs.
Optionaltoken: stringOptional access token for authenticated requests.
OptionalabortSignal: AbortSignalOptional AbortSignal to cancel the request.
OptionalnoRetry: booleanDisable automatic retry logic (default: false).
Promise resolving to array of AniListManga objects.
export async function getMangaByIds(
ids: number[],
token?: string,
abortSignal?: AbortSignal,
noRetry?: boolean,
): Promise<AniListManga[]> {
return withGroupAsync(
`[AniListClient] Get Manga (${ids.length} IDs)`,
async () => {
if (!ids.length) {
return [];
}
try {
// Updated type parameter to handle potential nested data structure
const response = await request<{
data?: { Page: { media: AniListManga[] } };
Page?: { media: AniListManga[] };
}>(GET_MANGA_BY_IDS, { ids }, token, abortSignal, undefined, noRetry);
// Validate response structure
if (!response?.data) {
console.error(
`[AniListClient] ❌ Invalid API response when fetching manga by IDs:`,
response,
);
return [];
}
// Check for nested data structure
const responseData = response.data.data ?? response.data;
// Safely access media array or return empty array if not found
return responseData.Page?.media || [];
} catch (error) {
console.error(
`[AniListClient] ❌ Error fetching manga by IDs [${ids.join(", ")}]:`,
error,
);
throw error;
}
},
);
}
Get multiple manga by their AniList media IDs. Returns results in original order matching input array.