39 lines
1005 B
TypeScript
39 lines
1005 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { backupService } from "@/services/backup.service";
|
|
|
|
export async function POST(_request: NextRequest) {
|
|
try {
|
|
// Check if automatic backup should run
|
|
const shouldRun = await backupService.shouldRunAutomaticBackup();
|
|
|
|
if (!shouldRun) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
skipped: true,
|
|
message: "Backup not due yet",
|
|
});
|
|
}
|
|
|
|
// Create backup
|
|
const backup = await backupService.createBackup();
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: backup,
|
|
message: backup.skipped
|
|
? "Backup skipped - no changes detected"
|
|
: "Automatic backup created",
|
|
});
|
|
} catch (error) {
|
|
console.error("Error creating automatic backup:", error);
|
|
return NextResponse.json(
|
|
{
|
|
success: false,
|
|
error: error instanceof Error ? error.message : "Failed to create automatic backup",
|
|
},
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|