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:
@@ -1,45 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { LibraryService } from "@/lib/services/library.service";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { getErrorMessage } from "@/utils/errors";
|
||||
import type { NextRequest } from "next/server";
|
||||
import logger from "@/lib/logger";
|
||||
|
||||
export async function POST(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ libraryId: string }> }
|
||||
) {
|
||||
try {
|
||||
const libraryId: string = (await params).libraryId;
|
||||
|
||||
// Scan library with deep=false
|
||||
await LibraryService.scanLibrary(libraryId, false);
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (error) {
|
||||
logger.error({ err: error }, "API Library Scan - Erreur");
|
||||
if (error instanceof AppError) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: error.code,
|
||||
name: "Library scan error",
|
||||
message: getErrorMessage(error.code),
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: {
|
||||
code: ERROR_CODES.LIBRARY.SCAN_ERROR,
|
||||
name: "Library scan error",
|
||||
message: getErrorMessage(ERROR_CODES.LIBRARY.SCAN_ERROR),
|
||||
},
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user