Add inbound country flags and node load in location picker
- Inbound.CountryCode (ISO alpha-2), set on publish; flag shown before the location name (SVG via country-flag-icons on the site, emoji in bot) - Node.Capacity (optional, not a limit); available inbounds report load percent of capacity or active config count, sorted least loaded first Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7743977a1
commit
bb5e59904f
51 files changed
+3160
-284
No files matched your search
+1
-1
@@ -26,7 +26,7 @@ public class ListAllConfigsQueryHandlerTests
|
||||
null
|
||||
);
|
||||
var inbound = Inbound.FromRemote(node.Id, "1", VpnProtocol.Vless, "remark", 443);
|
||||
inbound.Publish("Germany", []);
|
||||
inbound.Publish("Germany", null, []);
|
||||
var config = VpnConfig.Create(userId, inbound.Id, VpnProtocol.Vless, "my-config");
|
||||
|
||||
dbContext.Nodes.Add(node);
|
||||
|
||||
+6
-4
@@ -22,7 +22,7 @@ public class PublishInboundCommandHandlerTests
|
||||
var roleId = Guid.NewGuid();
|
||||
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var command = new PublishInboundCommand(inbound.Id, true, "EU Fast", [roleId]);
|
||||
var command = new PublishInboundCommand(inbound.Id, true, "EU Fast", "de", [roleId]);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
@@ -31,6 +31,8 @@ public class PublishInboundCommandHandlerTests
|
||||
Assert.Equal("EU Fast", inbound.DisplayName);
|
||||
Assert.Contains(roleId, inbound.AllowedRoleIds);
|
||||
Assert.Equal("EU Fast", result.Value.DisplayName);
|
||||
Assert.Equal("DE", inbound.CountryCode);
|
||||
Assert.Equal("DE", result.Value.CountryCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,13 +40,13 @@ public class PublishInboundCommandHandlerTests
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var inbound = Inbound.FromRemote(Guid.NewGuid(), "1", VpnProtocol.Vless, "remark", 443);
|
||||
inbound.Publish("EU Fast", [Guid.NewGuid()]);
|
||||
inbound.Publish("EU Fast", null, [Guid.NewGuid()]);
|
||||
dbContext.Inbounds.Add(inbound);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var command = new PublishInboundCommand(inbound.Id, false, null, []);
|
||||
var command = new PublishInboundCommand(inbound.Id, false, null, null, []);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
@@ -59,7 +61,7 @@ public class PublishInboundCommandHandlerTests
|
||||
|
||||
var handler = new PublishInboundCommandHandler(dbContext, _currentUser);
|
||||
|
||||
var command = new PublishInboundCommand(Guid.NewGuid(), true, "EU Fast", []);
|
||||
var command = new PublishInboundCommand(Guid.NewGuid(), true, "EU Fast", null, []);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
using PnvPanel.Application.Admin.Inbounds;
|
||||
using Xunit;
|
||||
|
||||
namespace PnvPanel.Application.Tests.Admin.Inbounds;
|
||||
|
||||
public class PublishInboundCommandValidatorTests
|
||||
{
|
||||
private readonly PublishInboundCommandValidator _validator = new();
|
||||
|
||||
private static PublishInboundCommand Command(string? countryCode) =>
|
||||
new(Guid.NewGuid(), true, "EU Fast", countryCode, []);
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
[InlineData("DE")]
|
||||
[InlineData("nl")]
|
||||
public void Validate_WithEmptyOrAlpha2CountryCode_IsValid(string? countryCode)
|
||||
{
|
||||
var result = _validator.Validate(Command(countryCode));
|
||||
|
||||
Assert.True(result.IsValid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("DEU")]
|
||||
[InlineData("D")]
|
||||
[InlineData("1E")]
|
||||
public void Validate_WithInvalidCountryCode_IsInvalid(string countryCode)
|
||||
{
|
||||
var result = _validator.Validate(Command(countryCode));
|
||||
|
||||
Assert.False(result.IsValid);
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class SyncNodeCommandHandlerTests
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
var node = CreateNode();
|
||||
var inbound = Inbound.FromRemote(node.Id, "old-id", VpnProtocol.Vless, "old", 443);
|
||||
inbound.Publish("Old", [Guid.NewGuid()]);
|
||||
inbound.Publish("Old", null, [Guid.NewGuid()]);
|
||||
var config = VpnConfig.Create(Guid.NewGuid(), inbound.Id, VpnProtocol.Vless, null);
|
||||
config.AssignRemoteClient("external-id");
|
||||
|
||||
|
||||
+9
-2
@@ -40,6 +40,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -69,6 +70,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -90,7 +92,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
|
||||
var handler = new UpdateNodeCommandHandler(dbContext, _gateway, _secretProtector, _currentUser);
|
||||
|
||||
var command = new UpdateNodeCommand(node.Id, "node-1", "not-a-uri", null, true, false, null, null);
|
||||
var command = new UpdateNodeCommand(node.Id, "node-1", "not-a-uri", null, true, false, null, null, null);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
|
||||
@@ -121,6 +123,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -152,7 +155,8 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
false,
|
||||
"new-admin",
|
||||
"new-password"
|
||||
"new-password",
|
||||
null
|
||||
);
|
||||
|
||||
var result = await handler.Handle(command, CancellationToken.None);
|
||||
@@ -181,6 +185,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
false,
|
||||
"new-admin",
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -211,6 +216,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
@@ -235,6 +241,7 @@ public class UpdateNodeCommandHandlerTests
|
||||
true,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user