37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { authenticateRelayNode } from "@/db/relay-control-plane";
|
|
import { advanceRelayMigration } from "@/db/relay-migrations";
|
|
import { apiError, readJsonMutation } from "../../../../respond";
|
|
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const principal = await authenticateRelayNode(request);
|
|
const payload = await readJsonMutation<{
|
|
migration_id?: string;
|
|
action?: "quiesced" | "copied" | "switched" | "finalized" | "failed";
|
|
backup_ref?: string;
|
|
manifest_sha256?: string;
|
|
error_code?: string;
|
|
}>(request);
|
|
if (!payload.action) {
|
|
return Response.json(
|
|
{ error_code: "invalid_relay_migration", message: "迁移动作无效", retryable: false },
|
|
{ status: 400, headers: { "cache-control": "no-store" } },
|
|
);
|
|
}
|
|
const migration = await advanceRelayMigration({
|
|
principal,
|
|
migrationId: payload.migration_id ?? "",
|
|
action: payload.action,
|
|
backupRef: payload.backup_ref,
|
|
manifestSha256: payload.manifest_sha256,
|
|
errorCode: payload.error_code,
|
|
});
|
|
return Response.json(
|
|
{ migration_id: migration.id, state: migration.state, updated_at: migration.updated_at },
|
|
{ headers: { "cache-control": "no-store" } },
|
|
);
|
|
} catch (error) {
|
|
return apiError(error);
|
|
}
|
|
}
|