feat: Clearing cache automatically after quitting e read session
This commit is contained in:
39
src/app/api/komga/cache/clear/[libraryId]/[seriesId]/route.ts
vendored
Normal file
39
src/app/api/komga/cache/clear/[libraryId]/[seriesId]/route.ts
vendored
Normal file
@@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
>
|
||||
<div className="relative flex items-center justify-center w-5 h-5">
|
||||
<div className="relative flex items-center w-5 h-5">
|
||||
<Sun className="absolute inset-0 h-[1.2rem] w-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
|
||||
<Moon className="absolute inset-0 h-[1.2rem] w-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
|
||||
</div>
|
||||
|
||||
@@ -21,6 +21,7 @@ export function ClientBookReader({ book, pages }: ClientBookReaderProps) {
|
||||
|
||||
const handleCloseReader = () => {
|
||||
setIsReading(false);
|
||||
//Fetch une nouvelle route pour rafraichir les différents caches
|
||||
router.back();
|
||||
};
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ export function ClientBookWrapper({ book, pages }: ClientBookWrapperProps) {
|
||||
const router = useRouter();
|
||||
|
||||
const handleCloseReader = () => {
|
||||
fetch(`/api/komga/cache/clear/${book.libraryId}/${book.seriesId}`, {
|
||||
method: "POST",
|
||||
});
|
||||
router.back();
|
||||
};
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ export interface KomgaBook {
|
||||
id: string;
|
||||
seriesId: string;
|
||||
seriesTitle: string;
|
||||
libraryId: string;
|
||||
name: string;
|
||||
url: string;
|
||||
number: number;
|
||||
|
||||
Reference in New Issue
Block a user