From 02043a432da33f0b4c649491a835aa7bf778af62 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 2 Jun 2026 13:57:02 +0200 Subject: [PATCH] fix(node): fix "invalid input" on save and gate save on connectivity The pinnedCertSha256 form field unmounts for non-pin TLS modes, so antd dropped it from the onFinish values and Zod rejected the missing string (the user-facing "invalid input"). Make it optional with a default so saving works in every TLS mode. Saving now runs the connection test first and only persists when the probe is online; the add/update endpoints enforce the same probe so an unreachable node cannot be stored via the API either. Selecting the http scheme forces TLS verify mode to skip and disables the control, normalized on open for existing http nodes. http-vs-https probe failures report a clear "set the node scheme to http" message across the test button, save, and the backend gate. Closes #4794 --- frontend/src/pages/nodes/NodeFormModal.tsx | 16 +++++++++++++++- frontend/src/schemas/node.ts | 2 +- web/controller/node.go | 18 ++++++++++++++++++ web/service/node.go | 9 ++++++++- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/nodes/NodeFormModal.tsx b/frontend/src/pages/nodes/NodeFormModal.tsx index 0d4f3f53..985e80d3 100644 --- a/frontend/src/pages/nodes/NodeFormModal.tsx +++ b/frontend/src/pages/nodes/NodeFormModal.tsx @@ -65,6 +65,7 @@ export default function NodeFormModal({ const [testing, setTesting] = useState(false); const [fetchingPin, setFetchingPin] = useState(false); const [testResult, setTestResult] = useState(null); + const scheme = Form.useWatch('scheme', form) ?? 'https'; const tlsVerifyMode = Form.useWatch('tlsVerifyMode', form) ?? 'verify'; useEffect(() => { @@ -78,6 +79,7 @@ export default function NodeFormModal({ scheme: (node.scheme as 'http' | 'https') || base.scheme, } : base; + if (next.scheme === 'http') next.tlsVerifyMode = 'skip'; form.resetFields(); form.setFieldsValue(next); setTestResult(null); @@ -155,7 +157,15 @@ export default function NodeFormModal({ } setSubmitting(true); try { - const msg = await save(buildPayload(result.data)); + const payload = buildPayload(result.data); + const test = await testConnection(payload); + const probe = test?.success ? test.obj : null; + if (!probe || probe.status !== 'online') { + setTestResult(probe ?? { status: 'offline', error: test?.msg || t('pages.nodes.connectionFailed') }); + return; + } + setTestResult(probe); + const msg = await save(payload); if (msg?.success) { onOpenChange(false); } @@ -213,6 +223,9 @@ export default function NodeFormModal({ { value: 'https', label: 'https' }, { value: 'http', label: 'http' }, ]} + onChange={(value) => { + if (value === 'http') form.setFieldValue('tlsVerifyMode', 'skip'); + }} /> @@ -268,6 +281,7 @@ export default function NodeFormModal({ extra={t('pages.nodes.tlsVerifyModeHint')} >