|
|
@@ -1508,10 +1508,14 @@ class AnimeController extends BaseController
|
|
|
$segments = DB::table('mp_episode_segments')
|
|
|
->where('anime_id', $animeId)
|
|
|
->where('episode_id', $episodeId)
|
|
|
- ->whereNotNull('pic_task_id')
|
|
|
+ ->where('pic_task_id', '!=', '')
|
|
|
->orderBy('segment_number')
|
|
|
->select('segment_id', 'segment_number', 'pic_task_id', 'pic_task_status', 'img_url', 'audio_url')
|
|
|
->get();
|
|
|
+
|
|
|
+ // 判断是否有未完成的任务
|
|
|
+ $count = DB::table('mp_episode_segments')->where('anime_id', $animeId)
|
|
|
+ ->where('episode_id', $episodeId)->where('pic_task_id', '<>', '')->whereNotIn('pic_task_status', ['已完成', '失败'])->count('id');
|
|
|
|
|
|
if ($segments->isEmpty()) {
|
|
|
Utils::throwError('20003:未找到分镜任务数据');
|
|
|
@@ -1522,7 +1526,27 @@ class AnimeController extends BaseController
|
|
|
$checkInterval = 5; // 每5秒检查一次
|
|
|
|
|
|
// 设置 SSE 响应头并开始长连接
|
|
|
- return response()->stream(function () use ($segments, $animeId, $episodeId, $startTime, $maxDuration, $checkInterval) {
|
|
|
+ return response()->stream(function () use ($segments, $animeId, $episodeId, $startTime, $maxDuration, $checkInterval, $count) {
|
|
|
+
|
|
|
+ if ($count == 0) {
|
|
|
+ $completedCount = DB::table('mp_episode_segments')->where('anime_id', $animeId)->where('episode_id', $episodeId)->where('pic_task_id', '<>', '')->where('pic_task_status', '已完成')->count('id');
|
|
|
+ echo "data: " . json_encode([
|
|
|
+ 'type' => 'completed',
|
|
|
+ 'data' => [
|
|
|
+ 'anime_id' => $animeId,
|
|
|
+ 'episode_id' => $episodeId,
|
|
|
+ 'completed_count' => $completedCount, // 成功完成的数量
|
|
|
+ 'processed_count' => count($segments), // 已处理完成的数量(成功+失败)
|
|
|
+ 'total_count' => count($segments),
|
|
|
+ 'total_elapsed_time' => time() - $startTime,
|
|
|
+ 'episode_info' => $episode ?? null
|
|
|
+ ]
|
|
|
+ ]) . "\n\n";
|
|
|
+ ob_flush();
|
|
|
+ flush();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 发送初始任务信息
|
|
|
echo "data: " . json_encode([
|
|
|
'type' => 'init',
|