From 146ce0845474f6ce9c8a343b377d375bc15d8cd0 Mon Sep 17 00:00:00 2001 From: meoacgx Date: Fri, 19 Dec 2025 17:08:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=AD=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=EF=BC=9A=E6=89=8B=E6=9C=BA=E5=8F=B7=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=90=8E=E9=87=8A=E6=94=BE=E5=AE=A2=E6=88=B7=E7=AB=AF=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=20session=20=E6=96=87=E4=BB=B6=E8=A2=AB?= =?UTF-8?q?=E5=8D=A0=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interfaces/IAccountService.cs | 5 ++++ .../Services/Telegram/AccountService.cs | 5 ++++ .../Components/Pages/AccountLogin.razor | 27 +++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) 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) {