refactor: convert Komga test connection to Server Action

- Add testKomgaConnection to config.ts
- Update KomgaSettings to use Server Action
- Remove api/komga/test route
This commit is contained in:
2026-02-28 11:09:48 +01:00
parent b40f59bec6
commit eec51b7ef8
4 changed files with 35 additions and 53 deletions

View File

@@ -1,37 +0,0 @@
import { NextResponse } from "next/server";
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";
import logger from "@/lib/logger";
export async function POST(request: NextRequest) {
try {
const { serverUrl, username, password } = await request.json();
const authHeader = Buffer.from(`${username}:${password}`).toString("base64");
const { libraries }: { libraries: KomgaLibrary[] } = await TestService.testConnection({
serverUrl,
authHeader,
});
return NextResponse.json({
message: `✅ Connexion réussie ! ${libraries.length} bibliothèque${
libraries.length > 1 ? "s" : ""
} trouvée${libraries.length > 1 ? "s" : ""}`,
});
} catch (error) {
logger.error({ err: error }, "Erreur lors du test de connexion:");
return NextResponse.json(
{
error: {
code: ERROR_CODES.KOMGA.CONNECTION_ERROR,
name: "Connection error",
message: getErrorMessage(ERROR_CODES.KOMGA.CONNECTION_ERROR),
},
},
{ status: 400 }
);
}
}