Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

1.5 KB
Raw Blame
import { selectionFrom } from "@/lib/infra/connection-dispatch";
import { MSO_ORIGIN } from "@/lib/mcp/ui-config";
import { NextRequest, NextResponse } from "next/server";
import { getSessionContext } from "@/lib/auth/require-session";
import { audit } from "@/lib/host/audit-api";
import { openIntegrationSetup } from "@/lib/infra/setup-capability";
import { readSetupJson } from "@/lib/infra/setup-http";

const headers = { "Cache-Control": "no-store, private", "Referrer-Policy": "no-referrer" };

export async function handlePostInfraSetup(req: NextRequest): Promise<Response> {
  const context = await getSessionContext();
  if (context?.role !== "owner" || !context.session.device_id)
    return NextResponse.json({ error: "owner_required" }, { status: 403, headers });
  try {
    const body = await readSetupJson(req);
    if (
      Object.keys(body).some((k) => !["provider", "method", "user", "connection"].includes(k)) ||
      typeof body.provider !== "string" ||
      (body.method !== undefined && typeof body.method !== "string")
    )
      throw new Error("invalid");
    const grant = await openIntegrationSetup(body.provider, context.session.device_id, body.method as string | undefined, selectionFrom(body));
    void audit({ action: "infra.write", actor: context.session.device_id, target: body.provider, ok: true, detail: "integration.setup-open" });
    return NextResponse.json({ ...grant, setupUrl: `${MSO_ORIGIN}/integrations` }, { headers });
  } catch {
    return NextResponse.json({ error: "setup_unavailable" }, { status: 400, headers });
  }
}