mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 21:52:25 +00:00
AI-optimized code
This commit is contained in:
parent
23b27575a0
commit
d4a8787356
10 changed files with 57 additions and 34 deletions
|
@ -215,7 +215,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
foreach (var item in s)
|
foreach (var item in s)
|
||||||
{
|
{
|
||||||
if (str.Contains(item, StringComparison.OrdinalIgnoreCase))
|
if (str.Contains(item, StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,10 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
var remark = string.Empty;
|
||||||
string remark = string.Empty;
|
|
||||||
if (item.Remarks.IsNotEmpty())
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
|
@ -53,7 +53,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
var match = UrlFinder.Match(result);
|
var match = UrlFinder.Match(result);
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProfileItem item = new();
|
ProfileItem item = new();
|
||||||
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
||||||
|
@ -72,7 +74,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!details.Success)
|
if (!details.Success)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
item.Security = details.Groups["method"].Value;
|
item.Security = details.Groups["method"].Value;
|
||||||
item.Id = details.Groups["password"].Value;
|
item.Id = details.Groups["password"].Value;
|
||||||
item.Address = details.Groups["hostname"].Value;
|
item.Address = details.Groups["hostname"].Value;
|
||||||
|
@ -84,7 +88,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
var parsedUrl = Utils.TryUri(result);
|
var parsedUrl = Utils.TryUri(result);
|
||||||
if (parsedUrl == null)
|
if (parsedUrl == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProfileItem item = new()
|
ProfileItem item = new()
|
||||||
{
|
{
|
||||||
|
@ -96,7 +102,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
//2022-blake3
|
//2022-blake3
|
||||||
if (rawUserInfo.Contains(':'))
|
if (rawUserInfo.Contains(':'))
|
||||||
{
|
{
|
||||||
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
var userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length != 2)
|
if (userInfoParts.Length != 2)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -107,8 +113,8 @@ namespace ServiceLib.Handler.Fmt
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parse base64 UserInfo
|
// parse base64 UserInfo
|
||||||
string userInfo = Utils.Base64Decode(rawUserInfo);
|
var userInfo = Utils.Base64Decode(rawUserInfo);
|
||||||
string[] userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
var userInfoParts = userInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length != 2)
|
if (userInfoParts.Length != 2)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
namespace ServiceLib.Handler.Fmt
|
namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
public class SingboxFmt : BaseFmt
|
public class SingboxFmt : BaseFmt
|
||||||
{
|
{
|
||||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||||
{
|
{
|
||||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||||
if (configObjects != null && configObjects.Length > 0)
|
if (configObjects != null && configObjects.Length > 0)
|
||||||
{
|
{
|
||||||
List<ProfileItem> lstResult = [];
|
List<ProfileItem> lstResult = [];
|
||||||
|
|
|
@ -24,9 +24,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
var url = string.Empty;
|
}
|
||||||
|
|
||||||
var remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (item.Remarks.IsNotEmpty())
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
|
@ -77,7 +77,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
item.Address = arr1[1][..indexPort];
|
item.Address = arr1[1][..indexPort];
|
||||||
item.Port = (arr1[1][(indexPort + 1)..]).ToInt();
|
item.Port = arr1[1][(indexPort + 1)..].ToInt();
|
||||||
item.Security = arr21.First();
|
item.Security = arr21.First();
|
||||||
item.Id = arr21[1];
|
item.Id = arr21[1];
|
||||||
|
|
||||||
|
@ -88,7 +88,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
var parsedUrl = Utils.TryUri(result);
|
var parsedUrl = Utils.TryUri(result);
|
||||||
if (parsedUrl == null)
|
if (parsedUrl == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
ProfileItem item = new()
|
ProfileItem item = new()
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
|
@ -21,7 +23,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
item.Id = Utils.UrlDecode(url.UserInfo);
|
item.Id = Utils.UrlDecode(url.UserInfo);
|
||||||
|
|
||||||
var query = Utils.ParseQueryString(url.Query);
|
var query = Utils.ParseQueryString(url.Query);
|
||||||
ResolveStdTransport(query, ref item);
|
_ = ResolveStdTransport(query, ref item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -29,16 +31,16 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
var remark = string.Empty;
|
||||||
string remark = string.Empty;
|
|
||||||
if (item.Remarks.IsNotEmpty())
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
}
|
}
|
||||||
var dicQuery = new Dictionary<string, string>();
|
var dicQuery = new Dictionary<string, string>();
|
||||||
GetStdTransport(item, null, ref dicQuery);
|
_ = GetStdTransport(item, null, ref dicQuery);
|
||||||
|
|
||||||
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
|
@ -36,10 +38,11 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
|
||||||
string remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (item.Remarks.IsNotEmpty())
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
namespace ServiceLib.Handler.Fmt
|
namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
public class V2rayFmt : BaseFmt
|
public class V2rayFmt : BaseFmt
|
||||||
{
|
{
|
||||||
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
public static List<ProfileItem>? ResolveFullArray(string strData, string? subRemarks)
|
||||||
{
|
{
|
||||||
var configObjects = JsonUtils.Deserialize<Object[]>(strData);
|
var configObjects = JsonUtils.Deserialize<object[]>(strData);
|
||||||
if (configObjects != null && configObjects.Length > 0)
|
if (configObjects != null && configObjects.Length > 0)
|
||||||
{
|
{
|
||||||
List<ProfileItem> lstResult = [];
|
List<ProfileItem> lstResult = [];
|
||||||
|
|
|
@ -14,7 +14,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
|
@ -24,7 +26,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
var query = Utils.ParseQueryString(url.Query);
|
var query = Utils.ParseQueryString(url.Query);
|
||||||
item.Security = query["encryption"] ?? Global.None;
|
item.Security = query["encryption"] ?? Global.None;
|
||||||
item.StreamSecurity = query["security"] ?? "";
|
item.StreamSecurity = query["security"] ?? "";
|
||||||
ResolveStdTransport(query, ref item);
|
_ = ResolveStdTransport(query, ref item);
|
||||||
|
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
@ -32,10 +34,11 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
|
||||||
string remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (item.Remarks.IsNotEmpty())
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
|
@ -49,7 +52,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
{
|
{
|
||||||
dicQuery.Add("encryption", Global.None);
|
dicQuery.Add("encryption", Global.None);
|
||||||
}
|
}
|
||||||
GetStdTransport(item, Global.None, ref dicQuery);
|
_ = GetStdTransport(item, Global.None, ref dicQuery);
|
||||||
|
|
||||||
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Id, dicQuery, remark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,10 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
var vmessQRCode = new VmessQRCode
|
||||||
VmessQRCode vmessQRCode = new()
|
|
||||||
{
|
{
|
||||||
v = item.ConfigVersion,
|
v = item.ConfigVersion,
|
||||||
ps = item.Remarks.TrimEx(),
|
ps = item.Remarks.TrimEx(),
|
||||||
|
@ -42,7 +42,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
fp = item.Fingerprint
|
fp = item.Fingerprint
|
||||||
};
|
};
|
||||||
|
|
||||||
url = JsonUtils.Serialize(vmessQRCode);
|
var url = JsonUtils.Serialize(vmessQRCode);
|
||||||
url = Utils.Base64Encode(url);
|
url = Utils.Base64Encode(url);
|
||||||
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
|
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
|
|
||||||
VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
var vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||||
if (vmessQRCode == null)
|
if (vmessQRCode == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedConversionConfiguration;
|
msg = ResUI.FailedConversionConfiguration;
|
||||||
|
@ -100,7 +100,7 @@ namespace ServiceLib.Handler.Fmt
|
||||||
|
|
||||||
public static ProfileItem? ResolveStdVmess(string str)
|
public static ProfileItem? ResolveStdVmess(string str)
|
||||||
{
|
{
|
||||||
ProfileItem item = new()
|
var item = new ProfileItem
|
||||||
{
|
{
|
||||||
ConfigType = EConfigType.VMess,
|
ConfigType = EConfigType.VMess,
|
||||||
Security = "auto"
|
Security = "auto"
|
||||||
|
@ -108,7 +108,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
|
|
|
@ -13,7 +13,9 @@ namespace ServiceLib.Handler.Fmt
|
||||||
|
|
||||||
var url = Utils.TryUri(str);
|
var url = Utils.TryUri(str);
|
||||||
if (url == null)
|
if (url == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
item.Address = url.IdnHost;
|
item.Address = url.IdnHost;
|
||||||
item.Port = url.Port;
|
item.Port = url.Port;
|
||||||
|
@ -33,10 +35,11 @@ namespace ServiceLib.Handler.Fmt
|
||||||
public static string? ToUri(ProfileItem? item)
|
public static string? ToUri(ProfileItem? item)
|
||||||
{
|
{
|
||||||
if (item == null)
|
if (item == null)
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
string url = string.Empty;
|
}
|
||||||
|
|
||||||
string remark = string.Empty;
|
var remark = string.Empty;
|
||||||
if (item.Remarks.IsNotEmpty())
|
if (item.Remarks.IsNotEmpty())
|
||||||
{
|
{
|
||||||
remark = "#" + Utils.UrlEncode(item.Remarks);
|
remark = "#" + Utils.UrlEncode(item.Remarks);
|
||||||
|
|
Loading…
Reference in a new issue