From e83bc6085e04f01f4688ab08a54d72d67b8b925c Mon Sep 17 00:00:00 2001 From: Loren Eteval Date: Sun, 28 Apr 2024 20:10:01 +0800 Subject: [PATCH] Update Utility.py Signed-off-by: Loren Eteval --- Furious/Utility/Utility.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Furious/Utility/Utility.py b/Furious/Utility/Utility.py index 6d4b221..0930bea 100644 --- a/Furious/Utility/Utility.py +++ b/Furious/Utility/Utility.py @@ -36,6 +36,8 @@ __all__ = [ 'parseHostPort', 'runExternalCommand', 'getAbsolutePath', + 'getXrayProxyOutboundObject', + 'getXrayProxyOutboundStream', ] @@ -57,6 +59,9 @@ class BinarySettings: @functools.lru_cache(None) def protocolRepr(protocol: str) -> str: + if not isinstance(protocol, str): + return '' + if protocol.lower() == 'vmess': return Protocol.VMess @@ -105,3 +110,26 @@ def runExternalCommand(*args, **kwargs): def getAbsolutePath(path): return path if os.path.isabs(path) else str(ROOT_DIR / path) + + +def getXrayProxyOutboundObject(config: dict) -> dict: + if not isinstance(config.get('outbounds'), list): + config['outbounds'] = [] + + for outbound in config['outbounds']: + if isinstance(outbound, dict): + tag = outbound.get('tag') + + if isinstance(tag, str) and tag == 'proxy': + return outbound + + return {} + + +def getXrayProxyOutboundStream(config: dict) -> dict: + proxyOutboundObject = getXrayProxyOutboundObject(config) + + if not isinstance(proxyOutboundObject.get('streamSettings'), dict): + proxyOutboundObject['streamSettings'] = {} + + return proxyOutboundObject['streamSettings']