Files
portabase/app/api/v1/databases/[id]/backup/[backupId]/route.ts
T

61 lines
1.8 KiB
TypeScript
Raw Normal View History

import { NextResponse } from "next/server";
2026-05-25 18:31:00 +02:00
import { withApiKey } from "@/lib/api-v1/middleware";
import { db } from "@/db";
import * as drizzleDb from "@/db";
2026-05-27 22:02:22 +02:00
import { and, eq, isNull } from "drizzle-orm";
import { logger } from "@/lib/logger";
2026-05-27 22:02:22 +02:00
import { ApiKeyContext } from "@/lib/api-v1/types";
import {requireDatabaseAccess} from "@/lib/api-v1/services/databases";
2026-05-27 22:02:22 +02:00
const log = logger.child({
module: "api/v1/databases/[id]/backup/[backupId]",
});
export const GET = withApiKey(
2026-05-27 22:02:22 +02:00
async (_req: Request, ctx: ApiKeyContext, params?: Record<string, string>) => {
try {
const guard = await requireDatabaseAccess(params, ctx.user);
2026-05-27 22:02:22 +02:00
if (!guard.ok) {
return guard.response;
}
const { id } = guard.data;
const backupId = params?.backupId;
if (!backupId) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
const backup = await db.query.backup.findFirst({
where: and(
eq(drizzleDb.schemas.backup.id, backupId),
eq(drizzleDb.schemas.backup.databaseId, id),
isNull(drizzleDb.schemas.backup.deletedAt)
),
with: {
storages: {
where: (backupStorage, { isNull }) =>
isNull(backupStorage.deletedAt),
},
},
});
2026-05-27 22:02:22 +02:00
if (!backup) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
return NextResponse.json({ data: backup });
} catch (error) {
log.error(
{ error },
"Error in GET /api/v1/databases/[id]/backup/[backupId]"
);
return NextResponse.json(
2026-05-27 22:02:22 +02:00
{ error: "Internal server error" },
{ status: 500 }
);
}
}
2026-05-27 22:02:22 +02:00
);