refactor: convert library scan to Server Action

- Add src/app/actions/library.ts with scanLibrary
- Update ScanButton to use Server Action
- Remove POST from api/komga/libraries/[libraryId]/scan route
This commit is contained in:
2026-02-28 10:53:41 +01:00
parent d56b0fd7ae
commit 6180f9abb1
4 changed files with 35 additions and 57 deletions

View File

@@ -0,0 +1,28 @@
"use server";
import { revalidatePath } from "next/cache";
import { LibraryService } from "@/lib/services/library.service";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
/**
* Lance un scan de bibliothèque
*/
export async function scanLibrary(
libraryId: string
): Promise<{ success: boolean; message: string }> {
try {
await LibraryService.scanLibrary(libraryId, false);
// Invalider le cache de la bibliothèque
revalidatePath(`/libraries/${libraryId}`);
revalidatePath("/libraries");
return { success: true, message: "Scan lancé" };
} catch (error) {
if (error instanceof AppError) {
return { success: false, message: error.message };
}
return { success: false, message: "Erreur lors du scan" };
}
}