|
@@ -1,5 +1,5 @@
|
|
|
import schedule from 'node-schedule';
|
|
import schedule from 'node-schedule';
|
|
|
-import { AppDataSource, PublishTask, PlatformAccount, AnalyticsData } from '../models/index.js';
|
|
|
|
|
|
|
+import { AppDataSource, PublishTask, PublishResult, PlatformAccount, AnalyticsData } from '../models/index.js';
|
|
|
import { logger } from '../utils/logger.js';
|
|
import { logger } from '../utils/logger.js';
|
|
|
import { wsManager } from '../websocket/index.js';
|
|
import { wsManager } from '../websocket/index.js';
|
|
|
import { WS_EVENTS } from '@media-manager/shared';
|
|
import { WS_EVENTS } from '@media-manager/shared';
|
|
@@ -170,6 +170,7 @@ export class TaskScheduler {
|
|
|
private async executePublishTask(task: PublishTask): Promise<void> {
|
|
private async executePublishTask(task: PublishTask): Promise<void> {
|
|
|
const taskRepository = AppDataSource.getRepository(PublishTask);
|
|
const taskRepository = AppDataSource.getRepository(PublishTask);
|
|
|
const accountRepository = AppDataSource.getRepository(PlatformAccount);
|
|
const accountRepository = AppDataSource.getRepository(PlatformAccount);
|
|
|
|
|
+ const resultRepository = AppDataSource.getRepository(PublishResult);
|
|
|
|
|
|
|
|
const targetAccounts = task.targetAccounts || [];
|
|
const targetAccounts = task.targetAccounts || [];
|
|
|
const accounts = await accountRepository.find({
|
|
const accounts = await accountRepository.find({
|
|
@@ -188,7 +189,7 @@ export class TaskScheduler {
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
const adapter = getAdapter(account.platform);
|
|
const adapter = getAdapter(account.platform);
|
|
|
- const result = await adapter.publishVideo(account.cookieData || '', {
|
|
|
|
|
|
|
+ const publishResult = await adapter.publishVideo(account.cookieData || '', {
|
|
|
videoPath: task.videoPath || '',
|
|
videoPath: task.videoPath || '',
|
|
|
title: task.title || '',
|
|
title: task.title || '',
|
|
|
description: task.description || undefined,
|
|
description: task.description || undefined,
|
|
@@ -196,17 +197,38 @@ export class TaskScheduler {
|
|
|
tags: task.tags || undefined,
|
|
tags: task.tags || undefined,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- if (result.success) {
|
|
|
|
|
|
|
+ // 保存发布结果到 publish_results 表
|
|
|
|
|
+ const publishResultRecord = new PublishResult();
|
|
|
|
|
+ publishResultRecord.taskId = task.id;
|
|
|
|
|
+ publishResultRecord.accountId = account.id;
|
|
|
|
|
+ publishResultRecord.platform = account.platform;
|
|
|
|
|
+ publishResultRecord.status = publishResult.success ? 'success' : 'failed';
|
|
|
|
|
+ publishResultRecord.videoUrl = publishResult.videoUrl || null;
|
|
|
|
|
+ publishResultRecord.platformVideoId = publishResult.platformVideoId || null;
|
|
|
|
|
+ publishResultRecord.errorMessage = publishResult.error || null;
|
|
|
|
|
+ publishResultRecord.publishedAt = publishResult.success ? new Date() : null;
|
|
|
|
|
+ await resultRepository.save(publishResultRecord);
|
|
|
|
|
+
|
|
|
|
|
+ if (publishResult.success) {
|
|
|
successCount++;
|
|
successCount++;
|
|
|
} else {
|
|
} else {
|
|
|
failCount++;
|
|
failCount++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 更新发布结果
|
|
|
|
|
- // TODO: 更新 publish_results 表
|
|
|
|
|
-
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
logger.error(`Publish to ${account.platform} failed:`, error);
|
|
logger.error(`Publish to ${account.platform} failed:`, error);
|
|
|
|
|
+
|
|
|
|
|
+ // 保存失败结果到 publish_results 表
|
|
|
|
|
+ const errorMessage = error instanceof Error ? error.message : String(error);
|
|
|
|
|
+ const failedRecord = new PublishResult();
|
|
|
|
|
+ failedRecord.taskId = task.id;
|
|
|
|
|
+ failedRecord.accountId = account.id;
|
|
|
|
|
+ failedRecord.platform = account.platform;
|
|
|
|
|
+ failedRecord.status = 'failed';
|
|
|
|
|
+ failedRecord.errorMessage = errorMessage;
|
|
|
|
|
+ failedRecord.publishedAt = null;
|
|
|
|
|
+ await resultRepository.save(failedRecord);
|
|
|
|
|
+
|
|
|
failCount++;
|
|
failCount++;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|