fix: types of nj15
This commit is contained in:
@@ -3,9 +3,8 @@
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"plugins": ["@typescript-eslint", "unused-imports"],
|
||||
"rules": {
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": [
|
||||
"error",
|
||||
"warn",
|
||||
{
|
||||
"argsIgnorePattern": "^_",
|
||||
"varsIgnorePattern": "^_",
|
||||
@@ -23,7 +22,7 @@
|
||||
"no-unreachable": "error",
|
||||
"no-unused-expressions": "warn",
|
||||
"no-unused-private-class-members": "warn",
|
||||
"unused-imports/no-unused-imports": "error",
|
||||
"unused-imports/no-unused-imports": "warn",
|
||||
"unused-imports/no-unused-vars": [
|
||||
"warn",
|
||||
{
|
||||
@@ -34,7 +33,6 @@
|
||||
}
|
||||
],
|
||||
"no-empty-function": "warn",
|
||||
"no-empty": ["warn", { "allowEmptyCatch": true }],
|
||||
"@typescript-eslint/consistent-type-imports": ["error", { "prefer": "type-imports" }]
|
||||
"no-empty": ["warn", { "allowEmptyCatch": true }]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint",
|
||||
"typecheck": "tsc --noEmit",
|
||||
"icons": "node scripts/generate-icons.js"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@@ -4,14 +4,14 @@ import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import type { UserData } from "@/lib/services/auth-server.service";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
import type { NextRequest } from "next/server";
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { email, password } = await request.json();
|
||||
|
||||
try {
|
||||
const userData: UserData = await AuthServerService.loginUser(email, password);
|
||||
AuthServerService.setUserCookie(userData);
|
||||
await AuthServerService.setUserCookie(userData);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "✅ Connexion réussie",
|
||||
|
||||
@@ -7,7 +7,9 @@ import type { AppErrorType } from "@/types/global";
|
||||
export async function POST() {
|
||||
try {
|
||||
// Supprimer le cookie
|
||||
cookies().delete("stripUser");
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.delete("stripUser");
|
||||
|
||||
return NextResponse.json({ message: "👋 Déconnexion réussie" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la déconnexion:", error);
|
||||
|
||||
@@ -4,14 +4,15 @@ import { AuthServerService } from "@/lib/services/auth-server.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { email, password } = await request.json();
|
||||
|
||||
try {
|
||||
const userData: UserData = await AuthServerService.createUser(email, password);
|
||||
AuthServerService.setUserCookie(userData);
|
||||
await AuthServerService.setUserCookie(userData);
|
||||
|
||||
return NextResponse.json({
|
||||
message: "✅ Inscription réussie",
|
||||
|
||||
@@ -7,12 +7,13 @@ import { AppError } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { bookId: string; pageNumber: string } }
|
||||
) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const pageNumber: number = parseInt(params.pageNumber);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const pageNumberParam = params.get("pageNumber") || "0";
|
||||
const bookIdParam = params.get("bookId") || "";
|
||||
|
||||
const pageNumber: number = parseInt(pageNumberParam);
|
||||
if (isNaN(pageNumber) || pageNumber < 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -26,7 +27,7 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
|
||||
const response = await BookService.getPage(params.bookId, pageNumber);
|
||||
const response = await BookService.getPage(bookIdParam, pageNumber);
|
||||
const buffer = await response.arrayBuffer();
|
||||
const headers = new Headers();
|
||||
headers.set("Content-Type", response.headers.get("Content-Type") || "image/jpeg");
|
||||
|
||||
@@ -5,9 +5,11 @@ import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import { AppError } from "@/utils/errors";
|
||||
|
||||
export async function PATCH(request: NextRequest, { params }: { params: { bookId: string } }) {
|
||||
export async function PATCH(request: NextRequest) {
|
||||
try {
|
||||
const { page, completed } = await request.json();
|
||||
const params = request.nextUrl.searchParams;
|
||||
const bookId: string = params.get("bookId") || "";
|
||||
|
||||
if (typeof page !== "number") {
|
||||
return NextResponse.json(
|
||||
@@ -22,7 +24,7 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
|
||||
);
|
||||
}
|
||||
|
||||
await BookService.updateReadProgress(params.bookId, page, completed);
|
||||
await BookService.updateReadProgress(bookId, page, completed);
|
||||
return NextResponse.json({ message: "📖 Progression mise à jour avec succès" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la mise à jour de la progression:", error);
|
||||
@@ -51,9 +53,12 @@ export async function PATCH(request: NextRequest, { params }: { params: { bookId
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(request: NextRequest, { params }: { params: { bookId: string } }) {
|
||||
export async function DELETE(request: NextRequest) {
|
||||
try {
|
||||
await BookService.deleteReadProgress(params.bookId);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const bookId: string = params.get("bookId") || "";
|
||||
|
||||
await BookService.deleteReadProgress(bookId);
|
||||
return NextResponse.json({ message: "🗑️ Progression supprimée avec succès" });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la suppression de la progression:", error);
|
||||
|
||||
@@ -4,9 +4,14 @@ import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import type { KomgaBookWithPages } from "@/types/komga";
|
||||
export async function GET(request: Request, { params }: { params: { bookId: string } }) {
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const data: KomgaBookWithPages = await BookService.getBook(params.bookId);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const bookId: string = params.get("bookId") || "";
|
||||
|
||||
const data: KomgaBookWithPages = await BookService.getBook(bookId);
|
||||
return NextResponse.json(data);
|
||||
} catch (error) {
|
||||
console.error("API Books - Erreur:", error);
|
||||
|
||||
@@ -5,13 +5,13 @@ import { LibraryService } from "@/lib/services/library.service";
|
||||
import { HomeService } from "@/lib/services/home.service";
|
||||
import { SeriesService } from "@/lib/services/series.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: { libraryId: string; seriesId: string } }
|
||||
) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { libraryId, seriesId } = params;
|
||||
const params = request.nextUrl.searchParams;
|
||||
const libraryId: string = params.get("libraryId") || "";
|
||||
const seriesId: string = params.get("seriesId") || "";
|
||||
|
||||
await HomeService.invalidateHomeCache();
|
||||
revalidatePath("/");
|
||||
|
||||
11
src/app/api/komga/cache/mode/route.ts
vendored
11
src/app/api/komga/cache/mode/route.ts
vendored
@@ -1,12 +1,9 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import type {
|
||||
CacheMode,
|
||||
ServerCacheService} from "@/lib/services/server-cache.service";
|
||||
import {
|
||||
getServerCacheService
|
||||
} from "@/lib/services/server-cache.service";
|
||||
import type { CacheMode, ServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import { getServerCacheService } from "@/lib/services/server-cache.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -27,7 +24,7 @@ export async function GET() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { mode }: { mode: CacheMode } = await request.json();
|
||||
if (mode !== "file" && mode !== "memory") {
|
||||
|
||||
@@ -3,10 +3,11 @@ import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import type { KomgaConfig, KomgaConfigData } from "@/types/komga";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const data: KomgaConfigData = await request.json();
|
||||
const mongoConfig: KomgaConfig = await ConfigDBService.saveConfig(data);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { FavoriteService } from "@/lib/services/favorite.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -35,7 +36,7 @@ export async function GET() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { seriesId }: { seriesId: string } = await request.json();
|
||||
await FavoriteService.addToFavorites(seriesId);
|
||||
@@ -67,7 +68,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request) {
|
||||
export async function DELETE(request: NextRequest) {
|
||||
try {
|
||||
const { seriesId }: { seriesId: string } = await request.json();
|
||||
await FavoriteService.removeFromFavorites(seriesId);
|
||||
|
||||
@@ -7,12 +7,13 @@ import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { bookId: string; pageNumber: string } }
|
||||
) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const response = await BookService.getPage(params.bookId, parseInt(params.pageNumber));
|
||||
const params = request.nextUrl.searchParams;
|
||||
const bookId: string = params.get("bookId") || "";
|
||||
const pageNumber: string = params.get("pageNumber") || "";
|
||||
|
||||
const response = await BookService.getPage(bookId, parseInt(pageNumber));
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la page du livre:", error);
|
||||
|
||||
@@ -7,13 +7,13 @@ import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { bookId: string; pageNumber: string } }
|
||||
) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
// Convertir le numéro de page en nombre
|
||||
const pageNumber: number = parseInt(params.pageNumber);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const bookId: string = params.get("bookId") || "";
|
||||
const pageNumberParam: string = params.get("pageNumber") || "";
|
||||
|
||||
const pageNumber: number = parseInt(pageNumberParam);
|
||||
if (isNaN(pageNumber) || pageNumber < 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
@@ -27,7 +27,7 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
|
||||
const response = await BookService.getPageThumbnail(params.bookId, pageNumber);
|
||||
const response = await BookService.getPageThumbnail(bookId, pageNumber);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la miniature de la page:", error);
|
||||
|
||||
@@ -5,9 +5,12 @@ import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: { bookId: string } }) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const response = await BookService.getCover(params.bookId);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const bookId: string = params.get("bookId") || "";
|
||||
|
||||
const response = await BookService.getCover(bookId);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la miniature du livre:", error);
|
||||
|
||||
@@ -7,9 +7,12 @@ import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: { seriesId: string } }) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const response = await SeriesService.getCover(params.seriesId);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const seriesId: string = params.get("seriesId") || "";
|
||||
|
||||
const response = await SeriesService.getCover(seriesId);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la couverture de la série:", error);
|
||||
|
||||
@@ -5,9 +5,12 @@ import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
export async function GET(request: NextRequest, { params }: { params: { seriesId: string } }) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const response = await SeriesService.getCover(params.seriesId);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const seriesId: string = params.get("seriesId") || "";
|
||||
|
||||
const response = await SeriesService.getCover(seriesId);
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la récupération de la miniature de la série:", error);
|
||||
|
||||
@@ -4,12 +4,15 @@ import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import type { KomgaSeries } from "@/types/komga";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
|
||||
import type { NextRequest } from "next/server";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET(request: Request, { params }: { params: { seriesId: string } }) {
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const series: KomgaSeries = await SeriesService.getSeries(params.seriesId);
|
||||
const params = request.nextUrl.searchParams;
|
||||
const seriesId: string = params.get("seriesId") || "";
|
||||
|
||||
const series: KomgaSeries = await SeriesService.getSeries(seriesId);
|
||||
return NextResponse.json(series);
|
||||
} catch (error) {
|
||||
console.error("API Series - Erreur:", error);
|
||||
|
||||
@@ -3,8 +3,9 @@ import { TestService } from "@/lib/services/test.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { KomgaLibrary } from "@/types/komga";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { serverUrl, username, password } = await request.json();
|
||||
const authHeader = Buffer.from(`${username}:${password}`).toString("base64");
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ConfigDBService } from "@/lib/services/config-db.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import type { TTLConfig } from "@/types/komga";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
@@ -37,7 +38,7 @@ export async function GET() {
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const data = await request.json();
|
||||
const config: TTLConfig = await ConfigDBService.saveTTLConfig(data);
|
||||
|
||||
@@ -58,8 +58,8 @@ export const metadata: Metadata = {
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const cookieStore = cookies();
|
||||
export default async function RootLayout({ children }: { children: React.ReactNode }) {
|
||||
const cookieStore = await cookies();
|
||||
const locale = cookieStore.get("NEXT_LOCALE")?.value || "fr";
|
||||
|
||||
return (
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import type { Metadata } from "next";
|
||||
import { LoginContent } from "./LoginContent";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
|
||||
interface PageProps {
|
||||
searchParams: {
|
||||
from?: string;
|
||||
tab?: string;
|
||||
};
|
||||
}
|
||||
export const metadata: Metadata = {
|
||||
title: "Connexion",
|
||||
description: "Connectez-vous à votre compte StripStream",
|
||||
};
|
||||
|
||||
export default function LoginPage({
|
||||
searchParams,
|
||||
}: {
|
||||
searchParams: { from?: string; tab?: string };
|
||||
}) {
|
||||
function LoginPage({ searchParams }: PageProps) {
|
||||
return <LoginContent searchParams={searchParams} />;
|
||||
}
|
||||
export default withPageTiming("LoginPage", LoginPage);
|
||||
|
||||
@@ -67,12 +67,13 @@ export class AuthServerService {
|
||||
return true;
|
||||
}
|
||||
|
||||
static setUserCookie(userData: UserData): void {
|
||||
static async setUserCookie(userData: UserData): Promise<void> {
|
||||
// Encode user data in base64
|
||||
const encodedUserData = Buffer.from(JSON.stringify(userData)).toString("base64");
|
||||
|
||||
// Set cookie with user data
|
||||
cookies().set("stripUser", encodedUserData, {
|
||||
const cookieStore = await cookies();
|
||||
cookieStore.set("stripUser", encodedUserData, {
|
||||
httpOnly: true,
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
sameSite: "lax",
|
||||
@@ -81,8 +82,9 @@ export class AuthServerService {
|
||||
});
|
||||
}
|
||||
|
||||
static getCurrentUser(): UserData | null {
|
||||
const userCookie = cookies().get("stripUser");
|
||||
static async getCurrentUser(): Promise<UserData | null> {
|
||||
const cookieStore = await cookies();
|
||||
const userCookie = cookieStore.get("stripUser");
|
||||
|
||||
if (!userCookie) {
|
||||
return null;
|
||||
|
||||
@@ -8,8 +8,8 @@ import { AppError } from "../../utils/errors";
|
||||
import type { User, KomgaConfigData, TTLConfigData, KomgaConfig, TTLConfig } from "@/types/komga";
|
||||
|
||||
export class ConfigDBService {
|
||||
private static getCurrentUser(): User {
|
||||
const user: User | null = AuthServerService.getCurrentUser();
|
||||
private static async getCurrentUser(): Promise<User> {
|
||||
const user: User | null = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
@@ -18,7 +18,7 @@ export class ConfigDBService {
|
||||
|
||||
static async saveConfig(data: KomgaConfigData): Promise<KomgaConfig> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
const authHeader: string = Buffer.from(`${data.username}:${data.password}`).toString(
|
||||
@@ -51,7 +51,7 @@ export class ConfigDBService {
|
||||
|
||||
static async getConfig(): Promise<KomgaConfig | null> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("getConfig", async () => {
|
||||
@@ -68,7 +68,7 @@ export class ConfigDBService {
|
||||
|
||||
static async getTTLConfig(): Promise<TTLConfig | null> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("getTTLConfig", async () => {
|
||||
@@ -85,7 +85,7 @@ export class ConfigDBService {
|
||||
|
||||
static async saveTTLConfig(data: TTLConfigData): Promise<TTLConfig> {
|
||||
try {
|
||||
const user: User | null = this.getCurrentUser();
|
||||
const user: User | null = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("saveTTLConfig", async () => {
|
||||
|
||||
@@ -25,8 +25,8 @@ export interface RequestTiming {
|
||||
}
|
||||
|
||||
export class DebugService {
|
||||
private static getCurrentUserId(): string {
|
||||
const user = AuthServerService.getCurrentUser();
|
||||
private static async getCurrentUserId(): Promise<string> {
|
||||
const user = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ export class FavoriteService {
|
||||
}
|
||||
}
|
||||
|
||||
private static getCurrentUser(): User {
|
||||
const user = AuthServerService.getCurrentUser();
|
||||
private static async getCurrentUser(): Promise<User> {
|
||||
const user = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ export class FavoriteService {
|
||||
*/
|
||||
static async isFavorite(seriesId: string): Promise<boolean> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("isFavorite", async () => {
|
||||
@@ -50,7 +50,7 @@ export class FavoriteService {
|
||||
*/
|
||||
static async addToFavorites(seriesId: string): Promise<void> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
await DebugService.measureMongoOperation("addToFavorites", async () => {
|
||||
@@ -72,7 +72,7 @@ export class FavoriteService {
|
||||
*/
|
||||
static async removeFromFavorites(seriesId: string): Promise<void> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
await DebugService.measureMongoOperation("removeFromFavorites", async () => {
|
||||
@@ -92,7 +92,7 @@ export class FavoriteService {
|
||||
* Récupère tous les IDs des séries favorites
|
||||
*/
|
||||
static async getAllFavoriteIds(): Promise<string[]> {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("getAllFavoriteIds", async () => {
|
||||
@@ -102,7 +102,7 @@ export class FavoriteService {
|
||||
}
|
||||
|
||||
static async addFavorite(seriesId: string) {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("addFavorite", async () => {
|
||||
@@ -116,7 +116,7 @@ export class FavoriteService {
|
||||
}
|
||||
|
||||
static async removeFavorite(seriesId: string): Promise<boolean> {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
await connectDB();
|
||||
|
||||
return DebugService.measureMongoOperation("removeFavorite", async () => {
|
||||
|
||||
@@ -7,8 +7,8 @@ import { defaultPreferences } from "@/types/preferences";
|
||||
import type { User } from "@/types/komga";
|
||||
|
||||
export class PreferencesService {
|
||||
static getCurrentUser(): User {
|
||||
const user = AuthServerService.getCurrentUser();
|
||||
static async getCurrentUser(): Promise<User> {
|
||||
const user = await AuthServerService.getCurrentUser();
|
||||
if (!user) {
|
||||
throw new AppError(ERROR_CODES.AUTH.UNAUTHENTICATED);
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export class PreferencesService {
|
||||
|
||||
static async getPreferences(): Promise<UserPreferences> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
const preferences = await PreferencesModel.findOne({ userId: user.id });
|
||||
if (!preferences) {
|
||||
return defaultPreferences;
|
||||
@@ -36,7 +36,7 @@ export class PreferencesService {
|
||||
|
||||
static async updatePreferences(preferences: Partial<UserPreferences>): Promise<UserPreferences> {
|
||||
try {
|
||||
const user = this.getCurrentUser();
|
||||
const user = await this.getCurrentUser();
|
||||
const updatedPreferences = await PreferencesModel.findOneAndUpdate(
|
||||
{ userId: user.id },
|
||||
{ $set: preferences },
|
||||
|
||||
Reference in New Issue
Block a user