Refactor project files for improved readability and structure
CI / Backend (build + test) (push) Successful in 1m18s
CI / Frontend (lint + typecheck + build) (push) Successful in 31s

- Cleaned up whitespace in Directory.Build.props and Directory.Packages.props for consistency.
- Reformatted project file references in PnvPanel.Api.csproj for better clarity.
- Enhanced code readability in various endpoint files by adjusting line breaks and indentation.
- Standardized method signatures and improved formatting in ResultExtensions and multiple endpoint classes for better maintainability.
This commit is contained in:
Leonid Pershin
2026-07-14 07:24:13 +03:00
parent 9d5424bb9c
commit df137ca5a7
285 changed files with 6911 additions and 2063 deletions
@@ -17,9 +17,21 @@ public class ConfigQuotaTests(PnvPanelWebApplicationFactory factory)
private sealed record SyncNodeResponse(int InboundsSynced, string Status);
private sealed record InboundResponse(Guid Id, Guid NodeId, string RemoteInboundId, string Protocol, string Remark, int Port, bool IsPublished);
private sealed record InboundResponse(
Guid Id,
Guid NodeId,
string RemoteInboundId,
string Protocol,
string Remark,
int Port,
bool IsPublished
);
private sealed record ActivationRequestResponse(Guid Id, string? Comment, DateTimeOffset CreatedAt);
private sealed record ActivationRequestResponse(
Guid Id,
string? Comment,
DateTimeOffset CreatedAt
);
private sealed record MyConfigsResponse(List<object> Configs, int MaxConfigs);
@@ -41,33 +53,44 @@ public class ConfigQuotaTests(PnvPanelWebApplicationFactory factory)
var userRole = roles!.Single(r => r.Name == "user");
var updateRoleResponse = await adminClient.SendPutJsonAsync(
$"/api/admin/roles/{userRole.Id}", new { maxConfigs = Quota, maxIpLimit = -1 });
$"/api/admin/roles/{userRole.Id}",
new { maxConfigs = Quota, maxIpLimit = -1 }
);
Assert.Equal(HttpStatusCode.OK, updateRoleResponse.StatusCode);
var registerNodeResponse = await adminClient.PostJsonAsync("/api/admin/nodes", new
{
name = $"QuotaNode-{Guid.NewGuid():N}"[..24],
baseAddress = "https://quota-node.example.com",
username = "admin",
password = "node-panel-password",
location = (string?)null,
});
var registerNodeResponse = await adminClient.PostJsonAsync(
"/api/admin/nodes",
new
{
name = $"QuotaNode-{Guid.NewGuid():N}"[..24],
baseAddress = "https://quota-node.example.com",
username = "admin",
password = "node-panel-password",
location = (string?)null,
}
);
var node = await registerNodeResponse.ReadAsAsync<NodeResponse>();
var syncResponse = await adminClient.PostAsync($"/api/admin/nodes/{node!.Id}/sync", content: null);
var syncResponse = await adminClient.PostAsync(
$"/api/admin/nodes/{node!.Id}/sync",
content: null
);
var sync = await syncResponse.ReadAsAsync<SyncNodeResponse>();
Assert.Equal(1, sync!.InboundsSynced);
var inboundsResponse = await adminClient.GetAsync($"/api/admin/inbounds?nodeId={node.Id}");
var inbound = (await inboundsResponse.ReadAsAsync<List<InboundResponse>>())!.Single();
var publishResponse = await adminClient.SendPutJsonAsync($"/api/admin/inbounds/{inbound.Id}/publish", new
{
isPublished = true,
displayName = "Quota inbound",
allowedRoleIds = new[] { userRole.Id },
maxClients = (int?)null,
});
var publishResponse = await adminClient.SendPutJsonAsync(
$"/api/admin/inbounds/{inbound.Id}/publish",
new
{
isPublished = true,
displayName = "Quota inbound",
allowedRoleIds = new[] { userRole.Id },
maxClients = (int?)null,
}
);
Assert.Equal(HttpStatusCode.OK, publishResponse.StatusCode);
using var userClient = factory.CreateClient();
@@ -75,21 +98,29 @@ public class ConfigQuotaTests(PnvPanelWebApplicationFactory factory)
var (_, userToken) = await RegisterAndLoginAsync(userClient, userName, "P@ssw0rd123");
userClient.UseBearerToken(userToken);
var activationRequestResponse = await userClient.PostJsonAsync("/api/activation/request", new { comment = (string?)null });
var activationRequest = await activationRequestResponse.ReadAsAsync<ActivationRequestResponse>();
var approveResponse = await adminClient.PostAsync($"/api/admin/activation-requests/{activationRequest!.Id}/approve", content: null);
var activationRequestResponse = await userClient.PostJsonAsync(
"/api/activation/request",
new { comment = (string?)null }
);
var activationRequest =
await activationRequestResponse.ReadAsAsync<ActivationRequestResponse>();
var approveResponse = await adminClient.PostAsync(
$"/api/admin/activation-requests/{activationRequest!.Id}/approve",
content: null
);
Assert.Equal(HttpStatusCode.NoContent, approveResponse.StatusCode);
var tasks = Enumerable.Range(0, ConcurrentAttempts).Select(async i =>
{
using var attemptClient = factory.CreateClient();
attemptClient.UseBearerToken(userToken);
return await attemptClient.PostJsonAsync("/api/configs", new
var tasks = Enumerable
.Range(0, ConcurrentAttempts)
.Select(async i =>
{
inboundId = inbound.Id,
label = $"device-{i}",
using var attemptClient = factory.CreateClient();
attemptClient.UseBearerToken(userToken);
return await attemptClient.PostJsonAsync(
"/api/configs",
new { inboundId = inbound.Id, label = $"device-{i}" }
);
});
});
var responses = await Task.WhenAll(tasks);