diff --git a/src/TelegramPanel.Core/Interfaces/IAccountService.cs b/src/TelegramPanel.Core/Interfaces/IAccountService.cs index 84f7113..57c2815 100644 --- a/src/TelegramPanel.Core/Interfaces/IAccountService.cs +++ b/src/TelegramPanel.Core/Interfaces/IAccountService.cs @@ -41,6 +41,11 @@ public interface IAccountService /// 检查账号状态 /// Task CheckStatusAsync(int accountId); + + /// + /// 释放并移除指定账号的 Telegram 客户端(用于避免 session 文件长期被占用)。 + /// + Task ReleaseClientAsync(int accountId); } /// diff --git a/src/TelegramPanel.Core/Services/Telegram/AccountService.cs b/src/TelegramPanel.Core/Services/Telegram/AccountService.cs index dad6fa9..59af436 100644 --- a/src/TelegramPanel.Core/Services/Telegram/AccountService.cs +++ b/src/TelegramPanel.Core/Services/Telegram/AccountService.cs @@ -230,6 +230,11 @@ public class AccountService : IAccountService return Task.FromResult(AccountStatus.Active); } + public Task ReleaseClientAsync(int accountId) + { + return _clientPool.RemoveClientAsync(accountId); + } + private static AccountInfo MapToAccountInfo(int accountId, WTelegram.Client client) { var user = client.User!; diff --git a/src/TelegramPanel.Web/Components/Pages/AccountLogin.razor b/src/TelegramPanel.Web/Components/Pages/AccountLogin.razor index f3ce6e6..0a7d086 100644 --- a/src/TelegramPanel.Web/Components/Pages/AccountLogin.razor +++ b/src/TelegramPanel.Web/Components/Pages/AccountLogin.razor @@ -156,8 +156,20 @@ _ => "下一步" }; - private Task ResetAsync() + private async Task ResetAsync() { + if (accountId != 0) + { + try + { + await AccountService.ReleaseClientAsync(accountId); + } + catch + { + // 忽略释放失败,避免影响 UI 重置 + } + } + accountId = 0; phoneNumber = ""; verificationCode = ""; @@ -165,7 +177,6 @@ username = ""; userId = 0; currentStep = LoginStep.Phone; - return Task.CompletedTask; } private Task PreviousAsync() @@ -374,6 +385,18 @@ // 跳转到完成步骤 currentStep = LoginStep.Done; + + if (accountId != 0) + { + try + { + await AccountService.ReleaseClientAsync(accountId); + } + catch + { + // 忽略释放失败 + } + } } catch (Exception ex) {