fix: lints
This commit is contained in:
1
src/app/api/komga/cache/mode/route.ts
vendored
1
src/app/api/komga/cache/mode/route.ts
vendored
@@ -18,6 +18,7 @@ export async function POST(request: Request) {
|
||||
serverCacheService.setCacheMode(mode);
|
||||
return NextResponse.json({ mode: serverCacheService.getCacheMode() });
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la mise à jour du mode de cache:", error);
|
||||
return NextResponse.json({ error: "Invalid request" }, { status: 400 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable @next/next/no-img-element */
|
||||
"use client";
|
||||
|
||||
import { BookReaderProps } from "./types";
|
||||
|
||||
@@ -33,6 +33,7 @@ export function CacheModeSwitch() {
|
||||
description: `Le cache est maintenant en mode ${checked ? "mémoire" : "fichier"}`,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la modification du mode de cache:", error);
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Erreur",
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { ImageOff } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { useState, useEffect, useRef, useCallback } from "react";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { ImageLoader } from "@/components/ui/image-loader";
|
||||
|
||||
@@ -29,23 +29,21 @@ export function Cover({
|
||||
}: CoverProps) {
|
||||
const [imageError, setImageError] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isInViewport, setIsInViewport] = useState(false);
|
||||
const [imageUrl, setImageUrl] = useState<string | null>(null);
|
||||
const coverRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const getImageUrl = () => {
|
||||
const getImageUrl = useCallback(() => {
|
||||
if (type === "series") {
|
||||
return `/api/komga/images/series/${id}/thumbnail`;
|
||||
}
|
||||
return `/api/komga/images/books/${id}/thumbnail`;
|
||||
};
|
||||
}, [type, id]);
|
||||
|
||||
// Observer pour détecter quand la cover est dans le viewport
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
entries.forEach((entry) => {
|
||||
setIsInViewport(entry.isIntersecting);
|
||||
if (entry.isIntersecting && !imageUrl) {
|
||||
setImageUrl(getImageUrl());
|
||||
}
|
||||
@@ -66,7 +64,7 @@ export function Cover({
|
||||
observer.unobserve(element);
|
||||
}
|
||||
};
|
||||
}, [id, imageUrl]);
|
||||
}, [id, imageUrl, getImageUrl]);
|
||||
|
||||
if (imageError) {
|
||||
return (
|
||||
|
||||
@@ -42,6 +42,7 @@ export function MarkAsReadButton({
|
||||
});
|
||||
onSuccess?.();
|
||||
} catch (error) {
|
||||
console.error("Erreur lors de la mise à jour du progresseur de lecture:", error);
|
||||
toast({
|
||||
title: "Erreur",
|
||||
description: "Impossible de marquer le tome comme lu",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { cookies } from "next/headers";
|
||||
import connectDB from "@/lib/mongodb";
|
||||
import { PreferencesModel } from "@/lib/models/preferences.model";
|
||||
|
||||
interface User {
|
||||
|
||||
@@ -74,7 +74,8 @@ class ServerCacheService {
|
||||
if (isSubDirEmpty) {
|
||||
try {
|
||||
fs.rmdirSync(itemPath);
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
console.error(`Could not remove directory ${itemPath}:`, error);
|
||||
isEmpty = false;
|
||||
}
|
||||
} else {
|
||||
@@ -89,18 +90,21 @@ class ServerCacheService {
|
||||
} else {
|
||||
isEmpty = false;
|
||||
}
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
console.error(`Could not parse file ${itemPath}:`, error);
|
||||
// Si le fichier est corrompu, on le supprime
|
||||
try {
|
||||
fs.unlinkSync(itemPath);
|
||||
} catch (_) {
|
||||
} catch (error) {
|
||||
console.error(`Could not remove file ${itemPath}:`, error);
|
||||
isEmpty = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isEmpty = false;
|
||||
}
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
console.error(`Could not access ${itemPath}:`, error);
|
||||
// En cas d'erreur sur le fichier/dossier, on continue
|
||||
isEmpty = false;
|
||||
continue;
|
||||
@@ -146,7 +150,6 @@ class ServerCacheService {
|
||||
}
|
||||
|
||||
this.config.mode = mode;
|
||||
console.log(`Cache mode switched to: ${mode}`);
|
||||
}
|
||||
|
||||
public getCacheMode(): CacheMode {
|
||||
@@ -174,11 +177,13 @@ class ServerCacheService {
|
||||
const key = path.relative(this.cacheDir, itemPath).slice(0, -5); // Remove .json
|
||||
this.memoryCache.set(key, cached);
|
||||
}
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
console.error(`Could not parse file ${itemPath}:`, error);
|
||||
// Ignore les fichiers corrompus
|
||||
}
|
||||
}
|
||||
} catch (_error) {
|
||||
} catch (error) {
|
||||
console.error(`Could not access ${itemPath}:`, error);
|
||||
// Ignore les erreurs d'accès
|
||||
}
|
||||
}
|
||||
@@ -196,8 +201,8 @@ class ServerCacheService {
|
||||
fs.mkdirSync(dirPath, { recursive: true });
|
||||
}
|
||||
fs.writeFileSync(filePath, JSON.stringify(value), "utf-8");
|
||||
} catch (_error) {
|
||||
// Ignore les erreurs d'écriture
|
||||
} catch (error) {
|
||||
console.error(`Could not write cache file ${filePath}:`, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -303,25 +308,24 @@ class ServerCacheService {
|
||||
removeDirectory(itemPath);
|
||||
try {
|
||||
fs.rmdirSync(itemPath);
|
||||
} catch (_error) {
|
||||
console.error(`Could not remove directory ${itemPath}`);
|
||||
} catch (error) {
|
||||
console.error(`Could not remove directory ${itemPath}:`, error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
fs.unlinkSync(itemPath);
|
||||
} catch (_error) {
|
||||
console.error(`Could not remove file ${itemPath}`);
|
||||
} catch (error) {
|
||||
console.error(`Could not remove file ${itemPath}:`, error);
|
||||
}
|
||||
}
|
||||
} catch (_error) {
|
||||
console.error(`Error accessing ${itemPath}`);
|
||||
} catch (error) {
|
||||
console.error(`Error accessing ${itemPath}:`, error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
removeDirectory(this.cacheDir);
|
||||
console.log("Cache cleared successfully");
|
||||
} catch (error) {
|
||||
console.error("Error clearing cache:", error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user