feat: route config pour les front
This commit is contained in:
parent
41dc3c51aa
commit
ed0a075a6c
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user