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

View File

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

View File

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