Some checks failed
Deploy with Docker Compose / deploy (push) Has been cancelled
- Fix POST requests (series/list, books/list) not being cached by Next.js fetch cache by wrapping them with unstable_cache in the private fetch method - Wrap getHomeData() entirely with unstable_cache so all 5 home requests are cached as a single unit, reducing cold-start cost from 5 parallel calls to 0 on cache hit - Remove N+1 book count enrichment from getLibraries() (8 extra calls per cold start) as LibraryDto does not return booksCount and the value was only used in BackgroundSettings - Simplify getLibraryById() to reuse cached getLibraries() data instead of making separate HTTP calls (saves 2 calls per library page load) - Fix cache debug logs: replace misleading x-nextjs-cache header check (always UNKNOWN on external APIs) with pre-request logs showing the configured cache strategy - Remove book count display from BackgroundSettings as it is no longer fetched Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
"use server";
|
|
|
|
import { revalidatePath } from "next/cache";
|
|
import { ConfigDBService } from "@/lib/services/config-db.service";
|
|
import { AppError } from "@/utils/errors";
|
|
import { ERROR_CODES } from "@/constants/errorCodes";
|
|
import type { KomgaConfig, KomgaConfigData, KomgaLibrary } from "@/types/komga";
|
|
|
|
interface SaveConfigInput {
|
|
url: string;
|
|
username: string;
|
|
password?: string;
|
|
authHeader?: string;
|
|
}
|
|
|
|
export async function testKomgaConnection(
|
|
serverUrl: string,
|
|
username: string,
|
|
password: string
|
|
): Promise<{ success: boolean; message: string }> {
|
|
try {
|
|
const authHeader = Buffer.from(`${username}:${password}`).toString("base64");
|
|
const url = new URL(`${serverUrl}/api/v1/libraries`).toString();
|
|
const headers = new Headers({
|
|
Authorization: `Basic ${authHeader}`,
|
|
Accept: "application/json",
|
|
});
|
|
|
|
const response = await fetch(url, { headers });
|
|
|
|
if (!response.ok) {
|
|
throw new AppError(ERROR_CODES.KOMGA.CONNECTION_ERROR);
|
|
}
|
|
|
|
const libraries: KomgaLibrary[] = await response.json();
|
|
return {
|
|
success: true,
|
|
message: `Connexion réussie ! ${libraries.length} bibliothèque${libraries.length > 1 ? "s" : ""} trouvée${libraries.length > 1 ? "s" : ""}`,
|
|
};
|
|
} catch (error) {
|
|
if (error instanceof AppError) {
|
|
return { success: false, message: error.message };
|
|
}
|
|
return { success: false, message: "Erreur lors de la connexion" };
|
|
}
|
|
}
|
|
|
|
export async function saveKomgaConfig(
|
|
config: SaveConfigInput
|
|
): Promise<{ success: boolean; message: string; data?: KomgaConfig }> {
|
|
try {
|
|
const configData: KomgaConfigData = {
|
|
url: config.url,
|
|
username: config.username,
|
|
password: config.password,
|
|
authHeader: config.authHeader || "",
|
|
};
|
|
const mongoConfig = await ConfigDBService.saveConfig(configData);
|
|
revalidatePath("/settings");
|
|
return { success: true, message: "Configuration sauvegardée", data: mongoConfig };
|
|
} catch (error) {
|
|
if (error instanceof AppError) {
|
|
return { success: false, message: error.message };
|
|
}
|
|
return { success: false, message: "Erreur lors de la sauvegarde" };
|
|
}
|
|
}
|