Compare commits

...
1 Commits
Author SHA1 Message Date
SerinaNya f38d640ac4 feat(settings): use webListen URI format for Web API address
- rename webPort field/label to webListen (Web API 监听地址)
- seed initial form state from webListen with legacy webPort fallback
- save webListen URI string while deriving legacy webPort integer for
  backend compatibility
2026-08-26 19:42:20 +08:00
2 changed files with 21 additions and 9 deletions
+20 -9
View File
@@ -151,6 +151,9 @@ function SettingsForm({
...initialConfig, ...initialConfig,
TCPListen: toAddrString(initialConfig.TCPListen), TCPListen: toAddrString(initialConfig.TCPListen),
UDPListen: toAddrString(initialConfig.UDPListen), UDPListen: toAddrString(initialConfig.UDPListen),
webListen:
initialConfig.webListen ??
(initialConfig.webPort ? `http://0.0.0.0:${initialConfig.webPort}` : 'http://0.0.0.0:4665'),
})) }))
const [tunEnabled, setTunEnabled] = useState<boolean>(() => const [tunEnabled, setTunEnabled] = useState<boolean>(() =>
initialConfig.enableTUN ?? initialConfig.enableTUN ??
@@ -209,9 +212,19 @@ function SettingsForm({
form.denyConnectionBroadcast ?? form.denyConnectionBroadcast ??
form.denyLineTableBroadcast ?? form.denyLineTableBroadcast ??
false false
const webListen = form.webListen?.trim() || 'http://0.0.0.0:4665'
let webPort = 4665
try {
const parsedPort = new URL(webListen).port
if (parsedPort) webPort = parseInt(parsedPort, 10)
} catch {
// Java backend validates the canonical listen address.
}
const updatedConfig: Record<string, unknown> = { const updatedConfig: Record<string, unknown> = {
...form, ...form,
webListen,
webPort,
externalEndpoints: updatedExternalEndpoints, externalEndpoints: updatedExternalEndpoints,
openConnections: updatedExternalEndpoints, openConnections: updatedExternalEndpoints,
autoConnections: updatedAutoConnections, autoConnections: updatedAutoConnections,
@@ -485,23 +498,21 @@ function SettingsForm({
)} )}
<Field> <Field>
<FieldLabel htmlFor="webPort">Web </FieldLabel> <FieldLabel htmlFor="webListen">Web API </FieldLabel>
<Input <Input
id="webPort" id="webListen"
type="number" type="text"
min={1} placeholder="http://0.0.0.0:4665"
max={65535} value={form.webListen ?? 'http://0.0.0.0:4665'}
placeholder="4665"
value={form.webPort ?? 4665}
onChange={(e) => onChange={(e) =>
setForm((prev) => ({ setForm((prev) => ({
...prev, ...prev,
webPort: parseInt(e.target.value) || 4665, webListen: e.target.value,
})) }))
} }
/> />
<FieldDescription> <FieldDescription>
Web API 4665 Web API http://0.0.0.0:4665
</FieldDescription> </FieldDescription>
</Field> </Field>
+1
View File
@@ -109,6 +109,7 @@ export interface KLALBControllerConfig {
enableTUN?: boolean enableTUN?: boolean
TUNName?: string | null TUNName?: string | null
webUI?: boolean webUI?: boolean
webListen?: string
webPort?: number webPort?: number
nogui?: boolean nogui?: boolean
TCPListen?: string TCPListen?: string