|
|
@@ -211,35 +211,50 @@ router.post('/tasks', async (ctx) => {
|
|
|
}
|
|
|
|
|
|
const body = ctx.request.body as any;
|
|
|
- const { videoProjectId, platform, title, description, tags, coverUrl } = body;
|
|
|
+ const { videoProjectId, videoUrl, platform, title, description, tags, coverUrl } = body;
|
|
|
|
|
|
- if (!videoProjectId || !platform || !title) {
|
|
|
+ if (!platform || !title) {
|
|
|
ctx.status = 400;
|
|
|
ctx.body = { success: false, error: '缺少必要参数' };
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 获取视频项目信息
|
|
|
- const projectInfo = await getVideoProjectForPublish(videoProjectId);
|
|
|
- if (!projectInfo) {
|
|
|
- ctx.status = 404;
|
|
|
- ctx.body = { success: false, error: '视频项目不存在或未生成视频' };
|
|
|
+ // 支持两种方式:1. 使用 videoProjectId 2. 直接使用 videoUrl
|
|
|
+ let finalVideoUrl = videoUrl;
|
|
|
+ let finalDescription = description || '';
|
|
|
+ let finalCoverUrl = coverUrl;
|
|
|
+
|
|
|
+ if (videoProjectId) {
|
|
|
+ // 方式1:通过 videoProjectId 获取视频信息
|
|
|
+ const projectInfo = await getVideoProjectForPublish(videoProjectId);
|
|
|
+ if (!projectInfo) {
|
|
|
+ ctx.status = 404;
|
|
|
+ ctx.body = { success: false, error: '视频项目不存在或未生成视频' };
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ finalVideoUrl = projectInfo.videoUrl;
|
|
|
+ finalDescription = description || projectInfo.description;
|
|
|
+ finalCoverUrl = coverUrl || projectInfo.coverUrl;
|
|
|
+ } else if (!videoUrl) {
|
|
|
+ // 两种方式都没有
|
|
|
+ ctx.status = 400;
|
|
|
+ ctx.body = { success: false, error: '请提供 videoProjectId 或 videoUrl' };
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 创建发布任务
|
|
|
const task = await createPublishTask(userId, {
|
|
|
- videoProjectId,
|
|
|
+ videoProjectId: videoProjectId || 0, // 如果没有 projectId 则用 0
|
|
|
platform,
|
|
|
title,
|
|
|
- description: description || projectInfo.description,
|
|
|
+ description: finalDescription,
|
|
|
tags,
|
|
|
- coverUrl: coverUrl || projectInfo.coverUrl,
|
|
|
+ coverUrl: finalCoverUrl,
|
|
|
});
|
|
|
|
|
|
// 更新视频URL
|
|
|
const { updatePublishTask } = await import('./publish.service');
|
|
|
- await updatePublishTask(task.id!, { videoUrl: projectInfo.videoUrl });
|
|
|
+ await updatePublishTask(task.id!, { videoUrl: finalVideoUrl });
|
|
|
|
|
|
// 根据平台执行发布
|
|
|
let result: { success: boolean; publishedUrl?: string; error?: string };
|