feat: establish NekoNest Cloud control and relay
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import {
|
||||
authenticateRelayNode,
|
||||
heartbeatRelayNode,
|
||||
} from "@/db/relay-control-plane";
|
||||
import { relayMigrationAssignments } from "@/db/relay-migrations";
|
||||
import { relayPurgeAssignments } from "@/db/relay-purges";
|
||||
import { apiError, readJsonMutation } from "../../../respond";
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const principal = await authenticateRelayNode(request);
|
||||
const payload = await readJsonMutation<{
|
||||
generation?: number;
|
||||
capacity_tenants?: number;
|
||||
}>(request);
|
||||
const heartbeat = await heartbeatRelayNode({
|
||||
principal,
|
||||
generation: Number(payload.generation ?? -1),
|
||||
capacityTenants: Number(payload.capacity_tenants ?? -1),
|
||||
});
|
||||
const [migrations, purges] = await Promise.all([
|
||||
relayMigrationAssignments(principal),
|
||||
relayPurgeAssignments(principal),
|
||||
]);
|
||||
return Response.json(
|
||||
{ ...heartbeat, migrations, purges },
|
||||
{ headers: { "cache-control": "no-store" } },
|
||||
);
|
||||
} catch (error) {
|
||||
return apiError(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user