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:
28
src/app/actions/library.ts
Normal file
28
src/app/actions/library.ts
Normal 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" };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user