refacto: types big review
This commit is contained in:
@@ -3,13 +3,14 @@ import { AuthServerService } from "@/lib/services/auth-server.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { UserData } from "@/lib/services/auth-server.service";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { email, password } = await request.json();
|
||||
|
||||
try {
|
||||
const userData = await AuthServerService.loginUser(email, password);
|
||||
const userData: UserData = await AuthServerService.loginUser(email, password);
|
||||
AuthServerService.setUserCookie(userData);
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { AuthServerService } from "@/lib/services/auth-server.service";
|
||||
import { AuthServerService, UserData } from "@/lib/services/auth-server.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
@@ -9,7 +9,7 @@ export async function POST(request: Request) {
|
||||
const { email, password } = await request.json();
|
||||
|
||||
try {
|
||||
const userData = await AuthServerService.createUser(email, password);
|
||||
const userData: UserData = await AuthServerService.createUser(email, password);
|
||||
AuthServerService.setUserCookie(userData);
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { DebugService } from "@/lib/services/debug.service";
|
||||
import { DebugService, RequestTiming } from "@/lib/services/debug.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const logs = await DebugService.getRequestLogs();
|
||||
const logs: RequestTiming[] = await DebugService.getRequestLogs();
|
||||
return NextResponse.json(logs);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération des logs:", error);
|
||||
@@ -35,7 +35,7 @@ export async function GET() {
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const timing = await request.json();
|
||||
const timing: RequestTiming = await request.json();
|
||||
await DebugService.logRequest(timing);
|
||||
return NextResponse.json({
|
||||
message: "✅ Log enregistré avec succès",
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(
|
||||
{ params }: { params: { bookId: string; pageNumber: string } }
|
||||
) {
|
||||
try {
|
||||
const pageNumber = parseInt(params.pageNumber);
|
||||
const pageNumber: number = parseInt(params.pageNumber);
|
||||
if (isNaN(pageNumber) || pageNumber < 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -3,10 +3,10 @@ import { BookService } from "@/lib/services/book.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
import { KomgaBookWithPages } from "@/types/komga";
|
||||
export async function GET(request: Request, { params }: { params: { bookId: string } }) {
|
||||
try {
|
||||
const data = await BookService.getBook(params.bookId);
|
||||
const data: KomgaBookWithPages = await BookService.getBook(params.bookId);
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.error("API Books - Erreur:", error);
|
||||
|
||||
4
src/app/api/komga/cache/clear/route.ts
vendored
4
src/app/api/komga/cache/clear/route.ts
vendored
@@ -1,11 +1,11 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import { getServerCacheService, ServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function POST() {
|
||||
try {
|
||||
const cacheService = await getServerCacheService();
|
||||
const cacheService: ServerCacheService = await getServerCacheService();
|
||||
cacheService.clear();
|
||||
return NextResponse.json({ message: "🧹 Cache vidé avec succès" });
|
||||
} catch (error) {
|
||||
|
||||
12
src/app/api/komga/cache/mode/route.ts
vendored
12
src/app/api/komga/cache/mode/route.ts
vendored
@@ -1,11 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import {
|
||||
CacheMode,
|
||||
getServerCacheService,
|
||||
ServerCacheService,
|
||||
} from "@/lib/services/server-cache.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const cacheService = await getServerCacheService();
|
||||
const cacheService: ServerCacheService = await getServerCacheService();
|
||||
return NextResponse.json({ mode: cacheService.getCacheMode() });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération du mode de cache:", error);
|
||||
@@ -23,7 +27,7 @@ export async function GET() {
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { mode } = await request.json();
|
||||
const { mode }: { mode: CacheMode } = await request.json();
|
||||
if (mode !== "file" && mode !== "memory") {
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -36,7 +40,7 @@ export async function POST(request: Request) {
|
||||
);
|
||||
}
|
||||
|
||||
const cacheService = await getServerCacheService();
|
||||
const cacheService: ServerCacheService = await getServerCacheService();
|
||||
cacheService.setCacheMode(mode);
|
||||
return NextResponse.json({ mode: cacheService.getCacheMode() });
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,22 +2,17 @@ import { NextResponse } from "next/server";
|
||||
import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { KomgaConfig, KomgaConfigData } from "@/types/komga";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const data = await request.json();
|
||||
const mongoConfig = await ConfigDBService.saveConfig(data);
|
||||
// Convertir le document Mongoose en objet simple
|
||||
const config = {
|
||||
url: mongoConfig.url,
|
||||
username: mongoConfig.username,
|
||||
password: mongoConfig.password,
|
||||
userId: mongoConfig.userId,
|
||||
};
|
||||
const data: KomgaConfigData = await request.json();
|
||||
const mongoConfig: KomgaConfig = await ConfigDBService.saveConfig(data);
|
||||
|
||||
return NextResponse.json(
|
||||
{ message: "⚙️ Configuration sauvegardée avec succès", config },
|
||||
{ message: "⚙️ Configuration sauvegardée avec succès", mongoConfig },
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
@@ -47,15 +42,9 @@ export async function POST(request: Request) {
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const mongoConfig = await ConfigDBService.getConfig();
|
||||
// Convertir le document Mongoose en objet simple
|
||||
const config = {
|
||||
url: mongoConfig.url,
|
||||
username: mongoConfig.username,
|
||||
password: mongoConfig.password,
|
||||
userId: mongoConfig.userId,
|
||||
};
|
||||
return NextResponse.json(config, { status: 200 });
|
||||
const mongoConfig: KomgaConfig | null = await ConfigDBService.getConfig();
|
||||
|
||||
return NextResponse.json(mongoConfig, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la configuration:", error);
|
||||
if (error instanceof Error) {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const favoriteIds = await FavoriteService.getAllFavoriteIds();
|
||||
const favoriteIds: string[] = await FavoriteService.getAllFavoriteIds();
|
||||
return NextResponse.json(favoriteIds);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération des favoris:", error);
|
||||
@@ -35,7 +35,7 @@ export async function GET() {
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { seriesId } = await request.json();
|
||||
const { seriesId }: { seriesId: string } = await request.json();
|
||||
await FavoriteService.addToFavorites(seriesId);
|
||||
return NextResponse.json({ message: "⭐️ Série ajoutée aux favoris" });
|
||||
} catch (error) {
|
||||
@@ -65,7 +65,7 @@ export async function POST(request: Request) {
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
try {
|
||||
const { seriesId } = await request.json();
|
||||
const { seriesId }: { seriesId: string } = await request.json();
|
||||
await FavoriteService.removeFromFavorites(seriesId);
|
||||
return NextResponse.json({ message: "💔 Série retirée des favoris" });
|
||||
} catch (error) {
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function GET(
|
||||
) {
|
||||
try {
|
||||
// Convertir le numéro de page en nombre
|
||||
const pageNumber = parseInt(params.pageNumber);
|
||||
const pageNumber: number = parseInt(params.pageNumber);
|
||||
if (isNaN(pageNumber) || pageNumber < 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
|
||||
@@ -3,12 +3,12 @@ import { LibraryService } from "@/lib/services/library.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
import { KomgaLibrary } from "@/types/komga";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const libraries = await LibraryService.getLibraries();
|
||||
const libraries: KomgaLibrary[] = await LibraryService.getLibraries();
|
||||
return NextResponse.json(libraries);
|
||||
} catch (error) {
|
||||
console.error("API Libraries - Erreur:", error);
|
||||
|
||||
@@ -3,12 +3,13 @@ import { SeriesService } from "@/lib/services/series.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { KomgaSeries } from "@/types/komga";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(request: Request, { params }: { params: { seriesId: string } }) {
|
||||
try {
|
||||
const series = await SeriesService.getSeries(params.seriesId);
|
||||
const series: KomgaSeries = await SeriesService.getSeries(params.seriesId);
|
||||
return NextResponse.json(series);
|
||||
} catch (error) {
|
||||
console.error("API Series - Erreur:", error);
|
||||
|
||||
@@ -2,13 +2,14 @@ import { NextResponse } from "next/server";
|
||||
import { TestService } from "@/lib/services/test.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { KomgaLibrary } from "@/types/komga";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { serverUrl, username, password } = await request.json();
|
||||
const authHeader = Buffer.from(`${username}:${password}`).toString("base64");
|
||||
|
||||
const { libraries } = await TestService.testConnection({
|
||||
const { libraries }: { libraries: KomgaLibrary[] } = await TestService.testConnection({
|
||||
serverUrl,
|
||||
authHeader,
|
||||
});
|
||||
|
||||
@@ -2,10 +2,11 @@ import { NextResponse } from "next/server";
|
||||
import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { TTLConfig } from "@/types/komga";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const config = await ConfigDBService.getTTLConfig();
|
||||
const config: TTLConfig | null = await ConfigDBService.getTTLConfig();
|
||||
return NextResponse.json(config);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la configuration TTL:", error);
|
||||
@@ -37,7 +38,8 @@ export async function GET() {
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const data = await request.json();
|
||||
const config = await ConfigDBService.saveTTLConfig(data);
|
||||
const config: TTLConfig = await ConfigDBService.saveTTLConfig(data);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "⏱️ Configuration TTL sauvegardée avec succès",
|
||||
config: {
|
||||
|
||||
@@ -3,10 +3,11 @@ import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { ERROR_MESSAGES } from "@/constants/errorMessages";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { UserPreferences } from "@/types/preferences";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const preferences = await PreferencesService.getPreferences();
|
||||
const preferences: UserPreferences = await PreferencesService.getPreferences();
|
||||
return NextResponse.json(preferences);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération des préférences:", error);
|
||||
@@ -35,8 +36,10 @@ export async function GET() {
|
||||
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const preferences = await request.json();
|
||||
const updatedPreferences = await PreferencesService.updatePreferences(preferences);
|
||||
const preferences: UserPreferences = await request.json();
|
||||
const updatedPreferences: UserPreferences = await PreferencesService.updatePreferences(
|
||||
preferences
|
||||
);
|
||||
return NextResponse.json(updatedPreferences);
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la mise à jour des préférences:", error);
|
||||
|
||||
@@ -4,10 +4,11 @@ import { BookSkeleton } from "@/components/skeletons/BookSkeleton";
|
||||
import { BookService } from "@/lib/services/book.service";
|
||||
import { notFound } from "next/navigation";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { KomgaBookWithPages } from "@/types/komga";
|
||||
|
||||
async function BookPage({ params }: { params: { bookId: string } }) {
|
||||
try {
|
||||
const data = await BookService.getBook(params.bookId);
|
||||
const data: KomgaBookWithPages = await BookService.getBook(params.bookId);
|
||||
|
||||
return (
|
||||
<Suspense fallback={<BookSkeleton />}>
|
||||
|
||||
@@ -5,7 +5,9 @@ import { revalidatePath } from "next/cache";
|
||||
import { RefreshButton } from "@/components/library/RefreshButton";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
|
||||
import { LibraryResponse } from "@/types/library";
|
||||
import { KomgaSeries, KomgaLibrary } from "@/types/komga";
|
||||
import { UserPreferences } from "@/types/preferences";
|
||||
interface PageProps {
|
||||
params: { libraryId: string };
|
||||
searchParams: { page?: string; unread?: string; search?: string };
|
||||
@@ -36,14 +38,14 @@ async function getLibrarySeries(
|
||||
try {
|
||||
const pageIndex = page - 1;
|
||||
|
||||
const series = await LibraryService.getLibrarySeries(
|
||||
const series: LibraryResponse<KomgaSeries> = await LibraryService.getLibrarySeries(
|
||||
libraryId,
|
||||
pageIndex,
|
||||
PAGE_SIZE,
|
||||
unreadOnly,
|
||||
search
|
||||
);
|
||||
const library = await LibraryService.getLibrary(libraryId);
|
||||
const library: KomgaLibrary = await LibraryService.getLibrary(libraryId);
|
||||
|
||||
return { data: series, library };
|
||||
} catch (error) {
|
||||
@@ -53,19 +55,15 @@ async function getLibrarySeries(
|
||||
|
||||
async function LibraryPage({ params, searchParams }: PageProps) {
|
||||
const currentPage = searchParams.page ? parseInt(searchParams.page) : 1;
|
||||
const preferences = await PreferencesService.getPreferences();
|
||||
const preferences: UserPreferences = await PreferencesService.getPreferences();
|
||||
|
||||
// Utiliser le paramètre d'URL s'il existe, sinon utiliser la préférence utilisateur
|
||||
const unreadOnly =
|
||||
searchParams.unread !== undefined ? searchParams.unread === "true" : preferences.showOnlyUnread;
|
||||
|
||||
try {
|
||||
const { data: series, library } = await getLibrarySeries(
|
||||
params.libraryId,
|
||||
currentPage,
|
||||
unreadOnly,
|
||||
searchParams.search
|
||||
);
|
||||
const { data: series, library }: { data: LibraryResponse<KomgaSeries>; library: KomgaLibrary } =
|
||||
await getLibrarySeries(params.libraryId, currentPage, unreadOnly, searchParams.search);
|
||||
|
||||
return (
|
||||
<div className="container py-8 space-y-8">
|
||||
|
||||
@@ -5,6 +5,9 @@ import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
import { LibraryResponse } from "@/types/library";
|
||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||
import { UserPreferences } from "@/types/preferences";
|
||||
|
||||
interface PageProps {
|
||||
params: { seriesId: string };
|
||||
@@ -17,8 +20,13 @@ async function getSeriesBooks(seriesId: string, page: number = 1, unreadOnly: bo
|
||||
try {
|
||||
const pageIndex = page - 1;
|
||||
|
||||
const books = await SeriesService.getSeriesBooks(seriesId, pageIndex, PAGE_SIZE, unreadOnly);
|
||||
const series = await SeriesService.getSeries(seriesId);
|
||||
const books: LibraryResponse<KomgaBook> = await SeriesService.getSeriesBooks(
|
||||
seriesId,
|
||||
pageIndex,
|
||||
PAGE_SIZE,
|
||||
unreadOnly
|
||||
);
|
||||
const series: KomgaSeries = await SeriesService.getSeries(seriesId);
|
||||
|
||||
return { data: books, series };
|
||||
} catch (error) {
|
||||
@@ -42,14 +50,15 @@ async function refreshSeries(seriesId: string) {
|
||||
|
||||
async function SeriesPage({ params, searchParams }: PageProps) {
|
||||
const currentPage = searchParams.page ? parseInt(searchParams.page) : 1;
|
||||
const preferences = await PreferencesService.getPreferences();
|
||||
const preferences: UserPreferences = await PreferencesService.getPreferences();
|
||||
|
||||
// Utiliser le paramètre d'URL s'il existe, sinon utiliser la préférence utilisateur
|
||||
const unreadOnly =
|
||||
searchParams.unread !== undefined ? searchParams.unread === "true" : preferences.showOnlyUnread;
|
||||
|
||||
try {
|
||||
const { data: books, series } = await getSeriesBooks(params.seriesId, currentPage, unreadOnly);
|
||||
const { data: books, series }: { data: LibraryResponse<KomgaBook>; series: KomgaSeries } =
|
||||
await getSeriesBooks(params.seriesId, currentPage, unreadOnly);
|
||||
|
||||
return (
|
||||
<div className="container py-8 space-y-8">
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ClientSettings } from "@/components/settings/ClientSettings";
|
||||
import { Metadata } from "next";
|
||||
import { KomgaConfig, TTLConfig } from "@/types/komga";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Préférences",
|
||||
@@ -8,18 +9,19 @@ export const metadata: Metadata = {
|
||||
};
|
||||
|
||||
export default async function SettingsPage() {
|
||||
let config = null;
|
||||
let ttlConfig = null;
|
||||
let config: KomgaConfig | null = null;
|
||||
let ttlConfig: TTLConfig | null = null;
|
||||
|
||||
try {
|
||||
// Récupérer la configuration Komga
|
||||
const mongoConfig = await ConfigDBService.getConfig();
|
||||
const mongoConfig: KomgaConfig | null = await ConfigDBService.getConfig();
|
||||
if (mongoConfig) {
|
||||
config = {
|
||||
url: mongoConfig.url,
|
||||
username: mongoConfig.username,
|
||||
userId: mongoConfig.userId,
|
||||
authHeader: mongoConfig.authHeader,
|
||||
password: null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user