feat: route config pour les front

This commit is contained in:
ext.jeremy.guillot@maxicoffee.domains
2025-03-24 18:21:07 +01:00
parent 41dc3c51aa
commit ed0a075a6c
6 changed files with 29 additions and 26 deletions

View File

@@ -1,17 +0,0 @@
export class MangaApi {
static async fetchById(mangaId) {
const response = await fetch(`/api/mangas/${mangaId}`);
if (!response.ok) {
throw new Error('Failed to fetch manga details');
}
return response.json();
}
static async fetchChapters(mangaId) {
const response = await fetch(`/api/mangas/${mangaId}/chapters`);
if (!response.ok) {
throw new Error('Failed to fetch manga chapters');
}
return response.json();
}
}

View File

@@ -37,11 +37,25 @@ export class ApiMangaRepository {
async getChapters(mangaId) {
try {
const response = await fetch(`/api/mangas/${mangaId}/chapters`);
if (!response.ok) {
throw new Error('Failed to fetch manga chapters');
let allChapters = [];
let page = 1;
let hasMore = true;
while (hasMore) {
const response = await fetch(`/api/mangas/${mangaId}/chapters?limit=500&page=${page}`);
if (!response.ok) {
throw new Error('Failed to fetch manga chapters');
}
const data = await response.json();
allChapters = allChapters.concat(data.items);
hasMore = data.hasNextPage;
page++;
}
return await response.json();
return {
items: allChapters,
total: allChapters.length
};
} catch (error) {
console.error('API Error:', error);
throw error;