diff --git a/src/app/api/komga/cache/clear/[libraryId]/[seriesId]/route.ts b/src/app/api/komga/cache/clear/[libraryId]/[seriesId]/route.ts new file mode 100644 index 0000000..34e8d06 --- /dev/null +++ b/src/app/api/komga/cache/clear/[libraryId]/[seriesId]/route.ts @@ -0,0 +1,39 @@ +import { NextResponse } from "next/server"; +import { ERROR_CODES } from "@/constants/errorCodes"; +import { getErrorMessage } from "@/utils/errors"; +import { LibraryService } from "@/lib/services/library.service"; +import { HomeService } from "@/lib/services/home.service"; +import { SeriesService } from "@/lib/services/series.service"; + +export async function POST( + request: Request, + { params }: { params: { libraryId: string; seriesId: string } } +) { + try { + const { libraryId, seriesId } = params; + + await HomeService.invalidateHomeCache(); + + if (libraryId) { + await LibraryService.invalidateLibrarySeriesCache(libraryId); + } + if (seriesId) { + await SeriesService.invalidateSeriesBooksCache(seriesId); + await SeriesService.invalidateSeriesCache(seriesId); + } + + return NextResponse.json({ message: "🧹 Cache vidé avec succès" }); + } catch (error) { + console.error("Erreur lors de la suppression du cache:", error); + return NextResponse.json( + { + error: { + code: ERROR_CODES.CACHE.CLEAR_ERROR, + name: "Cache clear error", + message: getErrorMessage(ERROR_CODES.CACHE.CLEAR_ERROR), + }, + }, + { status: 500 } + ); + } +} diff --git a/src/components/layout/Header.tsx b/src/components/layout/Header.tsx index 53e55fd..cbdcc71 100644 --- a/src/components/layout/Header.tsx +++ b/src/components/layout/Header.tsx @@ -41,7 +41,7 @@ export function Header({ onToggleSidebar }: HeaderProps) { className="px-2 py-1.5 hover:bg-accent hover:text-accent-foreground rounded-md" aria-label="Toggle theme" > -