Add controller node selector and accordion wizards
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { Client } from "ssh2"
|
||||
import { buildControllerNodePlan, type ControllerPlanRequest } from "@/app/lib/controllerNodePlan"
|
||||
import { upsertControllerNode } from "@/app/lib/controllerNodeRegistry"
|
||||
|
||||
export const runtime = "nodejs"
|
||||
|
||||
@@ -147,6 +148,13 @@ export async function POST(request: Request) {
|
||||
acceptUnknownHostKey,
|
||||
expectedHostKeySha256,
|
||||
})
|
||||
await upsertControllerNode({
|
||||
id: plan.controller.name,
|
||||
name: plan.controller.name,
|
||||
host: plan.controller.host,
|
||||
url: plan.controller.url,
|
||||
role: "controller-node",
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
ok: true,
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { buildControllerNodePlan, type ControllerPlanRequest } from "@/app/lib/controllerNodePlan"
|
||||
import { upsertControllerNode } from "@/app/lib/controllerNodeRegistry"
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = (await request.json().catch(() => ({}))) as ControllerPlanRequest
|
||||
return NextResponse.json({ ok: true, ...buildControllerNodePlan(body) })
|
||||
const plan = buildControllerNodePlan(body)
|
||||
await upsertControllerNode({
|
||||
id: plan.controller.name,
|
||||
name: plan.controller.name,
|
||||
host: plan.controller.host,
|
||||
url: plan.controller.url,
|
||||
role: "controller-node",
|
||||
})
|
||||
return NextResponse.json({ ok: true, ...plan })
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to build controller node plan"
|
||||
return NextResponse.json({ ok: false, error: message }, { status: 400 })
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { NextResponse } from "next/server"
|
||||
import { listControllerNodes, renameControllerNode, upsertControllerNode } from "@/app/lib/controllerNodeRegistry"
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
return NextResponse.json({ nodes: await listControllerNodes() })
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to load controller nodes"
|
||||
return NextResponse.json({ error: message }, { status: 500 })
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.json().catch(() => ({}))
|
||||
const action = typeof body?.action === "string" ? body.action : "upsert"
|
||||
|
||||
if (action === "rename") {
|
||||
const node = await renameControllerNode(String(body?.nodeId || ""), String(body?.name || ""))
|
||||
return NextResponse.json({ node, nodes: await listControllerNodes() })
|
||||
}
|
||||
|
||||
const node = await upsertControllerNode({
|
||||
id: body?.id,
|
||||
name: body?.name,
|
||||
host: body?.host,
|
||||
url: body?.url,
|
||||
role: body?.role,
|
||||
})
|
||||
|
||||
return NextResponse.json({ node, nodes: await listControllerNodes() })
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to update controller nodes"
|
||||
return NextResponse.json({ error: message }, { status: 400 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user