From 56928a22c721d6b5ece0b7193c9397341fa2b17f Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Tue, 19 Mar 2024 10:39:19 +0100 Subject: [PATCH] [xray] fix: convert link to json #1107 --- web/assets/js/model/outbound.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/web/assets/js/model/outbound.js b/web/assets/js/model/outbound.js index 446b3865..e10b0d2c 100644 --- a/web/assets/js/model/outbound.js +++ b/web/assets/js/model/outbound.js @@ -659,20 +659,22 @@ class Outbound extends CommonClass { json.allowInsecure); } - return new Outbound(json.ps, Protocols.VMess, new Outbound.VmessSettings(json.add, json.port, json.id), stream); + const port = json.port * 1; + + return new Outbound(json.ps, Protocols.VMess, new Outbound.VmessSettings(json.add, port, json.id), stream); } static fromParamLink(link){ const url = new URL(link); - let type = url.searchParams.get('type'); + let type = url.searchParams.get('type') ?? 'tcp'; let security = url.searchParams.get('security') ?? 'none'; let stream = new StreamSettings(type, security); - let headerType = url.searchParams.get('headerType'); - let host = url.searchParams.get('host'); - let path = url.searchParams.get('path'); + let headerType = url.searchParams.get('headerType') ?? undefined; + let host = url.searchParams.get('host') ?? undefined; + let path = url.searchParams.get('path') ?? undefined; - if (type === 'tcp') { + if (type === 'tcp' || type === 'none') { stream.tcp = new TcpStreamSettings(headerType ?? 'none', host, path); } else if (type === 'kcp') { stream.kcp = new KcpStreamSettings(); @@ -713,10 +715,7 @@ class Outbound extends CommonClass { stream.reality = new RealityStreamSettings(pbk, fp, sni, sid, spx); } - let data = link.split('?'); - if(data.length != 2) return null; - - const regex = /([^@]+):\/\/([^@]+)@(.+):(\d+)\?(.*)$/; + const regex = /([^@]+):\/\/([^@]+)@(.+):(\d+)(.*)$/; const match = link.match(regex); if (!match) return null;