From eec251ab827c71c260902be451b915ab572fecb2 Mon Sep 17 00:00:00 2001 From: meoacgx Date: Tue, 3 Mar 2026 00:47:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(export):=20=E7=94=9F=E6=88=90=20tdata=20?= =?UTF-8?q?=E6=97=B6=E5=86=99=E5=85=A5=E8=B4=A6=E5=8F=B7=20user=5Fid?= =?UTF-8?q?=EF=BC=8C=E4=BF=AE=E5=A4=8D=E6=A1=8C=E9=9D=A2=E7=AB=AF=E4=BB=8D?= =?UTF-8?q?=E8=A6=81=E6=B1=82=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Telethon->tdata 桥接脚本新增 userId 参数并注入 session.self.userId\n- AccountExportService 调用转换时传入当前账号 UserId\n- 避免 @mtcute/convert 默认写入 userId=0 导致 Telegram Desktop 识别为未登录 --- .../Services/Telegram/TdataSessionBridge.cs | 15 +++++++++++++-- .../Services/AccountExportService.cs | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/TelegramPanel.Core/Services/Telegram/TdataSessionBridge.cs b/src/TelegramPanel.Core/Services/Telegram/TdataSessionBridge.cs index 4311a74..70683a1 100644 --- a/src/TelegramPanel.Core/Services/Telegram/TdataSessionBridge.cs +++ b/src/TelegramPanel.Core/Services/Telegram/TdataSessionBridge.cs @@ -43,11 +43,21 @@ try { private const string NodeScriptTelethonToTdata = """ import { convertFromTelethonSession, convertToTdata } from '@mtcute/convert'; -const telethonSession = process.argv[process.argv.length - 2]; +const telethonSession = process.argv[process.argv.length - 3]; +const userIdRaw = process.argv[process.argv.length - 2]; const outputDir = process.argv[process.argv.length - 1]; try { const session = convertFromTelethonSession(telethonSession); + const userId = Number.parseInt(userIdRaw, 10); + if (Number.isFinite(userId) && userId > 0) { + session.self = { + userId, + isBot: false, + isPremium: false, + usernames: [], + }; + } await convertToTdata(session, { path: outputDir }); console.log(JSON.stringify({ ok: true })); } catch (error) { @@ -141,6 +151,7 @@ try { public static async Task TryConvertTelethonStringSessionToTdataAsync( string telethonSessionString, + long? userId, string outputTdataDirectory, ILogger logger, CancellationToken cancellationToken = default) @@ -164,7 +175,7 @@ try { var run = await RunProcessAsync( fileName: "node", - arguments: new[] { "--input-type=module", "-e", NodeScriptTelethonToTdata, "--", normalizedSession, absoluteOutputDir }, + arguments: new[] { "--input-type=module", "-e", NodeScriptTelethonToTdata, "--", normalizedSession, (userId ?? 0).ToString(), absoluteOutputDir }, workingDirectory: RuntimeDir, timeoutMs: ConvertTimeoutMs, cancellationToken: cancellationToken); diff --git a/src/TelegramPanel.Web/Services/AccountExportService.cs b/src/TelegramPanel.Web/Services/AccountExportService.cs index 867c9d6..73e6fb6 100644 --- a/src/TelegramPanel.Web/Services/AccountExportService.cs +++ b/src/TelegramPanel.Web/Services/AccountExportService.cs @@ -177,6 +177,7 @@ public class AccountExportService var tdataResult = await TdataSessionBridge.TryConvertTelethonStringSessionToTdataAsync( telethonSessionString: telethonResult.SessionString, + userId: account.UserId > 0 ? account.UserId : null, outputTdataDirectory: tempTdataDir, logger: _logger, cancellationToken: cancellationToken);