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 <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -290,20 +290,20 @@ export function TvWelcomePage() {
|
||||
|
||||
<hr className="border-slate-100 dark:border-slate-700" />
|
||||
|
||||
{/* Server URL */}
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium text-slate-700 dark:text-slate-300">Адрес сервера NetUP</label>
|
||||
<input
|
||||
type="text" value={serverUrl} onChange={e => 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"
|
||||
/>
|
||||
<p className="text-xs text-slate-400 dark:text-slate-500">
|
||||
{connectionType === 'agent'
|
||||
? 'Локальный адрес NetUP в сети отеля (агент обращается к нему напрямую)'
|
||||
: 'Внешний адрес и порт, на который пробрасывается 172.16.0.12:80'}
|
||||
</p>
|
||||
</div>
|
||||
{/* Server URL — только для прямого подключения */}
|
||||
{connectionType !== 'agent' && (
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium text-slate-700 dark:text-slate-300">Адрес сервера NetUP</label>
|
||||
<input
|
||||
type="text" value={serverUrl} onChange={e => setServerUrl(e.target.value)}
|
||||
placeholder="http://192.168.1.100:8880"
|
||||
className="input w-full font-mono text-sm"
|
||||
/>
|
||||
<p className="text-xs text-slate-400 dark:text-slate-500">
|
||||
Внешний адрес и порт, на который пробрасывается 172.16.0.12:80
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Credentials */}
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
@@ -356,7 +356,7 @@ export function TvWelcomePage() {
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex gap-3 pt-1">
|
||||
<button onClick={handleTest} disabled={testing || !serverUrl} className="btn-secondary flex items-center gap-2">
|
||||
<button onClick={handleTest} disabled={testing || (connectionType !== 'agent' && !serverUrl)} className="btn-secondary flex items-center gap-2">
|
||||
{testing ? <Loader2 size={14} className="animate-spin" /> : <Plug size={14} />}
|
||||
Проверить подключение
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user