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:
MHSanaei 2026-05-30 15:17:16 +02:00
parent 06d0ae947d
commit 1645664f03
No known key found for this signature in database
GPG key ID: 7E4060F2FBE5AB7A
11 changed files with 42 additions and 34 deletions

View file

@ -2,7 +2,7 @@ import { Base64, Wireguard } from '@/utils';
import type { Inbound } from '@/schemas/api/inbound';
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 {
WireguardInboundPeer,
WireguardInboundSettings,

View file

@ -45,7 +45,7 @@ import {
canEnableTls,
isSS2022,
} 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 {
InboundFormBaseSchema,

View file

@ -60,7 +60,7 @@ import {
canEnableTls,
canEnableTlsFlow,
} 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 './OutboundFormModal.css';

View file

@ -1,8 +1,8 @@
import { z } from 'zod';
import { PortSchema } from '@/schemas/primitives';
import { VmessSecuritySchema } from '@/schemas/protocols/inbound/vmess';
import { SSMethodSchema } from '@/schemas/protocols/inbound/shadowsocks';
import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
import { VmessSecuritySchema } from '@/schemas/protocols/shared/vmess';
import { SecuritySettingsSchema } from '@/schemas/protocols/security';
import { NetworkSettingsSchema, StreamExtrasSchema } from '@/schemas/protocols/stream';
import {

View file

@ -1,15 +1,6 @@
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>;
import { SSMethodSchema } from '../shared/shadowsocks';
export const SSNetworkSchema = z.enum(['tcp', 'udp', 'tcp,udp']);
export type SSNetwork = z.infer<typeof SSNetworkSchema>;

View file

@ -1,22 +1,6 @@
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>;
import { VmessSecuritySchema } from '../shared/vmess';
export const VmessClientSchema = z.object({
id: z.uuid(),

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
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
// knobs (uot, UoTVersion) attached per-server when the user enabled them.

View file

@ -1,7 +1,7 @@
import { z } from 'zod';
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:
// { vnext: [{ address, port, users: [{ id, security }] }] }

View file

@ -0,0 +1,2 @@
export * from './shadowsocks';
export * from './vmess';

View 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>;

View 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>;