feat: add BackupCard component and corresponding Backup model to enhance settings functionality and data management
This commit is contained in:
38
app/api/backups/auto/route.ts
Normal file
38
app/api/backups/auto/route.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user