feat : File caching option

This commit is contained in:
Julien Froidefond
2025-02-19 16:33:21 +01:00
parent a5fd165200
commit aed35ce2b9
9 changed files with 445 additions and 55 deletions

View File

@@ -0,0 +1,59 @@
"use client";
import { useState } from "react";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { useToast } from "@/components/ui/use-toast";
import { usePreferences } from "@/contexts/PreferencesContext";
export function CacheModeSwitch() {
const [isLoading, setIsLoading] = useState(false);
const { toast } = useToast();
const { preferences, updatePreferences } = usePreferences();
const handleToggle = async (checked: boolean) => {
setIsLoading(true);
try {
// Mettre à jour les préférences
await updatePreferences({ cacheMode: checked ? "memory" : "file" });
// Mettre à jour le mode de cache côté serveur
const res = await fetch("/api/komga/cache/mode", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ mode: checked ? "memory" : "file" }),
});
if (!res.ok) throw new Error();
toast({
title: "Mode de cache modifié",
description: `Le cache est maintenant en mode ${checked ? "mémoire" : "fichier"}`,
});
} catch (error) {
toast({
variant: "destructive",
title: "Erreur",
description: "Impossible de modifier le mode de cache",
});
} finally {
setIsLoading(false);
}
};
return (
<div className="flex items-center space-x-2">
<Switch
id="cache-mode"
checked={preferences.cacheMode === "memory"}
onCheckedChange={handleToggle}
disabled={isLoading}
/>
<Label htmlFor="cache-mode" className="text-sm text-muted-foreground">
Cache en mémoire {isLoading && "(chargement...)"}
</Label>
</div>
);
}

View File

@@ -8,6 +8,7 @@ import { useToast } from "@/components/ui/use-toast";
import { usePreferences } from "@/contexts/PreferencesContext";
import { Switch } from "@/components/ui/switch";
import { Label } from "@/components/ui/label";
import { CacheModeSwitch } from "@/components/settings/CacheModeSwitch";
interface KomgaConfig {
url: string;
@@ -416,6 +417,16 @@ export function ClientSettings({ initialConfig, initialTTLConfig }: ClientSettin
</p>
</div>
<div className="flex items-center justify-between mb-4">
<div className="space-y-0.5">
<Label htmlFor="cache-mode">Mode de cache</Label>
<p className="text-sm text-muted-foreground">
Le cache en mémoire est plus rapide mais ne persiste pas entre les redémarrages
</p>
</div>
<CacheModeSwitch />
</div>
{/* Formulaire TTL */}
<form onSubmit={handleSaveTTL} className="space-y-4">
<div className="grid gap-3 sm:grid-cols-2">

View File

@@ -0,0 +1,25 @@
"use client";
import * as React from "react";
import * as SeparatorPrimitive from "@radix-ui/react-separator";
import { cn } from "@/lib/utils";
const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(({ className, orientation = "horizontal", decorative = true, ...props }, ref) => (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn(
"shrink-0 bg-border",
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
className
)}
{...props}
/>
));
Separator.displayName = SeparatorPrimitive.Root.displayName;
export { Separator };