Array of AniList manga IDs.
Optional
token: stringOptional access token.
Optional
abortSignal: AbortSignalOptional abort signal to cancel the request.
Promise resolving to an array of AniListManga objects.
export async function getMangaByIds(
ids: number[],
token?: string,
abortSignal?: AbortSignal,
): Promise<AniListManga[]> {
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);
// Validate response structure
if (!response || !response.data) {
console.error(
`Invalid API response when fetching manga by IDs:`,
response,
);
return [];
}
// Check for nested data structure
const responseData = response.data.data
? response.data.data
: response.data;
// Safely access media array or return empty array if not found
return responseData.Page?.media || [];
} catch (error) {
console.error(`Error fetching manga by IDs [${ids.join(", ")}]:`, error);
throw error;
}
}
Get multiple manga by their IDs.