mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-01 18:15:00 +03:00
Preserve subscription profiles on failed import (#10429)
This commit is contained in:
@@ -27,16 +27,51 @@ public class ConfigHandlerCustomSubscriptionTests
|
||||
Url = "http://127.0.0.1/sub",
|
||||
PreSocksPort = 10808,
|
||||
});
|
||||
var oldProfile = CoreConfigTestFactory.CreateVmessNode(ECoreType.Xray, $"profile-{Guid.NewGuid():N}", "old");
|
||||
oldProfile.Subid = subId;
|
||||
oldProfile.IsSub = true;
|
||||
await SQLiteHelper.Instance.InsertAsync(oldProfile);
|
||||
|
||||
var count = await ConfigHandler.AddBatchServers(config, FullXrayConfigs, subId, true);
|
||||
var profiles = await AppManager.Instance.ProfileItems(subId) ?? [];
|
||||
|
||||
await count.Should().BeEqualTo(2);
|
||||
await profiles.Should().HaveCount(2);
|
||||
await profiles.Any(profile => profile.IndexId == oldProfile.IndexId).Should().BeFalse();
|
||||
foreach (var profile in profiles)
|
||||
{
|
||||
await profile.ConfigType.Should().BeEqualTo(EConfigType.Custom);
|
||||
await profile.PreSocksPort.Should().BeEqualTo(10808);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AddBatchServers_UnsuccessfulSubscriptionUpdate_PreservesExistingProfiles()
|
||||
{
|
||||
var config = CoreConfigTestFactory.CreateConfig();
|
||||
CoreConfigTestFactory.BindAppManagerConfig(config);
|
||||
SQLiteHelper.Instance.CreateTable<SubItem>();
|
||||
SQLiteHelper.Instance.CreateTable<ProfileItem>();
|
||||
|
||||
var subId = $"sub-failed-{Guid.NewGuid():N}";
|
||||
await SQLiteHelper.Instance.ReplaceAsync(new SubItem
|
||||
{
|
||||
Id = subId,
|
||||
Remarks = "sub",
|
||||
Url = "http://127.0.0.1/sub",
|
||||
});
|
||||
|
||||
var existing = CoreConfigTestFactory.CreateVmessNode(ECoreType.Xray, $"profile-{Guid.NewGuid():N}", "existing");
|
||||
existing.Subid = subId;
|
||||
existing.IsSub = true;
|
||||
await SQLiteHelper.Instance.InsertAsync(existing);
|
||||
|
||||
var invalidSubscription = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes("not a valid profile"));
|
||||
var count = await ConfigHandler.AddBatchServers(config, invalidSubscription, subId, true);
|
||||
var profiles = await AppManager.Instance.ProfileItems(subId) ?? [];
|
||||
|
||||
await (count < 1).Should().BeTrue();
|
||||
await profiles.Should().HaveCount(1);
|
||||
await profiles[0].IndexId.Should().BeEqualTo(existing.IndexId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2134,7 +2134,6 @@ public static class ConfigHandler
|
||||
{
|
||||
lstOriSub = await AppManager.Instance.ProfileItems(subid);
|
||||
activeProfile = lstOriSub?.FirstOrDefault(t => t.IndexId == config.IndexId);
|
||||
await RemoveServersViaSubid(config, subid, true);
|
||||
}
|
||||
|
||||
var counter = 0;
|
||||
@@ -2194,6 +2193,11 @@ public static class ConfigHandler
|
||||
counter = await AddBatchServers4Custom(config, strData, subid, isSub);
|
||||
}
|
||||
|
||||
if (counter > 0 && lstOriSub is { Count: > 0 })
|
||||
{
|
||||
await RemoveServers(config, lstOriSub.Where(item => item.IsSub).ToList());
|
||||
}
|
||||
|
||||
//Select active node
|
||||
if (activeProfile != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user