fix: correction des URLs des images et nettoyage du code

This commit is contained in:
Julien Froidefond
2025-02-12 10:13:16 +01:00
parent c9cd081921
commit 6cec8da8e2
3 changed files with 21 additions and 9 deletions

View File

@@ -12,6 +12,7 @@ interface SeriesHeaderProps {
export function SeriesHeader({ series, serverUrl }: SeriesHeaderProps) {
const [languageDisplay, setLanguageDisplay] = useState<string>(series.metadata.language);
const [imageError, setImageError] = useState(false);
useEffect(() => {
try {
@@ -27,17 +28,28 @@ export function SeriesHeader({ series, serverUrl }: SeriesHeaderProps) {
}
}, [series.metadata.language]);
const getSeriesThumbnailUrl = (seriesId: string) => {
return `/api/komga/images/series/${seriesId}/thumbnail`;
};
return (
<div className="flex flex-col md:flex-row gap-8">
{/* Couverture */}
<div className="w-48 shrink-0">
<div className="relative aspect-[2/3] rounded-lg overflow-hidden bg-muted">
<Image
src={`/api/komga/images/series/${series.id}/thumbnail`}
alt={`Couverture de ${series.metadata.title}`}
fill
className="object-cover"
/>
{!imageError ? (
<Image
src={getSeriesThumbnailUrl(series.id)}
alt={`Couverture de ${series.metadata.title}`}
fill
className="object-cover"
onError={() => setImageError(true)}
/>
) : (
<div className="w-full h-full flex items-center justify-center">
<ImageOff className="w-12 h-12" />
</div>
)}
</div>
</div>

View File

@@ -9,7 +9,7 @@ export class ImageService extends BaseApiService {
static async getImage(path: string): Promise<ImageResponse> {
try {
const config = await this.getKomgaConfig();
const url = this.buildUrl(config, path);
const url = `${config.serverUrl}${path}`;
const headers = this.getAuthHeaders(config);
// Ajout des headers pour accepter les images

View File

@@ -13,7 +13,7 @@ export class SeriesService extends BaseApiService {
return this.fetchWithCache<Series>(
`series-${seriesId}`,
async () => this.fetchFromApi<Series>(url, headers),
5 * 60 // Cache de 5 minutes
"SERIES"
);
} catch (error) {
return this.handleError(error, "Impossible de récupérer la série");
@@ -39,7 +39,7 @@ export class SeriesService extends BaseApiService {
return this.fetchWithCache<LibraryResponse<KomgaBook>>(
`series-${seriesId}-books-${page}-${size}-${unreadOnly}`,
async () => this.fetchFromApi<LibraryResponse<KomgaBook>>(url, headers),
5 * 60 // Cache de 5 minutes
"BOOKS"
);
} catch (error) {
return this.handleError(error, "Impossible de récupérer les tomes");