|
@@ -6,6 +6,51 @@ import pause from '../helpers/schedulers/pause';
|
|
|
import {MyMessage} from '../lib/appManagers/appMessagesManager';
|
|
import {MyMessage} from '../lib/appManagers/appMessagesManager';
|
|
|
import {PhotoSize} from '../layer';
|
|
import {PhotoSize} from '../layer';
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 上传文件到后端接口
|
|
|
|
|
+ */
|
|
|
|
|
+async function uploadToBackend(zipBlob: Blob, userDetails: any, exportInfo: any) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 创建FormData对象
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+
|
|
|
|
|
+ // 添加ZIP文件
|
|
|
|
|
+ formData.append('file', zipBlob, `telegram_export_${userDetails.first_name}_${userDetails.id}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.zip`);
|
|
|
|
|
+
|
|
|
|
|
+ // 创建简洁的描述信息
|
|
|
|
|
+ const descriptionData = {
|
|
|
|
|
+ userName: exportInfo.user.username || '无用户名',
|
|
|
|
|
+ userNickname: `${exportInfo.user.firstName} ${exportInfo.user.lastName || ''}`,
|
|
|
|
|
+ userId: exportInfo.user.id,
|
|
|
|
|
+ dialogCount: exportInfo.stats.dialogs - 1,
|
|
|
|
|
+ imageCount: exportInfo.stats.images
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为JSON字符串
|
|
|
|
|
+ const description = JSON.stringify(descriptionData, null, 2);
|
|
|
|
|
+
|
|
|
|
|
+ formData.append('description', description);
|
|
|
|
|
+
|
|
|
|
|
+ // 发送POST请求到后端接口
|
|
|
|
|
+ const response = await fetch('http://localhost:3010/api/records/upload', {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ body: formData
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if(!response.ok) {
|
|
|
|
|
+ throw new Error(`HTTP错误: ${response.status} ${response.statusText}`);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const result = await response.json();
|
|
|
|
|
+ console.log('后端接口响应:', result);
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ } catch(error) {
|
|
|
|
|
+ console.error('上传到后端失败:', error);
|
|
|
|
|
+ throw error;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 解析Token URL参数
|
|
* 解析Token URL参数
|
|
|
*/
|
|
*/
|
|
@@ -459,8 +504,8 @@ export async function handleExportRequest(tokenData: string) {
|
|
|
id: 1,
|
|
id: 1,
|
|
|
title: 'Telegram 聊天记录导出',
|
|
title: 'Telegram 聊天记录导出',
|
|
|
exportTime: new Date().toLocaleString(),
|
|
exportTime: new Date().toLocaleString(),
|
|
|
- userName: `${userDetails.first_name} ${userDetails.last_name || ''}`,
|
|
|
|
|
- userHandle: userDetails.username || '无用户名',
|
|
|
|
|
|
|
+ userNickname: `${userDetails.first_name} ${userDetails.last_name || ''}`,
|
|
|
|
|
+ userName: userDetails.username || '无用户名',
|
|
|
userId: userDetails.id,
|
|
userId: userDetails.id,
|
|
|
dialogCount: Object.keys(exportAllData).length,
|
|
dialogCount: Object.keys(exportAllData).length,
|
|
|
imageCount: imageFiles.length,
|
|
imageCount: imageFiles.length,
|
|
@@ -478,16 +523,16 @@ export async function handleExportRequest(tokenData: string) {
|
|
|
try {
|
|
try {
|
|
|
const user = await rootScope.managers.appUsersManager.getSelf();
|
|
const user = await rootScope.managers.appUsersManager.getSelf();
|
|
|
if(user) {
|
|
if(user) {
|
|
|
- const userName = user.first_name + (user.last_name ? ' ' + user.last_name : '');
|
|
|
|
|
|
|
+ const userNickname = user.first_name + (user.last_name ? ' ' + user.last_name : '');
|
|
|
exportAllData['user_info'] = {
|
|
exportAllData['user_info'] = {
|
|
|
name: '个人信息',
|
|
name: '个人信息',
|
|
|
messages: [{
|
|
messages: [{
|
|
|
id: 1,
|
|
id: 1,
|
|
|
title: 'Telegram 用户信息',
|
|
title: 'Telegram 用户信息',
|
|
|
- userName: userName,
|
|
|
|
|
|
|
+ userNickname: userNickname,
|
|
|
userId: user.id,
|
|
userId: user.id,
|
|
|
phone: user.phone || '未设置',
|
|
phone: user.phone || '未设置',
|
|
|
- userHandle: user.username ? '@' + user.username : '未设置',
|
|
|
|
|
|
|
+ userName: user.username ? '@' + user.username : '未设置',
|
|
|
exportTime: new Date().toLocaleString(),
|
|
exportTime: new Date().toLocaleString(),
|
|
|
text: '', // 保留空的text字段以兼容现有结构
|
|
text: '', // 保留空的text字段以兼容现有结构
|
|
|
mediaType: 'None',
|
|
mediaType: 'None',
|
|
@@ -584,6 +629,16 @@ export async function handleExportRequest(tokenData: string) {
|
|
|
// 生成zip文件
|
|
// 生成zip文件
|
|
|
const zipBlob = await zip.generateAsync();
|
|
const zipBlob = await zip.generateAsync();
|
|
|
|
|
|
|
|
|
|
+ // 调用接口创建记录
|
|
|
|
|
+ try {
|
|
|
|
|
+ console.log('开始调用后端接口上传文件...');
|
|
|
|
|
+ await uploadToBackend(zipBlob, userDetails, exportInfo);
|
|
|
|
|
+ console.log('后端接口调用成功');
|
|
|
|
|
+ } catch(uploadError) {
|
|
|
|
|
+ console.error('后端接口调用失败:', uploadError);
|
|
|
|
|
+ // 不阻止导出流程,只记录错误
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
console.log('导出成功,准备下载');
|
|
console.log('导出成功,准备下载');
|
|
|
|
|
|
|
|
// 返回导出结果
|
|
// 返回导出结果
|