mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-08-29 14:37:13 +00:00
feat(xray): default outbound in basic routing (#5815)
* feat(xray): default outbound picker in basic routing Let panel users choose which outbound handles unmatched traffic by moving it to the first position in the template outbounds list. * fix(xray): keep direct/blocked outbounds when changing default * style(routing): revert incidental whitespace churn Drop double blank lines and the reformatted function signature so the default-outbound diff stays focused on behavior.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { XraySettingsValue } from '@/hooks/useXraySetting';
|
||||
import { blockedSettings, directSettings } from './constants';
|
||||
|
||||
export function ruleGetter(t: XraySettingsValue | null, outboundTag: string, property: string): string[] {
|
||||
if (!t?.routing?.rules) return [];
|
||||
@@ -55,6 +56,28 @@ export function syncOutbound(t: XraySettingsValue, tag: string, settings: Record
|
||||
if (haveRules && idx < 0) t.outbounds.push(settings as never);
|
||||
}
|
||||
|
||||
export function getDefaultOutboundTag(t: XraySettingsValue | null): string {
|
||||
const tag = t?.outbounds?.[0]?.tag;
|
||||
return typeof tag === 'string' && tag.length > 0 ? tag : 'direct';
|
||||
}
|
||||
|
||||
export function setDefaultOutboundTag(t: XraySettingsValue, tag: string): void {
|
||||
if (!tag) return;
|
||||
if (!Array.isArray(t.outbounds)) t.outbounds = [];
|
||||
const idx = t.outbounds.findIndex((o) => o?.tag === tag);
|
||||
if (idx < 0) {
|
||||
if (tag === 'direct') t.outbounds.push(directSettings as never);
|
||||
else if (tag === 'blocked') t.outbounds.push(blockedSettings as never);
|
||||
else return;
|
||||
const newIdx = t.outbounds.length - 1;
|
||||
const [moved] = t.outbounds.splice(newIdx, 1);
|
||||
t.outbounds.unshift(moved);
|
||||
} else if (idx > 0) {
|
||||
const [moved] = t.outbounds.splice(idx, 1);
|
||||
t.outbounds.unshift(moved);
|
||||
}
|
||||
}
|
||||
|
||||
export function propagateOutboundTagRename(
|
||||
t: XraySettingsValue,
|
||||
oldTag: string,
|
||||
|
||||
Reference in New Issue
Block a user