docs(modules): 补充账号数据包导出调用说明与 tdata 关键注意事项
- 新增模块复用 AccountExportService 的推荐方式\n- 补充 /downloads/accounts.zip 参数与鉴权/缓存注意\n- 记录 tdata 导出稳定条件:padding、user_id 注入、已授权 DCSession 选择\n- 便于后续模块实现按账号下载 telethon/tdata 数据包
This commit is contained in:
1 parent
eec251ab82
commit
a4669f8561
1 file changed
+45
@@ -257,6 +257,51 @@ public sealed class MyHandler : IModuleTaskHandler
|
||||
}
|
||||
```
|
||||
|
||||
## 账号导出下载(Telethon / Tdata)
|
||||
|
||||
如果模块需要“下载某个账号的数据包”,建议优先使用宿主服务直接生成 Zip(同进程内调用),避免绕 HTTP 鉴权与 Cookie。
|
||||
|
||||
### 推荐方式:模块内直接调用导出服务
|
||||
|
||||
可注入:
|
||||
|
||||
- `TelegramPanel.Web.Services.AccountExportService`
|
||||
- `TelegramPanel.Core.Services.AccountManagementService`
|
||||
|
||||
核心调用链:
|
||||
|
||||
1. 先通过 `AccountManagementService` 获取目标账号(或账号列表)
|
||||
2. 调用 `AccountExportService.BuildAccountsZipAsync(accounts, ct, format)`
|
||||
3. 将 `byte[]` 按模块自己的场景返回/落盘/上传
|
||||
|
||||
其中 `format`:
|
||||
|
||||
- `AccountExportFormat.Telethon`:导出 `.json + .session (+2fa.txt)`
|
||||
- `AccountExportFormat.Tdata`:在以上基础上额外导出 `tdata/`
|
||||
|
||||
### HTTP 方式(备选)
|
||||
|
||||
宿主现有下载接口:
|
||||
|
||||
- `GET /downloads/accounts.zip`
|
||||
- Query:
|
||||
- `ids=1,2,3`(可选,不传则导出全部)
|
||||
- `format=telethon|tdata`(不传默认 `telethon`)
|
||||
- `ts=<timestamp>`(可选,建议带上,避免浏览器缓存旧包)
|
||||
|
||||
注意:
|
||||
|
||||
- 若开启后台登录,接口受登录态保护(需带管理端 Cookie)
|
||||
- 响应已设置 `no-store/no-cache`,但调用方仍建议加 `ts`
|
||||
|
||||
### Tdata 导出的实现要点(后续扩展必须保持)
|
||||
|
||||
1. `session -> telethon string` 时必须保留 Base64 padding(尾部 `=`)
|
||||
2. `telethon string -> tdata` 时必须注入 `session.self.userId`
|
||||
3. 生成 `telethon string` 时要优先选择“已授权 DCSession”(不是任意 DC)
|
||||
|
||||
否则会出现“包结构看似正常,但 Telegram Desktop 仍要求重新登录”。
|
||||
|
||||
## UI 模块项目模板(Razor 组件)
|
||||
|
||||
如果你的模块需要提供页面(`IModuleUiProvider.GetPages`),推荐把模块做成 `Microsoft.NET.Sdk.Razor` 项目(类似 Razor Class Library),例如:
|
||||
|
||||
Reference in new issue
Block a user