From bf785b763f89d191e48d72a7fcda172b843fb108 Mon Sep 17 00:00:00 2001 From: HotelSync Date: Fri, 27 Mar 2026 21:06:33 +0300 Subject: [PATCH] fix: hide NetUP server URL field in agent mode, derive from device config - TvWelcomePage: hide server URL input when connection_type=agent - Test button enabled in agent mode without serverUrl - Backend test endpoint: derive server_url from workstation netup device - getNetupCfg: resolve URL from netup device in agent mode Co-Authored-By: Claude Sonnet 4.6 --- backend/src/routes/netup.ts | 32 ++++++++++++++++++++++++++++++-- src/pages/TvWelcomePage.tsx | 30 +++++++++++++++--------------- 2 files changed, 45 insertions(+), 17 deletions(-) diff --git a/backend/src/routes/netup.ts b/backend/src/routes/netup.ts index 42aa31c..e369853 100644 --- a/backend/src/routes/netup.ts +++ b/backend/src/routes/netup.ts @@ -188,10 +188,24 @@ const netup: FastifyPluginAsync = async (fastify) => { [hotelId], ) const cfg = rows[0] - if (!cfg?.server_url) return reply.code(400).send({ error: 'Настройки не заполнены' }) + + // В agent-режиме берём адрес из устройства netup на рабочем месте + let effectiveUrl = cfg?.server_url ?? '' + if (cfg?.connection_type === 'agent' && cfg?.agent_workstation_id) { + const { rows: [dev] } = await db.query( + `SELECT network_host, network_port FROM workstation_devices + WHERE workstation_id = $1 AND type = 'netup' ORDER BY id LIMIT 1`, + [cfg.agent_workstation_id], + ) + if (dev?.network_host) { + effectiveUrl = `http://${dev.network_host}:${dev.network_port ?? 80}` + } + } + + if (!effectiveUrl) return reply.code(400).send({ error: 'Настройки не заполнены' }) try { - const result = await netupReq(cfg, 'GET', '/hotel-room') + const result = await netupReq({ ...cfg, server_url: effectiveUrl }, 'GET', '/hotel-room') if (result.ok) return { ok: true, message: 'Подключение успешно' } return reply.code(502).send({ error: `NetUP вернул статус ${result.status}` }) } catch (err) { @@ -433,6 +447,20 @@ async function getNetupCfg(hotelId: string, needEnabled = true) { `SELECT server_url, username, password, default_language, connection_type, agent_workstation_id FROM netup_settings WHERE hotel_id = $1 ${cond}`, [hotelId], ) + if (!cfg) return undefined + + // В agent-режиме подставляем адрес из устройства netup на рабочем месте + if (cfg.connection_type === 'agent' && cfg.agent_workstation_id) { + const { rows: [dev] } = await db.query( + `SELECT network_host, network_port FROM workstation_devices + WHERE workstation_id = $1 AND type = 'netup' ORDER BY id LIMIT 1`, + [cfg.agent_workstation_id], + ).catch(() => ({ rows: [] })) + if (dev?.network_host) { + cfg.server_url = `http://${dev.network_host}:${dev.network_port ?? 80}` + } + } + return cfg as { server_url: string; username: string; password: string; default_language: string; connection_type: string; agent_workstation_id: string | null } | undefined } diff --git a/src/pages/TvWelcomePage.tsx b/src/pages/TvWelcomePage.tsx index 3752a75..a01c984 100644 --- a/src/pages/TvWelcomePage.tsx +++ b/src/pages/TvWelcomePage.tsx @@ -290,20 +290,20 @@ export function TvWelcomePage() {
- {/* Server URL */} -
- - setServerUrl(e.target.value)} - placeholder={connectionType === 'agent' ? 'http://172.16.0.12:8880' : 'http://192.168.1.100:8880'} - className="input w-full font-mono text-sm" - /> -

- {connectionType === 'agent' - ? 'Локальный адрес NetUP в сети отеля (агент обращается к нему напрямую)' - : 'Внешний адрес и порт, на который пробрасывается 172.16.0.12:80'} -

-
+ {/* Server URL — только для прямого подключения */} + {connectionType !== 'agent' && ( +
+ + setServerUrl(e.target.value)} + placeholder="http://192.168.1.100:8880" + className="input w-full font-mono text-sm" + /> +

+ Внешний адрес и порт, на который пробрасывается 172.16.0.12:80 +

+
+ )} {/* Credentials */}
@@ -356,7 +356,7 @@ export function TvWelcomePage() { {/* Actions */}
-