Refactor flow

This commit is contained in:
DHR60 2026-01-21 12:03:23 +08:00
parent ee7d3c60b6
commit 82443a64cd
7 changed files with 13 additions and 17 deletions

View file

@ -21,12 +21,6 @@ public class BaseFmt
protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery) protected static int ToUriQuery(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
{ {
var protocolExtra = item.GetProtocolExtra();
if (!protocolExtra.Flow.IsNullOrEmpty())
{
dicQuery.Add("flow", protocolExtra.Flow);
}
if (item.StreamSecurity.IsNotEmpty()) if (item.StreamSecurity.IsNotEmpty())
{ {
dicQuery.Add("security", item.StreamSecurity); dicQuery.Add("security", item.StreamSecurity);
@ -209,9 +203,6 @@ public class BaseFmt
protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem item) protected static int ResolveUriQuery(NameValueCollection query, ref ProfileItem item)
{ {
var protocolExtra = item.GetProtocolExtra();
protocolExtra.Flow = GetQueryValue(query, "flow");
item.SetProtocolExtra(protocolExtra);
item.StreamSecurity = GetQueryValue(query, "security"); item.StreamSecurity = GetQueryValue(query, "security");
item.Sni = GetQueryValue(query, "sni"); item.Sni = GetQueryValue(query, "sni");
item.Alpn = GetQueryDecoded(query, "alpn"); item.Alpn = GetQueryDecoded(query, "alpn");

View file

@ -10,6 +10,7 @@ public class TrojanFmt : BaseFmt
{ {
ConfigType = EConfigType.Trojan ConfigType = EConfigType.Trojan
}; };
var protocolExtra = item.GetProtocolExtra();
var url = Utils.TryUri(str); var url = Utils.TryUri(str);
if (url == null) if (url == null)
@ -23,8 +24,10 @@ public class TrojanFmt : BaseFmt
item.Password = Utils.UrlDecode(url.UserInfo); item.Password = Utils.UrlDecode(url.UserInfo);
var query = Utils.ParseQueryString(url.Query); var query = Utils.ParseQueryString(url.Query);
protocolExtra.Flow = GetQueryValue(query, "flow");
ResolveUriQuery(query, ref item); ResolveUriQuery(query, ref item);
item.SetProtocolExtra(protocolExtra);
return item; return item;
} }
@ -34,12 +37,17 @@ public class TrojanFmt : BaseFmt
{ {
return null; return null;
} }
var protocolExtra = item.GetProtocolExtra();
var 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);
} }
var dicQuery = new Dictionary<string, string>(); var dicQuery = new Dictionary<string, string>();
if (!protocolExtra.Flow.IsNullOrEmpty())
{
dicQuery.Add("flow", protocolExtra.Flow);
}
ToUriQuery(item, null, ref dicQuery); ToUriQuery(item, null, ref dicQuery);
return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Password, dicQuery, remark); return ToUri(EConfigType.Trojan, item.Address, item.Port, item.Password, dicQuery, remark);

View file

@ -25,6 +25,7 @@ public class VLESSFmt : BaseFmt
var query = Utils.ParseQueryString(url.Query); var query = Utils.ParseQueryString(url.Query);
protocolExtra.VlessEncryption = GetQueryValue(query, "encryption", Global.None); protocolExtra.VlessEncryption = GetQueryValue(query, "encryption", Global.None);
protocolExtra.Flow = GetQueryValue(query, "flow");
item.StreamSecurity = GetQueryValue(query, "security"); item.StreamSecurity = GetQueryValue(query, "security");
ResolveUriQuery(query, ref item); ResolveUriQuery(query, ref item);
@ -49,6 +50,10 @@ public class VLESSFmt : BaseFmt
var dicQuery = new Dictionary<string, string>(); var dicQuery = new Dictionary<string, string>();
dicQuery.Add("encryption", dicQuery.Add("encryption",
!protocolExtra.VlessEncryption.IsNullOrEmpty() ? protocolExtra.VlessEncryption : Global.None); !protocolExtra.VlessEncryption.IsNullOrEmpty() ? protocolExtra.VlessEncryption : Global.None);
if (!protocolExtra.Flow.IsNullOrEmpty())
{
dicQuery.Add("flow", protocolExtra.Flow);
}
ToUriQuery(item, Global.None, ref dicQuery); ToUriQuery(item, Global.None, ref dicQuery);
return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Password, dicQuery, remark); return ToUri(EConfigType.VLESS, item.Address, item.Port, item.Password, dicQuery, remark);

View file

@ -1,5 +1,3 @@
using ServiceLib.Common;
namespace ServiceLib.Manager; namespace ServiceLib.Manager;
/// <summary> /// <summary>

View file

@ -1,5 +1,3 @@
using ServiceLib.Common;
namespace ServiceLib.Models; namespace ServiceLib.Models;
[Serializable] [Serializable]

View file

@ -1,5 +1,3 @@
using System.Linq;
namespace ServiceLib.Services.CoreConfig; namespace ServiceLib.Services.CoreConfig;
public partial class CoreConfigSingboxService public partial class CoreConfigSingboxService

View file

@ -1,5 +1,3 @@
using System.Linq;
namespace ServiceLib.Services.CoreConfig; namespace ServiceLib.Services.CoreConfig;
public partial class CoreConfigV2rayService public partial class CoreConfigV2rayService