import { fetch } from "https://esm.town/v/std/fetch";
import { API_BASE_URL } from "https://esm.town/v/mangadex/API_BASE_URL";
type LoginSuccess = {
result: "ok";
token: {
session: string;
refresh: string;
};
};
type LoginFailure = {
result: "error";
errors: Array<{
id: string;
status: number;
title: string;
detail: string;
}>;
};
type LoginResponse = LoginSuccess | LoginFailure;
export const listFeed = async (listId: string, login: LoginResponse) => {
if (login.result === "error") {
return "The provided login credentials are incorrect.";
}
const response = await fetch(
`${API_BASE_URL}/list/${listId}/feed`,
{
headers: {
Authorization: `Bearer ${login.token.session}`,
},
},
);
return await response.json();
};