fix(video): transcribe archived videos and show progress (#560)

This commit is contained in:
Yiling-J
2026-12-04 15:37:58 +08:00
committed by GitHub
parent d3899d1257
commit 72a7f68c92
21 changed files with 408 additions and 171 deletions
@@ -1,4 +1,4 @@
import { prisma, WorkflowTaskType } from '@shumai/db'
import { prisma, WorkflowTaskStatus, WorkflowTaskType } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { transcriptionErrors } from '@shumai/dtos'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
@@ -177,6 +177,85 @@ describe('TranscriptService', () => {
expect(await prisma.workflowTask.count({ where: { assetId } })).toBe(0)
})
it.each(['archiving', 'archived', 'restoring'] as const)(
'queues generation from a full proxy while the video is %s',
async (status) => {
await prisma.asset.update({ where: { id: assetId }, data: { status } })
await expect(transcriptService.generate(assetId, 'en')).resolves.toMatchObject({
kind: 'queued',
})
},
)
it('lists each live project file with a pending or running transcription once', async () => {
const project = await prisma.project.findUniqueOrThrow({ where: { id: projectId } })
const otherProject = await prisma.project.create({
data: { name: 'Another project', teamId: project.teamId },
})
const [running, finished, deleted, external, transcoding] = await Promise.all(
[
{ projectId, name: 'Running video' },
{ projectId, name: 'Finished video' },
{ projectId, name: 'Deleted video', isDeleted: true },
{ projectId: otherProject.id, name: 'External video' },
{ projectId, name: 'Transcoding video' },
].map((file) =>
prisma.asset.create({ data: { ...file, type: 'file', status: 'processed' } }),
),
)
await expect(transcriptService.listActiveAssetIds(projectId)).resolves.toEqual([])
await prisma.workflowTask.createMany({
data: [
{ assetId, status: WorkflowTaskStatus.pending },
{ assetId, status: WorkflowTaskStatus.processing },
{ assetId, status: WorkflowTaskStatus.failed },
{ assetId: running.id, status: WorkflowTaskStatus.processing },
{ assetId: finished.id, status: WorkflowTaskStatus.completed },
{ assetId: finished.id, status: WorkflowTaskStatus.failed },
{ assetId: deleted.id, status: WorkflowTaskStatus.pending },
{ assetId: external.id, status: WorkflowTaskStatus.processing },
{
assetId: transcoding.id,
status: WorkflowTaskStatus.pending,
type: WorkflowTaskType.transcode_video,
},
].map((job) => ({ type: WorkflowTaskType.ai_transcription, ...job })),
})
await expect(transcriptService.listActiveAssetIds(projectId)).resolves.toEqual(
[assetId, running.id].sort().reverse(),
)
await expect(transcriptService.listActiveAssetIds(otherProject.id)).resolves.toEqual([
external.id,
])
})
it('rejects an archived video without a full proxy', async () => {
await prisma.asset.update({
where: { id: assetId },
data: { status: 'archived', media: { ...media, videoTranscodes: [] } },
})
await expect(transcriptService.generate(assetId, 'en')).rejects.toMatchObject({
status: 400,
message: transcriptionErrors.noProxy,
})
expect(await prisma.workflowTask.count({ where: { assetId } })).toBe(0)
})
it.each(['archiving', 'archived', 'restoring'] as const)(
'saves a transcript when the video has become %s while the job runs',
async (status) => {
const taskId = await generateAndStart('en')
await prisma.asset.update({ where: { id: assetId }, data: { status } })
await expect(
transcriptService.saveResult({ taskId, assetId, model, language: 'en', segments }),
).resolves.toBe(true)
await expect(transcriptService.getSavedTranscript(assetId, 'en')).resolves.toMatchObject({
segments,
})
},
)
it('rejects an audio-only proxy even when the file was uploaded with a video MIME type', async () => {
await prisma.asset.update({
where: { id: assetId },