删掉出站模式的写方向
界面上做「出站模式三选一」的计划经讨论废弃:全局档等价于既有的专属组, 直连留在卡片里是即时动作,规则档的真实需求(内网豁免、按站点分流)属于 之后的附加规则功能。outboundToProxyField 自此确定没有调用方。读方向保留, 手写配置里的 DIRECT/GLOBAL 仍要认得和显示。
This commit is contained in:
+1
-16
@@ -8,7 +8,6 @@ import {
|
||||
fallbackTarget,
|
||||
isUnsetOutbound,
|
||||
outboundLabel,
|
||||
outboundToProxyField,
|
||||
OUTBOUND_PRESETS,
|
||||
resolveDestination,
|
||||
} from './inbounds.ts'
|
||||
@@ -92,12 +91,6 @@ describe('出站去向的四种形态', () => {
|
||||
expect(of('AUTO')).toEqual({ kind: 'named', name: 'AUTO' })
|
||||
})
|
||||
|
||||
it('写回时能还原成原来的字段值', () => {
|
||||
expect(outboundToProxyField({ kind: 'rules' })).toBeUndefined()
|
||||
expect(outboundToProxyField({ kind: 'direct' })).toBe('DIRECT')
|
||||
expect(outboundToProxyField({ kind: 'global' })).toBe('GLOBAL')
|
||||
expect(outboundToProxyField({ kind: 'named', name: 'AUTO' })).toBe('AUTO')
|
||||
})
|
||||
})
|
||||
|
||||
describe('能被入站引用的出站名字', () => {
|
||||
@@ -149,7 +142,7 @@ describe('流量最终去哪', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('出站预设表是读写显示三者的唯一约定', () => {
|
||||
describe('出站预设表是读取和显示的唯一约定', () => {
|
||||
it('每种预设的字段值和标签一一对应', () => {
|
||||
expect(OUTBOUND_PRESETS.map((p) => [p.mode.kind, p.field, p.label])).toEqual([
|
||||
['rules', undefined, 'RULE'],
|
||||
@@ -158,14 +151,6 @@ describe('出站预设表是读写显示三者的唯一约定', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('从配置读出来再写回去,值不变', () => {
|
||||
// 这条是防止「显示的」和「写进文件的」跑偏:任何一种模式转一圈都要回到原值
|
||||
for (const preset of OUTBOUND_PRESETS) {
|
||||
expect(outboundToProxyField(preset.mode)).toBe(preset.field)
|
||||
}
|
||||
expect(outboundToProxyField({ kind: 'named', name: 'AUTO' })).toBe('AUTO')
|
||||
})
|
||||
|
||||
it('界面上的名字用配置里的原词', () => {
|
||||
expect(outboundLabel({ kind: 'rules' })).toBe('RULE')
|
||||
expect(outboundLabel({ kind: 'direct' })).toBe('DIRECT')
|
||||
|
||||
+3
-10
@@ -60,11 +60,10 @@ export interface Inbound {
|
||||
/**
|
||||
* 不用指名道姓的那几种出站,以及它们各自对应配置里的什么值。
|
||||
*
|
||||
* 这张表是「读配置 → 界面 → 写回配置」三者的唯一约定来源。之前它被拆成四份散在
|
||||
* 各处(读一份、显示一份、写回一份、表单里又抄了一份),加一种出站模式就要同时改
|
||||
* 四个地方,漏一个就是「界面显示的」和「实际写进文件的」对不上。
|
||||
* 这张表是「读配置 → 界面显示」的唯一约定来源。Patchbay 自己不会写出这些值
|
||||
* (出站模式的写方向已随设计废弃),但手写配置里它们都可能出现,读和显示必须认得。
|
||||
*
|
||||
* `field` 为 undefined 表示配置里**不写** proxy 这个字段——「没有这个键」和
|
||||
* `field` 为 undefined 表示配置里**没写** proxy 这个字段——「没有这个键」和
|
||||
* 「这个键是空字符串」在 YAML 里是两回事。
|
||||
*/
|
||||
export const OUTBOUND_PRESETS: Array<{
|
||||
@@ -83,12 +82,6 @@ function outboundOf(proxy: unknown): OutboundMode {
|
||||
return preset ? preset.mode : { kind: 'named', name: proxy }
|
||||
}
|
||||
|
||||
/** 把出站去向写回成配置里 proxy 字段该有的值。返回 undefined 表示不写这个字段。 */
|
||||
export function outboundToProxyField(mode: OutboundMode): string | undefined {
|
||||
if (mode.kind === 'named') return mode.name
|
||||
return OUTBOUND_PRESETS.find((p) => p.mode.kind === mode.kind)?.field
|
||||
}
|
||||
|
||||
/** 出站在界面上的名字。指名道姓的就是它自己的名字,其余用配置里的原词。 */
|
||||
export function outboundLabel(mode: OutboundMode): string {
|
||||
if (mode.kind === 'named') return mode.name
|
||||
|
||||
Reference in New Issue
Block a user