From 40ca58d42ede6b27841a31e84f424d56c02835c3 Mon Sep 17 00:00:00 2001 From: MHSanaei Date: Tue, 26 May 2026 01:07:02 +0200 Subject: [PATCH] refactor(frontend): lift OutboundProtocols + OutboundDomainStrategies to schemas/primitives MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves the two outbound-side consts out of models/outbound.ts and into schemas/primitives/outbound-protocol.ts. Renames the export to OutboundProtocols to disambiguate from the inbound Protocols const (different key casing — PascalCase vs ALL CAPS — and partly different member set, so they cannot share a single const). OutboundsTab.tsx keeps its 15+ Protocols.X call sites by aliasing the import. FinalMaskForm.tsx and BasicsTab.tsx swap directly. Drops a stale `as string[]` cast in BasicsTab that no longer fits the new readonly-tuple typing. After this commit only the two big form modals (InboundFormModal/OutboundFormModal) plus three intentional parity tests still import from @/models/. --- frontend/src/components/FinalMaskForm.tsx | 4 +-- frontend/src/pages/xray/BasicsTab.tsx | 4 +-- frontend/src/pages/xray/OutboundsTab.tsx | 2 +- frontend/src/schemas/primitives/index.ts | 1 + .../schemas/primitives/outbound-protocol.ts | 30 +++++++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 frontend/src/schemas/primitives/outbound-protocol.ts diff --git a/frontend/src/components/FinalMaskForm.tsx b/frontend/src/components/FinalMaskForm.tsx index b66709da..961a2c22 100644 --- a/frontend/src/components/FinalMaskForm.tsx +++ b/frontend/src/components/FinalMaskForm.tsx @@ -3,7 +3,7 @@ import { Button, Divider, Form, Input, InputNumber, Select, Switch } from 'antd' import { DeleteOutlined, PlusOutlined, ReloadOutlined } from '@ant-design/icons'; import { RandomUtil } from '@/utils'; -import { Protocols } from '@/models/outbound'; +import { OutboundProtocols } from '@/schemas/primitives'; interface StreamShape { network?: string; @@ -84,7 +84,7 @@ function newNoiseItem(): ItemRow { } export default function FinalMaskForm({ stream, protocol, onChange }: FinalMaskFormProps) { - const isHysteria = protocol === Protocols.Hysteria || protocol === 'hysteria'; + const isHysteria = protocol === OutboundProtocols.Hysteria || protocol === 'hysteria'; const network = stream?.network || ''; const showTcp = useMemo( diff --git a/frontend/src/pages/xray/BasicsTab.tsx b/frontend/src/pages/xray/BasicsTab.tsx index b13d2f21..c9a6a648 100644 --- a/frontend/src/pages/xray/BasicsTab.tsx +++ b/frontend/src/pages/xray/BasicsTab.tsx @@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'; import { Alert, Button, Collapse, Input, Modal, Select, Space, Switch } from 'antd'; import { CloudOutlined, ApiOutlined } from '@ant-design/icons'; -import { OutboundDomainStrategies } from '@/models/outbound'; +import { OutboundDomainStrategies } from '@/schemas/primitives'; import SettingListItem from '@/components/SettingListItem'; import type { XraySettingsValue, SetTemplate } from '@/hooks/useXraySetting'; import './BasicsTab.css'; @@ -217,7 +217,7 @@ export default function BasicsTab({