mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-17 00:31:00 +00:00
c93beef267
Clearing the Rewrite port field makes AntD InputNumber write null into the form store. The tunnel schema declared rewritePort as PortSchema.optional(), which accepts undefined but not null, so saving (or the JSON tab reflecting null) failed validation with "settings.rewritePort — Invalid input". Accept null and collapse it to undefined so the field is simply omitted from the serialized payload, matching the behavior of deleting the key by hand. The trailing .optional() keeps the key optional in the inferred type. Closes #5516
25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
import { PortSchema } from '@/schemas/primitives';
|
|
|
|
export const TunnelNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
|
|
export type TunnelNetwork = z.infer<typeof TunnelNetworkSchema>;
|
|
|
|
// Tunnel inbound (Xray's `dokodemo-door`-style transparent forwarder).
|
|
// `portMap` is persisted as Record<string, string> on the wire — the panel
|
|
// flattens an internal array-of-{name,value} into that map via toV2Headers
|
|
// with arr=false.
|
|
export const TunnelInboundSettingsSchema = z.object({
|
|
rewriteAddress: z.string().optional(),
|
|
// AntD InputNumber writes null when cleared; accept it and collapse to
|
|
// undefined so the field is omitted from the payload instead of crashing
|
|
// validation with "Invalid input" (issue #5516). The trailing .optional()
|
|
// keeps the key optional in the inferred type (a bare .transform() would
|
|
// make it required).
|
|
rewritePort: PortSchema.nullable().transform((v) => v ?? undefined).optional(),
|
|
portMap: z.record(z.string(), z.string()).default({}),
|
|
allowedNetwork: TunnelNetworkSchema.default('tcp,udp'),
|
|
followRedirect: z.boolean().default(false),
|
|
});
|
|
export type TunnelInboundSettings = z.infer<typeof TunnelInboundSettingsSchema>;
|