Refactor client update handling to support nullable parameters for name and expiration
- Updated the `UpdateClientAsync` method in `IXuiPanelGateway` to accept nullable parameters for `name` and `expiresAt`, allowing for more flexible client management without unintended modifications. - Adjusted the `BlockUserCommandHandler`, `UnblockUserCommandHandler`, and other related command handlers to utilize the new nullable parameters, ensuring that client names remain unchanged during block/unblock operations and that expiration dates are managed correctly. - Enhanced the billing and configuration handling to reflect the new logic for managing client states based on expiration rather than enabling/disabling, improving reliability in client status management. - Updated tests to cover the new behavior and ensure proper functionality across the application.
This commit is contained in:
@@ -36,6 +36,8 @@ public interface IXuiPanelGateway
|
||||
/// Возвращает ClientExternalId, присвоенный панелью (UUID для VLESS/VMess, пароль для Trojan/Shadowsocks).
|
||||
/// <paramref name="limitIp"/> — лимит одновременных IP клиента (квота роли, см. AppRole.MaxIpLimit);
|
||||
/// -1 (RoleQuota.Unlimited) означает без лимита — гейтвей сам переводит его в нативное значение 3x-ui.
|
||||
/// <paramref name="expiresAt"/> — дата, до которой клиент активен в самой панели (billing-роли —
|
||||
/// AppUser.BillingPaidUntil на момент создания); <c>null</c> — без ограничения по сроку.
|
||||
/// </summary>
|
||||
Task<Result<string>> AddClientAsync(
|
||||
Node node,
|
||||
@@ -44,6 +46,7 @@ public interface IXuiPanelGateway
|
||||
string clientEmail,
|
||||
string clientName,
|
||||
int limitIp,
|
||||
DateTimeOffset? expiresAt,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
@@ -55,13 +58,35 @@ public interface IXuiPanelGateway
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Все параметры, кроме обязательных идентификаторов, — "не трогать, если null" (см. ThreeXui.Net
|
||||
/// UpdateClientRequest: "All fields optional — null means leave as is").
|
||||
/// <para>
|
||||
/// <paramref name="name"/> — НЕ отдельная косметическая метка: у клиента 3x-ui нет своего поля
|
||||
/// remark/comment, поэтому ThreeXui.Net пишет её в то же поле <c>settings.clients[].email</c>,
|
||||
/// которое AddClientAsync изначально заполняет стабильным ClientEmail. Передавайте <c>null</c>
|
||||
/// для любого вызова, не являющегося намеренным переименованием — иначе затрёте панельный
|
||||
/// identity-идентификатор клиента (и сломаете сопоставление по email в GetClientTrafficAsync).
|
||||
/// Единственный легитимный вызывающий с непустым name — EditVpnConfigCommandHandler.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <paramref name="expiresAt"/> — используется для приостановки/возврата за неуплату
|
||||
/// (BillingService/BillingConfigResumer): дата в прошлом делает клиента просроченным для самой
|
||||
/// панели/Xray независимо от <paramref name="enable"/> (по факту тестирования — переключение
|
||||
/// enable ненадёжно останавливает уже установленные соединения, а expiryTime — надёжно), дата в
|
||||
/// будущем (новый AppUser.BillingPaidUntil) снимает приостановку. Блокировка/разблокировка
|
||||
/// админом (BlockUserCommandHandler/UnblockUserCommandHandler) — отдельная ось, передаёт
|
||||
/// <c>expiresAt: null</c> и управляет только <paramref name="enable"/>.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
Task<Result> UpdateClientAsync(
|
||||
Node node,
|
||||
string inboundRemoteId,
|
||||
string clientExternalId,
|
||||
VpnProtocol protocol,
|
||||
string name,
|
||||
bool enable,
|
||||
string? name,
|
||||
bool? enable,
|
||||
DateTimeOffset? expiresAt,
|
||||
CancellationToken cancellationToken
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user