mirror of
https://github.com/2dust/v2rayN.git
synced 2026-02-28 21:23:04 +00:00
Clean code
This commit is contained in:
parent
9c20beb6da
commit
0ac7e87158
3 changed files with 11 additions and 54 deletions
|
|
@ -96,8 +96,7 @@ public static class CoreConfigHandler
|
|||
var result = new RetResult();
|
||||
var context = await BuildCoreConfigContext(config, new());
|
||||
var ids = selecteds.Where(serverTestItem => !serverTestItem.IndexId.IsNullOrEmpty())
|
||||
.Select(serverTestItem => serverTestItem.IndexId!)
|
||||
.ToList();
|
||||
.Select(serverTestItem => serverTestItem.IndexId);
|
||||
var nodes = await AppManager.Instance.GetProfileItemsByIndexIds(ids);
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -230,9 +230,9 @@ public sealed class AppManager
|
|||
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().FirstOrDefaultAsync(it => it.IndexId == indexId);
|
||||
}
|
||||
|
||||
public async Task<List<ProfileItem>> GetProfileItemsByIndexIds(List<string> indexIds)
|
||||
public async Task<List<ProfileItem>> GetProfileItemsByIndexIds(IEnumerable<string> indexIds)
|
||||
{
|
||||
var ids = indexIds.Where(id => id.IsNotEmpty()).Distinct().ToList();
|
||||
var ids = indexIds.Where(id => !id.IsNullOrEmpty()).Distinct().ToList();
|
||||
if (ids.Count == 0)
|
||||
{
|
||||
return [];
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class GroupProfileManager
|
|||
{
|
||||
if (protocolExtra == null)
|
||||
{
|
||||
return new();
|
||||
return [];
|
||||
}
|
||||
|
||||
var items = new List<ProfileItem>();
|
||||
|
|
@ -93,27 +93,19 @@ public class GroupProfileManager
|
|||
{
|
||||
if (extra == null || extra.ChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return new();
|
||||
return [];
|
||||
}
|
||||
var childProfiles = (await Task.WhenAll(
|
||||
(Utils.String2List(extra.ChildItems) ?? new())
|
||||
.Where(p => !p.IsNullOrEmpty())
|
||||
.Select(AppManager.Instance.GetProfileItem)
|
||||
))
|
||||
.Where(p =>
|
||||
p != null &&
|
||||
p.IsValid() &&
|
||||
p.ConfigType != EConfigType.Custom
|
||||
)
|
||||
.ToList();
|
||||
return childProfiles ?? new();
|
||||
var childProfileIds = Utils.String2List(extra.ChildItems)
|
||||
?.Where(p => !string.IsNullOrEmpty(p)) ?? [];
|
||||
var childProfiles = await AppManager.Instance.GetProfileItemsByIndexIds(childProfileIds);
|
||||
return childProfiles ?? [];
|
||||
}
|
||||
|
||||
private static async Task<List<ProfileItem>> GetSubChildProfileItems(ProtocolExtraItem? extra)
|
||||
{
|
||||
if (extra == null || extra.SubChildItems.IsNullOrEmpty())
|
||||
{
|
||||
return new();
|
||||
return [];
|
||||
}
|
||||
var childProfiles = await AppManager.Instance.ProfileItems(extra.SubChildItems ?? string.Empty);
|
||||
|
||||
|
|
@ -123,7 +115,7 @@ public class GroupProfileManager
|
|||
!p.ConfigType.IsComplexType() &&
|
||||
(extra.Filter.IsNullOrEmpty() || Regex.IsMatch(p.Remarks, extra.Filter))
|
||||
)
|
||||
.ToList() ?? new();
|
||||
.ToList() ?? [];
|
||||
}
|
||||
|
||||
public static async Task<List<ProfileItem>> GetAllChildProfileItems(ProfileItem profileItem)
|
||||
|
|
@ -149,38 +141,4 @@ public class GroupProfileManager
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static async Task<HashSet<string>> GetAllChildDomainAddresses(ProfileItem profileItem)
|
||||
{
|
||||
var childAddresses = new HashSet<string>();
|
||||
var childItems = await GetAllChildProfileItems(profileItem);
|
||||
foreach (var child in childItems.Where(child => !child.Address.IsNullOrEmpty()).Where(child => Utils.IsDomain(child.Address)))
|
||||
{
|
||||
childAddresses.Add(child.Address);
|
||||
}
|
||||
return childAddresses;
|
||||
}
|
||||
|
||||
public static async Task<HashSet<string>> GetAllChildEchQuerySni(ProfileItem profileItem)
|
||||
{
|
||||
var childAddresses = new HashSet<string>();
|
||||
var childItems = await GetAllChildProfileItems(profileItem);
|
||||
foreach (var childNode in childItems.Where(childNode => !childNode.EchConfigList.IsNullOrEmpty()))
|
||||
{
|
||||
var sni = childNode.Sni;
|
||||
if (childNode.StreamSecurity == Global.StreamSecurity
|
||||
&& childNode.EchConfigList?.Contains("://") == true)
|
||||
{
|
||||
var idx = childNode.EchConfigList.IndexOf('+');
|
||||
sni = idx > 0 ? childNode.EchConfigList[..idx] : childNode.Sni;
|
||||
}
|
||||
if (!Utils.IsDomain(sni))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
childAddresses.Add(sni);
|
||||
}
|
||||
return childAddresses;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue