feat: Reader working, some work still need to be done
This commit is contained in:
parent
33f5a5568a
commit
668702b1fb
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { Manga, MangaCollection } from '../../domain/manga';
|
||||
import { Manga, MangaCollection, MangaDetail } from '../../domain/manga';
|
||||
import { Chapter } from '../../domain/chapter';
|
||||
|
||||
export class ApiMangaRepository {
|
||||
constructor() {
|
||||
@@ -38,4 +39,62 @@ export class ApiMangaRepository {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async searchMangas(query) {
|
||||
try {
|
||||
const response = await this.api.get(`/mangas-search?title=${encodeURIComponent(query)}`);
|
||||
const data = response.data;
|
||||
|
||||
return data.items.map(item => new Manga(
|
||||
item.externalId,
|
||||
item.title,
|
||||
item.slug,
|
||||
item.imageUrl,
|
||||
item.author,
|
||||
item.publicationYear,
|
||||
item.genres,
|
||||
item.status,
|
||||
item.rating,
|
||||
item.description
|
||||
));
|
||||
} catch (error) {
|
||||
console.error('Error searching mangas:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getMangaBySlug(slug) {
|
||||
try {
|
||||
const mangaResponse = await this.api.get(`/mangas/by-slug/${slug}`);
|
||||
const mangaData = mangaResponse.data;
|
||||
|
||||
const chaptersResponse = await this.api.get(`/mangas/${mangaData.id}/chapters?page=1&limit=1000&sortOrder=desc`);
|
||||
const chaptersData = chaptersResponse.data;
|
||||
|
||||
const chapters = chaptersData.items.map(item => new Chapter(
|
||||
item.id,
|
||||
parseFloat(item.number),
|
||||
item.title,
|
||||
item.volume,
|
||||
item.isVisible,
|
||||
item.createdAt
|
||||
));
|
||||
|
||||
return new MangaDetail({
|
||||
id: mangaData.id,
|
||||
title: mangaData.title,
|
||||
slug: mangaData.slug,
|
||||
imageUrl: mangaData.imageUrl,
|
||||
author: mangaData.author,
|
||||
publicationYear: mangaData.publicationYear,
|
||||
genres: mangaData.genres,
|
||||
status: mangaData.status,
|
||||
rating: mangaData.rating,
|
||||
description: mangaData.description
|
||||
}, chapters);
|
||||
} catch (error) {
|
||||
console.error('Error fetching manga details:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
74
assets/react/app/infrastructure/api/apiReaderRepository.js
Normal file
74
assets/react/app/infrastructure/api/apiReaderRepository.js
Normal file
@@ -0,0 +1,74 @@
|
||||
import axios from 'axios';
|
||||
import { ReaderContext, Page } from '../../domain/reader';
|
||||
import { ReaderRepository } from '../../domain/ports/readerRepository';
|
||||
|
||||
export class ApiReaderRepository extends ReaderRepository {
|
||||
constructor() {
|
||||
super();
|
||||
this.api = axios.create({
|
||||
baseURL: '/api'
|
||||
});
|
||||
}
|
||||
|
||||
async getChapterContext(chapterId) {
|
||||
try {
|
||||
const response = await this.api.get(`/reader/chapter/${chapterId}`);
|
||||
const data = response.data;
|
||||
|
||||
return new ReaderContext(
|
||||
data.id,
|
||||
data.title,
|
||||
data.number,
|
||||
data.manga,
|
||||
data.navigation
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error fetching chapter context:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getPage(chapterId, pageNumber) {
|
||||
try {
|
||||
const response = await this.api.get(`/reader/chapter/${chapterId}/page/${pageNumber}`);
|
||||
const data = response.data;
|
||||
|
||||
return new Page(
|
||||
data.id,
|
||||
data.pageNumber,
|
||||
data.base64Content,
|
||||
data.mimeType,
|
||||
data.dimensions
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Error fetching page:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getPages(chapterId) {
|
||||
try {
|
||||
const response = await this.api.get(`/reader/chapter/${chapterId}/pages`);
|
||||
const data = response.data;
|
||||
|
||||
// Charger chaque page individuellement pour obtenir le contenu base64
|
||||
const pagesPromises = data.pages.map(async (page) => {
|
||||
const pageResponse = await this.getPage(chapterId, page.pageNumber);
|
||||
return pageResponse;
|
||||
});
|
||||
|
||||
const loadedPages = await Promise.all(pagesPromises);
|
||||
|
||||
return {
|
||||
pages: loadedPages,
|
||||
totalItems: data.totalItems,
|
||||
currentPage: data.currentPage,
|
||||
itemsPerPage: data.itemsPerPage,
|
||||
totalPages: data.totalPages
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error fetching pages:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
61
assets/react/app/infrastructure/api/mockReaderRepository.js
Normal file
61
assets/react/app/infrastructure/api/mockReaderRepository.js
Normal file
@@ -0,0 +1,61 @@
|
||||
export class MockReaderRepository {
|
||||
async getChapterContext(chapterId) {
|
||||
// Simuler un délai réseau
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
return {
|
||||
id: chapterId,
|
||||
title: "Un assassin invité",
|
||||
number: "378",
|
||||
manga: {
|
||||
id: "1",
|
||||
title: "One Piece"
|
||||
},
|
||||
navigation: {
|
||||
previous: {
|
||||
id: "prev-chapter",
|
||||
number: "377"
|
||||
},
|
||||
next: {
|
||||
id: "next-chapter",
|
||||
number: "379"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async getPage(chapterId, pageNumber) {
|
||||
// Simuler un délai réseau
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
return {
|
||||
id: `page-${pageNumber}`,
|
||||
pageNumber: pageNumber,
|
||||
base64Content: "data:image/jpeg;base64,/9j/4AAQSkZJRg...", // Simulé
|
||||
mimeType: "image/jpeg",
|
||||
dimensions: {
|
||||
width: 800,
|
||||
height: 1200
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async getPages(chapterId) {
|
||||
// Simuler un délai réseau
|
||||
await new Promise(resolve => setTimeout(resolve, 500));
|
||||
|
||||
return {
|
||||
pages: Array.from({ length: 20 }, (_, i) => ({
|
||||
number: i + 1,
|
||||
dimensions: {
|
||||
width: 800,
|
||||
height: 1200
|
||||
}
|
||||
})),
|
||||
totalItems: 20,
|
||||
currentPage: 1,
|
||||
itemsPerPage: 20,
|
||||
totalPages: 1
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user