diff --git a/src/app/api/komga/libraries/[libraryId]/series/route.ts b/src/app/api/komga/libraries/[libraryId]/series/route.ts index 768c68a..eca340b 100644 --- a/src/app/api/komga/libraries/[libraryId]/series/route.ts +++ b/src/app/api/komga/libraries/[libraryId]/series/route.ts @@ -54,3 +54,40 @@ export async function GET( } } +export async function DELETE( + request: NextRequest, + { params }: { params: Promise<{ libraryId: string }> } +) { + try { + const libraryId: string = (await params).libraryId; + + await LibraryService.invalidateLibrarySeriesCache(libraryId); + + return NextResponse.json({ success: true }); + } catch (error) { + console.error("API Library Cache Invalidation - Erreur:", error); + if (error instanceof AppError) { + return NextResponse.json( + { + error: { + code: error.code, + name: "Cache invalidation error", + message: getErrorMessage(error.code), + }, + }, + { status: 500 } + ); + } + return NextResponse.json( + { + error: { + code: ERROR_CODES.CACHE.DELETE_ERROR, + name: "Cache invalidation error", + message: getErrorMessage(ERROR_CODES.CACHE.DELETE_ERROR), + }, + }, + { status: 500 } + ); + } +} + diff --git a/src/app/api/komga/series/[seriesId]/books/route.ts b/src/app/api/komga/series/[seriesId]/books/route.ts index 2ec6cb7..594e967 100644 --- a/src/app/api/komga/series/[seriesId]/books/route.ts +++ b/src/app/api/komga/series/[seriesId]/books/route.ts @@ -53,3 +53,43 @@ export async function GET( } } +export async function DELETE( + request: NextRequest, + { params }: { params: Promise<{ seriesId: string }> } +) { + try { + const seriesId: string = (await params).seriesId; + + await Promise.all([ + SeriesService.invalidateSeriesBooksCache(seriesId), + SeriesService.invalidateSeriesCache(seriesId) + ]); + + return NextResponse.json({ success: true }); + } catch (error) { + console.error("API Series Cache Invalidation - Erreur:", error); + if (error instanceof AppError) { + return NextResponse.json( + { + error: { + code: error.code, + name: "Cache invalidation error", + message: getErrorMessage(error.code), + }, + }, + { status: 500 } + ); + } + return NextResponse.json( + { + error: { + code: ERROR_CODES.CACHE.DELETE_ERROR, + name: "Cache invalidation error", + message: getErrorMessage(ERROR_CODES.CACHE.DELETE_ERROR), + }, + }, + { status: 500 } + ); + } +} + diff --git a/src/app/libraries/[libraryId]/ClientLibraryPage.tsx b/src/app/libraries/[libraryId]/ClientLibraryPage.tsx index 3496770..0a2c519 100644 --- a/src/app/libraries/[libraryId]/ClientLibraryPage.tsx +++ b/src/app/libraries/[libraryId]/ClientLibraryPage.tsx @@ -6,7 +6,6 @@ import { RefreshButton } from "@/components/library/RefreshButton"; import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { useTranslate } from "@/hooks/useTranslate"; import { OptimizedSkeleton } from "@/components/skeletons/OptimizedSkeletons"; -import { LibraryService } from "@/lib/services/library.service"; import type { LibraryResponse } from "@/types/library"; import type { KomgaSeries, KomgaLibrary } from "@/types/komga"; import type { UserPreferences } from "@/types/preferences"; @@ -77,7 +76,14 @@ export function ClientLibraryPage({ const handleRefresh = async (libraryId: string) => { try { - await LibraryService.invalidateLibrarySeriesCache(libraryId); + // Invalidate cache via API + const cacheResponse = await fetch(`/api/komga/libraries/${libraryId}/series`, { + method: 'DELETE', + }); + + if (!cacheResponse.ok) { + throw new Error("Error invalidating cache"); + } // Recharger les données const params = new URLSearchParams({ diff --git a/src/app/series/[seriesId]/ClientSeriesPage.tsx b/src/app/series/[seriesId]/ClientSeriesPage.tsx index f512979..9b8cdd4 100644 --- a/src/app/series/[seriesId]/ClientSeriesPage.tsx +++ b/src/app/series/[seriesId]/ClientSeriesPage.tsx @@ -3,7 +3,6 @@ import { useEffect, useState } from "react"; import { PaginatedBookGrid } from "@/components/series/PaginatedBookGrid"; import { SeriesHeader } from "@/components/series/SeriesHeader"; -import { SeriesService } from "@/lib/services/series.service"; import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { OptimizedSkeleton } from "@/components/skeletons/OptimizedSkeletons"; import type { LibraryResponse } from "@/types/library"; @@ -70,8 +69,14 @@ export function ClientSeriesPage({ const handleRefresh = async (seriesId: string) => { try { - await SeriesService.invalidateSeriesBooksCache(seriesId); - await SeriesService.invalidateSeriesCache(seriesId); + // Invalidate cache via API + const cacheResponse = await fetch(`/api/komga/series/${seriesId}/books`, { + method: 'DELETE', + }); + + if (!cacheResponse.ok) { + throw new Error("Erreur lors de l'invalidation du cache"); + } // Recharger les données const params = new URLSearchParams({