diff --git a/src/app/api/komga/home/route.ts b/src/app/api/komga/home/route.ts index 718714e..885af02 100644 --- a/src/app/api/komga/home/route.ts +++ b/src/app/api/komga/home/route.ts @@ -36,3 +36,34 @@ export async function GET() { } } +export async function DELETE() { + try { + await HomeService.invalidateHomeCache(); + return NextResponse.json({ success: true }); + } catch (error) { + console.error("API Home - Erreur lors de l'invalidation du cache:", 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]/page.tsx b/src/app/libraries/[libraryId]/page.tsx index b31a626..2159072 100644 --- a/src/app/libraries/[libraryId]/page.tsx +++ b/src/app/libraries/[libraryId]/page.tsx @@ -3,8 +3,8 @@ import { ClientLibraryPage } from "./ClientLibraryPage"; import type { UserPreferences } from "@/types/preferences"; interface PageProps { - params: { libraryId: string }; - searchParams: { page?: string; unread?: string; search?: string; size?: string }; + params: Promise<{ libraryId: string }>; + searchParams: Promise<{ page?: string; unread?: string; search?: string; size?: string }>; } export default async function LibraryPage({ params, searchParams }: PageProps) { diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index bea9868..5bea05f 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -3,10 +3,10 @@ import { LoginContent } from "./LoginContent"; import { withPageTiming } from "@/lib/hoc/withPageTiming"; interface PageProps { - searchParams: { + searchParams: Promise<{ from?: string; tab?: string; - }; + }>; } export const metadata: Metadata = { title: "Connexion", diff --git a/src/app/series/[seriesId]/page.tsx b/src/app/series/[seriesId]/page.tsx index 5c66245..28a819c 100644 --- a/src/app/series/[seriesId]/page.tsx +++ b/src/app/series/[seriesId]/page.tsx @@ -3,8 +3,8 @@ import { ClientSeriesPage } from "./ClientSeriesPage"; import type { UserPreferences } from "@/types/preferences"; interface PageProps { - params: { seriesId: string }; - searchParams: { page?: string; unread?: string; size?: string }; + params: Promise<{ seriesId: string }>; + searchParams: Promise<{ page?: string; unread?: string; size?: string }>; } export default async function SeriesPage({ params, searchParams }: PageProps) { diff --git a/src/components/debug/DebugInfo.tsx b/src/components/debug/DebugInfo.tsx index caadf68..147aac5 100644 --- a/src/components/debug/DebugInfo.tsx +++ b/src/components/debug/DebugInfo.tsx @@ -14,27 +14,10 @@ import { Filter, Calendar, } from "lucide-react"; -import type { CacheType } from "@/lib/services/base-api.service"; +import type { RequestTiming } from "@/types/debug"; import { useTranslation } from "react-i18next"; import { useDebug } from "@/contexts/DebugContext"; -interface RequestTiming { - url: string; - startTime: number; - endTime: number; - duration: number; - timestamp: string; - fromCache: boolean; - cacheType?: CacheType; - mongoAccess?: { - operation: string; - duration: number; - }; - pageRender?: { - page: string; - }; -} - function formatTime(timestamp: string) { const date = new Date(timestamp); return date.toLocaleTimeString("fr-FR", { diff --git a/src/components/home/ClientHomePage.tsx b/src/components/home/ClientHomePage.tsx index c018c20..fc261e7 100644 --- a/src/components/home/ClientHomePage.tsx +++ b/src/components/home/ClientHomePage.tsx @@ -3,11 +3,10 @@ import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { HomeContent } from "./HomeContent"; -import { HomeService } from "@/lib/services/home.service"; import { ErrorMessage } from "@/components/ui/ErrorMessage"; import { HomePageSkeleton } from "@/components/skeletons/OptimizedSkeletons"; import { ERROR_CODES } from "@/constants/errorCodes"; -import type { HomeData } from "@/lib/services/home.service"; +import type { HomeData } from "@/types/home"; export function ClientHomePage() { const router = useRouter(); @@ -51,8 +50,16 @@ export function ClientHomePage() { const handleRefresh = async () => { try { - await HomeService.invalidateHomeCache(); + // Invalider le cache via l'API + const deleteResponse = await fetch("/api/komga/home", { + method: "DELETE", + }); + if (!deleteResponse.ok) { + throw new Error("Erreur lors de l'invalidation du cache"); + } + + // Récupérer les nouvelles données const response = await fetch("/api/komga/home"); if (!response.ok) { diff --git a/src/components/home/HomeContent.tsx b/src/components/home/HomeContent.tsx index f1b4911..45b1874 100644 --- a/src/components/home/HomeContent.tsx +++ b/src/components/home/HomeContent.tsx @@ -3,9 +3,9 @@ import { HeroSection } from "./HeroSection"; import { MediaRow } from "./MediaRow"; import type { KomgaBook, KomgaSeries } from "@/types/komga"; +import type { HomeData } from "@/types/home"; import { RefreshButton } from "@/components/library/RefreshButton"; import { History, Sparkles, Clock, LibraryBig, BookOpen } from "lucide-react"; -import type { HomeData } from "@/lib/services/home.service"; import { useTranslate } from "@/hooks/useTranslate"; import { useEffect, useState } from "react"; diff --git a/src/contexts/DebugContext.tsx b/src/contexts/DebugContext.tsx index 93617f8..003095d 100644 --- a/src/contexts/DebugContext.tsx +++ b/src/contexts/DebugContext.tsx @@ -1,7 +1,7 @@ "use client"; import { createContext, useContext, useState, useEffect, ReactNode } from "react"; -import type { RequestTiming } from "@/lib/services/debug.service"; +import type { RequestTiming } from "@/types/debug"; import { usePreferences } from "./PreferencesContext"; interface DebugContextType { diff --git a/src/lib/services/base-api.service.ts b/src/lib/services/base-api.service.ts index 4e2cc76..91eb7b3 100644 --- a/src/lib/services/base-api.service.ts +++ b/src/lib/services/base-api.service.ts @@ -1,4 +1,5 @@ import type { AuthConfig } from "@/types/auth"; +import type { CacheType } from "@/types/cache"; import { getServerCacheService } from "./server-cache.service"; import { ConfigDBService } from "./config-db.service"; import { ERROR_CODES } from "../../constants/errorCodes"; @@ -8,8 +9,8 @@ import type { ServerCacheService } from "./server-cache.service"; import { DebugService } from "./debug.service"; import { RequestMonitorService } from "./request-monitor.service"; import { RequestQueueService } from "./request-queue.service"; -// Types de cache disponibles -export type CacheType = "DEFAULT" | "HOME" | "LIBRARIES" | "SERIES" | "BOOKS" | "IMAGES"; + +export type { CacheType }; interface KomgaRequestInit extends RequestInit { isImage?: boolean; @@ -87,23 +88,9 @@ export abstract class BaseApiService { } protected static async resolveWithFallback(url: string): Promise { - try { - // Essayer de résoudre le DNS d'abord - const urlObj = new URL(url); - const hostname = urlObj.hostname; - - // Si c'est un nom de domaine, essayer de le résoudre - if (!/^\d+\.\d+\.\d+\.\d+$/.test(hostname)) { - // Vérifier si le domaine peut être résolu - const { lookup } = await import('dns').then(dns => dns.promises); - await lookup(hostname); - } - - return url; - } catch (dnsError) { - console.warn(`DNS resolution failed for ${url}, using original URL:`, dnsError); - return url; - } + // DNS resolution is only needed server-side and causes build issues + // The fetch API will handle DNS resolution automatically + return url; } protected static async fetchFromApi( diff --git a/src/lib/services/debug.service.ts b/src/lib/services/debug.service.ts index 9c89765..f2e9888 100644 --- a/src/lib/services/debug.service.ts +++ b/src/lib/services/debug.service.ts @@ -1,28 +1,12 @@ import fs from "fs/promises"; import path from "path"; -import type { CacheType } from "./base-api.service"; +import type { RequestTiming } from "@/types/debug"; import { PreferencesService } from "./preferences.service"; import { getCurrentUser } from "../auth-utils"; import { ERROR_CODES } from "../../constants/errorCodes"; import { AppError } from "../../utils/errors"; -export interface RequestTiming { - url: string; - startTime: number; - endTime: number; - duration: number; - timestamp: string; - fromCache: boolean; - cacheType?: CacheType; - mongoAccess?: { - operation: string; - duration: number; - }; - pageRender?: { - page: string; - duration: number; - }; -} +export type { RequestTiming }; export class DebugService { private static writeQueues = new Map>(); diff --git a/src/lib/services/home.service.ts b/src/lib/services/home.service.ts index 9b0197a..9d4ffd0 100644 --- a/src/lib/services/home.service.ts +++ b/src/lib/services/home.service.ts @@ -1,17 +1,12 @@ import { BaseApiService } from "./base-api.service"; import type { KomgaBook, KomgaSeries } from "@/types/komga"; import type { LibraryResponse } from "@/types/library"; +import type { HomeData } from "@/types/home"; import { getServerCacheService } from "./server-cache.service"; import { ERROR_CODES } from "../../constants/errorCodes"; import { AppError } from "../../utils/errors"; -export interface HomeData { - ongoing: KomgaSeries[]; - ongoingBooks: KomgaBook[]; - recentlyRead: KomgaBook[]; - onDeck: KomgaBook[]; - latestSeries: KomgaSeries[]; -} +export type { HomeData }; export class HomeService extends BaseApiService { static async getHomeData(): Promise { diff --git a/src/types/cache.ts b/src/types/cache.ts index 6ecb2ab..7b5735d 100644 --- a/src/types/cache.ts +++ b/src/types/cache.ts @@ -1,8 +1 @@ -export interface TTLConfig { - defaultTTL: number; - homeTTL: number; - librariesTTL: number; - seriesTTL: number; - booksTTL: number; - imagesTTL: number; -} +export type CacheType = "DEFAULT" | "HOME" | "LIBRARIES" | "SERIES" | "BOOKS" | "IMAGES"; diff --git a/src/types/debug.ts b/src/types/debug.ts new file mode 100644 index 0000000..538e2ce --- /dev/null +++ b/src/types/debug.ts @@ -0,0 +1,20 @@ +import type { CacheType } from "./cache"; + +export interface RequestTiming { + url: string; + startTime: number; + endTime: number; + duration: number; + timestamp: string; + fromCache: boolean; + cacheType?: CacheType; + mongoAccess?: { + operation: string; + duration: number; + }; + pageRender?: { + page: string; + duration: number; + }; +} + diff --git a/src/types/home.ts b/src/types/home.ts new file mode 100644 index 0000000..bf4b70a --- /dev/null +++ b/src/types/home.ts @@ -0,0 +1,10 @@ +import type { KomgaBook, KomgaSeries } from "./komga"; + +export interface HomeData { + ongoing: KomgaSeries[]; + ongoingBooks: KomgaBook[]; + recentlyRead: KomgaBook[]; + onDeck: KomgaBook[]; + latestSeries: KomgaSeries[]; +} +