diff --git a/apps/control-station/package-lock.json b/apps/control-station/package-lock.json index dc234d48..0c11f688 100644 --- a/apps/control-station/package-lock.json +++ b/apps/control-station/package-lock.json @@ -10,7 +10,7 @@ "hasInstallScript": true, "dependencies": { "@noble/hashes": "^2.2.0", - "@nodedc/bim-viewer": "file:../../vendor/bim/nodedc-bim-viewer-0.2.66.tgz", + "@nodedc/bim-viewer": "file:../../vendor/bim/nodedc-bim-viewer-0.2.74.tgz", "@nodedc/map-cesium-react": "file:../../../NODEDC_DESIGN_GUIDELINE/packages/map-cesium-react", "@nodedc/page-patterns": "file:../../../NODEDC_DESIGN_GUIDELINE/packages/page-patterns", "@nodedc/tokens": "file:../../../NODEDC_DESIGN_GUIDELINE/packages/tokens", @@ -42,7 +42,7 @@ }, "../../../NODEDC_DESIGN_GUIDELINE/packages/map-cesium-react": { "name": "@nodedc/map-cesium-react", - "version": "0.1.2", + "version": "0.1.4", "dependencies": { "cesium": "1.147.0" }, @@ -71,7 +71,7 @@ }, "../../../NODEDC_DESIGN_GUIDELINE/packages/ui-react": { "name": "@nodedc/ui-react", - "version": "0.7.4", + "version": "0.7.5", "dependencies": { "@dnd-kit/core": "^6.3.1", "@dnd-kit/sortable": "^10.0.0", @@ -884,12 +884,12 @@ } }, "node_modules/@nodedc/bim-viewer": { - "version": "0.2.66", - "resolved": "file:../../vendor/bim/nodedc-bim-viewer-0.2.66.tgz", - "integrity": "sha512-aq8LktWb72/UFSDtYExDh+Eccb1dAoc2oiDg5gC+tvobXyofEBUnAdwzElYOAV2mg3CNgC7k74UnJmdJ5pKhJA==", + "version": "0.2.74", + "resolved": "file:../../vendor/bim/nodedc-bim-viewer-0.2.74.tgz", + "integrity": "sha512-pZOXFqDcypBEFEqUIjOEX9BU+J6qMemYYLPy+PitBF7Rw0pK+daKlhtUT/gW69v1BQW0PVKi209hkgRgpI3/Gg==", "peerDependencies": { - "@nodedc/map-cesium-react": ">=0.1.1 <0.2", - "@nodedc/ui-react": ">=0.7.4 <0.8", + "@nodedc/map-cesium-react": ">=0.1.4 <0.2", + "@nodedc/ui-react": ">=0.7.5 <0.8", "react": ">=19 <20", "react-dom": ">=19 <20" } diff --git a/apps/control-station/package.json b/apps/control-station/package.json index f04b02b4..fb8322ad 100644 --- a/apps/control-station/package.json +++ b/apps/control-station/package.json @@ -15,7 +15,7 @@ }, "dependencies": { "@noble/hashes": "^2.2.0", - "@nodedc/bim-viewer": "file:../../vendor/bim/nodedc-bim-viewer-0.2.66.tgz", + "@nodedc/bim-viewer": "file:../../vendor/bim/nodedc-bim-viewer-0.2.74.tgz", "@nodedc/map-cesium-react": "file:../../../NODEDC_DESIGN_GUIDELINE/packages/map-cesium-react", "@nodedc/page-patterns": "file:../../../NODEDC_DESIGN_GUIDELINE/packages/page-patterns", "@nodedc/tokens": "file:../../../NODEDC_DESIGN_GUIDELINE/packages/tokens", diff --git a/apps/control-station/src/components/EnvironmentSettingsWindow.tsx b/apps/control-station/src/components/EnvironmentSettingsWindow.tsx index 143e3c58..90fb024f 100644 --- a/apps/control-station/src/components/EnvironmentSettingsWindow.tsx +++ b/apps/control-station/src/components/EnvironmentSettingsWindow.tsx @@ -1,5 +1,6 @@ import { EnvironmentSettingsWindow as SharedEnvironmentSettingsWindow } from "@nodedc/ui-react"; import { environmentSurfaceIds, type EnvironmentSettings, type EnvironmentSurfaceId, type UploadedEnvironmentMedia } from "../core/environment/environmentSettings"; +import { CesiumServiceSettings } from "./map/CesiumServiceSettings"; import { useLabStorageSettings } from "./storage/LabStorageSettings"; import { roots, workspaces, workspacesForRoot } from "../productModel"; @@ -18,7 +19,7 @@ const surfaces = environmentSurfaceIds.map(id => ({ })); export function EnvironmentSettingsWindow(props: Props) { const storage = useLabStorageSettings(props.open); - return : null}]} onSave={draft => props.onSave({ ...draft, pages: Object.fromEntries(environmentSurfaceIds.map(id => [id, draft.pages[id]])) as EnvironmentSettings["pages"] })} onUpload={(id, itemId, file) => { if (!environmentSurfaceIds.includes(id as EnvironmentSurfaceId)) throw new Error("Страница окружения недоступна."); diff --git a/apps/control-station/src/components/map/CesiumServiceSettings.tsx b/apps/control-station/src/components/map/CesiumServiceSettings.tsx new file mode 100644 index 00000000..7fe7f8fe --- /dev/null +++ b/apps/control-station/src/components/map/CesiumServiceSettings.tsx @@ -0,0 +1,89 @@ +import {useEffect, useState} from "react"; +import {Description, Icon, IconButton, Select, SettingsCard, StatusBadge, TextField} from "@nodedc/ui-react"; +import {cesiumServiceMessage, cesiumTokenIndicator, readCesiumService, saveCesiumService, verifyCesiumService, + type CesiumRouteMode, type CesiumServiceSettings as Settings, type CesiumVerification} from "../../core/map/cesiumService"; +import "./cesiumServiceSettings.css"; +import {serverRequest, type Server} from "../../core/system/servers"; + +export function CesiumServiceSettings() { + const [service, setService] = useState(""); + const [pending, setPending] = useState<"verify" | "save" | "remove" | null>(null); + const [settings, setSettings] = useState(null); + const [mode, setMode] = useState("auto"); + const [egress, setEgress] = useState(""); + const [servers, setServers] = useState([]); + const [routesError, setRoutesError] = useState(""); + const [token, setToken] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(""); + const [checking, setChecking] = useState(false); + const [checkError, setCheckError] = useState(""); + const [showVerification, setShowVerification] = useState(false); + const [verification, setVerification] = useState(null); + useEffect(() => { + let active = true; + void readCesiumService().then(value => {if (active) {setSettings(value); setMode(value.mode); setEgress(value.egress_id || "");}}) + .catch(reason => {if (active) setError(reason.message);}); + void serverRequest<{items:Server[]}>("").then(value => {if(active) setServers(value.items);}) + .catch(reason => {if(active) setRoutesError(reason.message);}); + return () => {active = false;}; + }, []); + useEffect(() => { + let active = true; + setVerification(null); setCheckError(""); setShowVerification(false); + if (service !== "cesium" || !settings?.token_configured || token.trim() || egress !== (settings.egress_id || "")) {setChecking(false); return;} + setChecking(true); + void verifyCesiumService().then(value => {if (active) setVerification(value);}) + .catch(reason => {if (active) setCheckError(reason instanceof Error ? reason.message : cesiumServiceMessage());}) + .finally(() => {if (active) setChecking(false);}); + return () => {active = false;}; + }, [service, settings?.revision, settings?.token_configured, token, egress]); + const indicator = cesiumTokenIndicator({configured: !!settings?.token_configured, draft: !!token.trim(), + checking: checking || pending === "verify" || pending === "save", error: error || checkError, verification}); + async function action(kind: "verify" | "save" | "remove") { + if (!settings || busy) return; + setBusy(true); setPending(kind); setError(""); setCheckError(""); setVerification(null); setShowVerification(kind === "verify"); + try { + if (kind === "verify") setVerification(await verifyCesiumService(token.trim() || undefined, egress)); + else { + const result = await saveCesiumService({revision: settings.revision, mode, egress_id: egress, + ...(kind === "remove" ? {remove_token: true} : token.trim() ? {token: token.trim()} : {})}); + setSettings(result); setToken(""); + } + } catch (reason) {setError(reason instanceof Error ? reason.message : cesiumServiceMessage());} + finally {setBusy(false); setPending(null);} + } + return + void action("verify")}> + void action("save")}> + {settings?.token_configured && void action("remove")}>} + }> + setMode(value as CesiumRouteMode)} + options={[{value: "auto", label: "Автоматически"}, {value: "direct", label: "Напрямую к источнику"}, + {value: "gateway", label: "Сервер хранения локальных данных"}]}/> + {mode === "auto" ? "Карты используют сервер хранения локальных данных. Если сервер недоступен, подключение переключается на источник через интернет." : + mode === "direct" ? "Карты загружаются через интернет без сохранения тайлов на этом компьютере." : "Карты загружаются только через сервер хранения локальных данных. Если сервер недоступен, загрузка приостанавливается."} + setSettings(v=>({...v,mode:mode as RoverMode}))}/> - presentation.update(v=>({...v,model}))}/> {duty?setSettings(v=>({...v,throttlePercent:roverNumberInput(e.target.value)}))}/>: setSettings(v=>({...v,maxErpm:roverNumberInput(e.target.value)}))}/>} setSettings(v=>({...v,currentA:roverNumberInput(e.target.value)}))}/> diff --git a/apps/control-station/src/components/system/ServerServiceSetup.tsx b/apps/control-station/src/components/system/ServerServiceSetup.tsx index afb45ae0..1d9d1d85 100644 --- a/apps/control-station/src/components/system/ServerServiceSetup.tsx +++ b/apps/control-station/src/components/system/ServerServiceSetup.tsx @@ -5,10 +5,10 @@ import {serverRequest,useServers,type Server} from '../../core/system/servers'; import {vpsRequest} from '../../core/fleet/vps'; export function ServerServiceSetup({server:initialServer,fixedKind,onClose,onSaved}:{server?:Server;fixedKind?:'librespeed';onClose:()=>void;onSaved:()=>void}) { - const [kind,setKind]=useState<'wireguard'|'arnavi'|'librespeed'>(fixedKind??'wireguard'),[document,setDocument]=useState(''),[filename,setFilename]=useState(''); + const [kind,setKind]=useState<'wireguard'|'arnavi'|'librespeed'|'egress'>(fixedKind??'wireguard'),[document,setDocument]=useState(''),[filename,setFilename]=useState(''); const catalog=useServers();const [serverId,setServerId]=useState(initialServer?.id??''); const server=initialServer??catalog.items?.find(s=>s.id===serverId); - const serviceName=kind==='librespeed'?'LibreSpeed':'WireGuard'; + const serviceName=kind==='egress'?'Маршрутизация трафика':kind==='librespeed'?'LibreSpeed':'WireGuard'; const [network,setNetwork]=useState(''),[interfaces,setInterfaces]=useState<{id:string;label:string}[]>([]); const [busy,setBusy]=useState(false),[error,setError]=useState('');const file=useRef(null); useEffect(()=>{let active=true;void vpsRequest<{items:{id:string;label:string}[]}>('/interfaces').then(r=>{if(active)setInterfaces(r.items);}).catch(()=>{});return()=>{active=false;};},[]); @@ -22,14 +22,14 @@ export function ServerServiceSetup({server:initialServer,fixedKind,onClose,onSav {!initialServer&&{setKind(value as typeof kind);setDocument('');setFilename('');setError('');}}/> - + {const chosen=event.target.files?.[0];event.target.value='';if(!chosen)return;setDocument('');setFilename('');void (async()=>{if(chosen.size>16384)throw Error(`Выберите файл приглашения ${serviceName} (до 16 КБ).`);setDocument(await chosen.text());setFilename(chosen.name);})().catch(e=>setError(e.message));}}/> {filename&&{filename}} - Файл на VPS: {kind==='librespeed'?'/var/lib/ndc-librespeed-vps/mission-core-librespeed.json':'/var/lib/ndc-wireguard-vps/mission-core-wireguard.json'}. Скопируйте его по защищённому соединению (например, SFTP). Приглашение действует 24 часа; новое выпускается командой connection того же установщика. {kind==='wireguard'?'Экспорт .conf из клиента WireGuard не подходит.':''} + Файл на VPS: {kind==='egress'?'/var/lib/ndc-egress-vps/mission-core-egress.json':kind==='librespeed'?'/var/lib/ndc-librespeed-vps/mission-core-librespeed.json':'/var/lib/ndc-wireguard-vps/mission-core-wireguard.json'}. Скопируйте его по защищённому соединению (например, SFTP). Приглашение действует 24 часа; новое выпускается командой connection того же установщика. {kind==='wireguard'?'Экспорт .conf из клиента WireGuard не подходит.':''} :setDocument(e.target.value)} hint="Ключ находится на VPS в /opt/nodedc-mission-vps/connect.key. Действует 24 часа и используется один раз."/>} {interfaces.length>0&&