import { Code } from "@betternas/ui/code"; import { CopyField } from "./copy-field"; import { ControlPlaneConfigurationError, ControlPlaneRequestError, getControlPlaneConfig, issueMountProfile, listExports, type MountProfile, type StorageExport, } from "../lib/control-plane"; import styles from "./page.module.css"; export const dynamic = "force-dynamic"; interface PageProps { searchParams: Promise<{ exportId?: string | string[]; }>; } export default async function Home({ searchParams }: PageProps) { const resolvedSearchParams = await searchParams; const selectedExportId = readSearchParam(resolvedSearchParams.exportId); const controlPlaneConfig = await getControlPlaneConfig(); let exports: StorageExport[] = []; let mountProfile: MountProfile | null = null; let feedback: string | null = null; try { exports = await listExports(); if (selectedExportId !== null) { if ( exports.some((storageExport) => storageExport.id === selectedExportId) ) { mountProfile = await issueMountProfile(selectedExportId); } else { feedback = `Export ${selectedExportId} was not found in the current control-plane response.`; } } } catch (error) { if ( error instanceof ControlPlaneConfigurationError || error instanceof ControlPlaneRequestError ) { feedback = error.message; } else { throw error; } } const selectedExport = selectedExportId === null ? null : (exports.find( (storageExport) => storageExport.id === selectedExportId, ) ?? null); return (

betterNAS control plane

Mount exports from the live control-plane.

This page reads the running control-plane, lists available exports, and issues Finder-friendly WebDAV mount credentials for the export you select.

Control-plane URL
{controlPlaneConfig.baseUrl ?? "Not configured"}
Auth mode
{controlPlaneConfig.clientToken === null ? "Missing client token" : "Server-side bearer token"}
Exports discovered
{exports.length}

Exports

Registered storage exports

{exports.length === 1 ? "1 export" : `${exports.length} exports`}
{feedback !== null ? (
{feedback}
) : null} {exports.length === 0 ? (
No exports are registered yet. Start the node agent and verify the control-plane connection first.
) : (
{exports.map((storageExport) => { const isSelected = storageExport.id === selectedExportId; return (

{storageExport.label}

{storageExport.id}

{storageExport.protocols.join(", ")}
Node
{storageExport.nasNodeId}
Mount path
{storageExport.mountPath ?? "/dav/"}
Export path
{storageExport.path}
); })}
)}
); } function readSearchParam(value: string | string[] | undefined): string | null { if (typeof value === "string" && value.trim() !== "") { return value.trim(); } if (Array.isArray(value)) { const firstValue = value.find( (candidateValue) => candidateValue.trim() !== "", ); return firstValue?.trim() ?? null; } return null; }