mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-06 21:24:10 +00:00
refactor(frontend): move shared protocol enums to schemas/protocols/shared
Decouple Outbound from Inbound schemas: SSMethodSchema and VmessSecuritySchema (shared between inbound & outbound) now live in a neutral schemas/protocols/shared/ module. Outbound no longer reaches into schemas/protocols/inbound/*. Pure relocation + import rewiring; schema values identical, snapshots & golden tests unchanged.
This commit is contained in:
parent
06d0ae947d
commit
1645664f03
11 changed files with 42 additions and 34 deletions
|
|
@ -2,7 +2,7 @@ import { Base64, Wireguard } from '@/utils';
|
||||||
|
|
||||||
import type { Inbound } from '@/schemas/api/inbound';
|
import type { Inbound } from '@/schemas/api/inbound';
|
||||||
import type { VlessClient } from '@/schemas/protocols/inbound/vless';
|
import type { VlessClient } from '@/schemas/protocols/inbound/vless';
|
||||||
import type { VmessSecurity } from '@/schemas/protocols/inbound/vmess';
|
import type { VmessSecurity } from '@/schemas/protocols/shared/vmess';
|
||||||
import type {
|
import type {
|
||||||
WireguardInboundPeer,
|
WireguardInboundPeer,
|
||||||
WireguardInboundSettings,
|
WireguardInboundSettings,
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ import {
|
||||||
canEnableTls,
|
canEnableTls,
|
||||||
isSS2022,
|
isSS2022,
|
||||||
} from '@/lib/xray/protocol-capabilities';
|
} from '@/lib/xray/protocol-capabilities';
|
||||||
import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
|
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
||||||
import { getRandomRealityTarget } from '@/models/reality-targets';
|
import { getRandomRealityTarget } from '@/models/reality-targets';
|
||||||
import {
|
import {
|
||||||
InboundFormBaseSchema,
|
InboundFormBaseSchema,
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ import {
|
||||||
canEnableTls,
|
canEnableTls,
|
||||||
canEnableTlsFlow,
|
canEnableTlsFlow,
|
||||||
} from '@/lib/xray/protocol-capabilities';
|
} from '@/lib/xray/protocol-capabilities';
|
||||||
import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
|
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
||||||
import { antdRule } from '@/utils/zodForm';
|
import { antdRule } from '@/utils/zodForm';
|
||||||
import './OutboundFormModal.css';
|
import './OutboundFormModal.css';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { PortSchema } from '@/schemas/primitives';
|
import { PortSchema } from '@/schemas/primitives';
|
||||||
import { VmessSecuritySchema } from '@/schemas/protocols/inbound/vmess';
|
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
||||||
import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
|
import { VmessSecuritySchema } from '@/schemas/protocols/shared/vmess';
|
||||||
import { SecuritySettingsSchema } from '@/schemas/protocols/security';
|
import { SecuritySettingsSchema } from '@/schemas/protocols/security';
|
||||||
import { NetworkSettingsSchema, StreamExtrasSchema } from '@/schemas/protocols/stream';
|
import { NetworkSettingsSchema, StreamExtrasSchema } from '@/schemas/protocols/stream';
|
||||||
import {
|
import {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,6 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const SSMethodSchema = z.enum([
|
import { SSMethodSchema } from '../shared/shadowsocks';
|
||||||
'aes-256-gcm',
|
|
||||||
'chacha20-poly1305',
|
|
||||||
'chacha20-ietf-poly1305',
|
|
||||||
'xchacha20-ietf-poly1305',
|
|
||||||
'2022-blake3-aes-128-gcm',
|
|
||||||
'2022-blake3-aes-256-gcm',
|
|
||||||
'2022-blake3-chacha20-poly1305',
|
|
||||||
]);
|
|
||||||
export type SSMethod = z.infer<typeof SSMethodSchema>;
|
|
||||||
|
|
||||||
export const SSNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
|
export const SSNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
|
||||||
export type SSNetwork = z.infer<typeof SSNetworkSchema>;
|
export type SSNetwork = z.infer<typeof SSNetworkSchema>;
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,6 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const VmessSecurityEnum = z.enum([
|
import { VmessSecuritySchema } from '../shared/vmess';
|
||||||
'aes-128-gcm',
|
|
||||||
'chacha20-poly1305',
|
|
||||||
'auto',
|
|
||||||
'none',
|
|
||||||
'zero',
|
|
||||||
]);
|
|
||||||
|
|
||||||
// Legacy rows persisted `security: ""` (especially on VMess inbounds
|
|
||||||
// created before the enum was nailed down). Preprocess maps the empty
|
|
||||||
// string back to the documented default so existing data parses cleanly
|
|
||||||
// — subsequent writes serialize the normalized value.
|
|
||||||
export const VmessSecuritySchema = z.preprocess(
|
|
||||||
(val) => (val === '' ? 'auto' : val),
|
|
||||||
VmessSecurityEnum,
|
|
||||||
);
|
|
||||||
export type VmessSecurity = z.infer<typeof VmessSecurityEnum>;
|
|
||||||
|
|
||||||
export const VmessClientSchema = z.object({
|
export const VmessClientSchema = z.object({
|
||||||
id: z.uuid(),
|
id: z.uuid(),
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { PortSchema } from '@/schemas/primitives';
|
import { PortSchema } from '@/schemas/primitives';
|
||||||
import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
|
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
|
||||||
|
|
||||||
// Shadowsocks outbound persists as { servers: [{ ... }] }, with UDP-over-TCP
|
// Shadowsocks outbound persists as { servers: [{ ... }] }, with UDP-over-TCP
|
||||||
// knobs (uot, UoTVersion) attached per-server when the user enabled them.
|
// knobs (uot, UoTVersion) attached per-server when the user enabled them.
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
import { PortSchema } from '@/schemas/primitives';
|
import { PortSchema } from '@/schemas/primitives';
|
||||||
import { VmessSecuritySchema } from '@/schemas/protocols/inbound/vmess';
|
import { VmessSecuritySchema } from '@/schemas/protocols/shared/vmess';
|
||||||
|
|
||||||
// Vmess outbound persists in the standard Xray `vnext` shape:
|
// Vmess outbound persists in the standard Xray `vnext` shape:
|
||||||
// { vnext: [{ address, port, users: [{ id, security }] }] }
|
// { vnext: [{ address, port, users: [{ id, security }] }] }
|
||||||
|
|
|
||||||
2
frontend/src/schemas/protocols/shared/index.ts
Normal file
2
frontend/src/schemas/protocols/shared/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
export * from './shadowsocks';
|
||||||
|
export * from './vmess';
|
||||||
12
frontend/src/schemas/protocols/shared/shadowsocks.ts
Normal file
12
frontend/src/schemas/protocols/shared/shadowsocks.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export const SSMethodSchema = z.enum([
|
||||||
|
'aes-256-gcm',
|
||||||
|
'chacha20-poly1305',
|
||||||
|
'chacha20-ietf-poly1305',
|
||||||
|
'xchacha20-ietf-poly1305',
|
||||||
|
'2022-blake3-aes-128-gcm',
|
||||||
|
'2022-blake3-aes-256-gcm',
|
||||||
|
'2022-blake3-chacha20-poly1305',
|
||||||
|
]);
|
||||||
|
export type SSMethod = z.infer<typeof SSMethodSchema>;
|
||||||
19
frontend/src/schemas/protocols/shared/vmess.ts
Normal file
19
frontend/src/schemas/protocols/shared/vmess.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
const VmessSecurityEnum = z.enum([
|
||||||
|
'aes-128-gcm',
|
||||||
|
'chacha20-poly1305',
|
||||||
|
'auto',
|
||||||
|
'none',
|
||||||
|
'zero',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Legacy rows persisted `security: ""` (especially on VMess inbounds
|
||||||
|
// created before the enum was nailed down). Preprocess maps the empty
|
||||||
|
// string back to the documented default so existing data parses cleanly
|
||||||
|
// — subsequent writes serialize the normalized value.
|
||||||
|
export const VmessSecuritySchema = z.preprocess(
|
||||||
|
(val) => (val === '' ? 'auto' : val),
|
||||||
|
VmessSecurityEnum,
|
||||||
|
);
|
||||||
|
export type VmessSecurity = z.infer<typeof VmessSecurityEnum>;
|
||||||
Loading…
Reference in a new issue