fix(video): refine transcript viewing and generation

This commit is contained in:
yiling
2026-12-03 16:00:41 +08:00
parent 5daa2a8f92
commit 543862ff9b
8 changed files with 67 additions and 25 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- **sessions**: See total tokens and estimated cost in the session logs footer, with a breakdown of input, output, and cached tokens.
- **projects**: Middle-click or Command/Ctrl-click a project to open it in a new tab. Use **Open in new tab** in a file or folder's context menu to keep your current view open.
- **video**: Use **Generate Transcripts** in a video's context menu to save a transcript with the local embedding server. Choose a language or let the server detect it automatically.
- **video**: Use **Generate Transcripts** in a video's context menu to save a transcript with the local embedding server. Choose a language or let the server detect it automatically. The dialog closes when the transcript is ready.
- **video**: Open saved transcripts from the video player, switch languages, search the text, and jump to the exact start of a segment by selecting it. Follow along as the video plays.
### Fixed
@@ -7,6 +7,7 @@ test('reads, searches and follows a saved transcript in the video player', async
prisma,
}) => {
const { page, projectId, fileId } = file
await page.setViewportSize({ width: 1280, height: 720 })
await expect
.poll(() =>
prisma.asset.findUnique({
@@ -58,8 +59,12 @@ test('reads, searches and follows a saved transcript in the video player', async
const video = page.locator('video').first()
const sync = panel.getByRole('button', { name: 'Sync to playback' })
await expect(navigator).toBeHidden()
await expect(panel).toHaveCSS('width', '384px')
await expect(toggle).toHaveAttribute('aria-expanded', 'true')
await expect(toggle).toHaveCSS('cursor', 'pointer')
await expect(first).toHaveAttribute('aria-current', 'true')
await expect(first.getByText('Signal. signal.', { exact: true })).toHaveCSS('font-weight', '700')
await expect(first).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
await expect(first).toContainText('00:00.000 – 00:00.180')
await panel.getByRole('button', { name: 'Search transcript' }).click()
@@ -67,6 +72,9 @@ test('reads, searches and follows a saved transcript in the video player', async
await expect(search).toBeFocused()
await search.fill('SIGNAL.')
await expect(panel.getByText('1 / 3')).toBeVisible()
const match = panel.locator('[data-current-match]')
await expect(match).toHaveCSS('padding-left', '1px')
await expect(match).toHaveCSS('padding-right', '1px')
await panel.getByRole('button', { name: 'Next match' }).click()
await expect(panel.getByText('2 / 3')).toBeVisible()
await search.press('Enter')
@@ -1,5 +1,6 @@
import { expect, test } from '../../fixtures'
import { fileCard } from '../../helpers/files'
import type { TranscriptJobStatus } from '@shumai/dtos'
test.use({ fileOptions: { mediaType: 'video' } })
@@ -8,7 +9,9 @@ test('selects a transcription language from the video context menu and tracks th
prisma,
}) => {
const { page, projectId, fileId, fileName } = file
let submitted = false
let status: TranscriptJobStatus = { taskId: 'previous-transcript', status: 'completed' }
const expectedLanguages = ['zh', 'en']
let submissions = 0
await page.route('**/api/signup-info', async (route) => {
const response = await route.fetch()
await route.fulfill({ json: { ...(await response.json()), transcriptionEnabled: true } })
@@ -25,15 +28,13 @@ test('selects a transcription language from the video context menu and tracks th
}),
)
await page.route(`**/api/files/${fileId}/transcription-status`, (route) =>
route.fulfill({
body: JSON.stringify(submitted ? { taskId: 'transcript-task', status: 'completed' } : null),
contentType: 'application/json',
}),
route.fulfill({ json: status }),
)
await page.route(`**/api/files/${fileId}/transcripts`, async (route) => {
expect(route.request().postDataJSON()).toEqual({ language: 'zh' })
submitted = true
await route.fulfill({ status: 202, json: { kind: 'queued', taskId: 'transcript-task' } })
expect(route.request().postDataJSON()).toEqual({ language: expectedLanguages[submissions] })
const taskId = `transcript-task-${++submissions}`
status = { taskId, status: 'processing' }
await route.fulfill({ status: 202, json: { kind: 'queued', taskId } })
})
await expect
@@ -49,14 +50,32 @@ test('selects a transcription language from the video context menu and tracks th
page.goto(`/projects/${projectId}`),
])
expect(await signupInfo.json()).toMatchObject({ transcriptionEnabled: true })
await fileCard(page, fileName).click({ button: 'right' })
await page.getByRole('menuitem', { name: 'Generate Transcripts' }).click()
const openDialog = async () => {
await fileCard(page, fileName).click({ button: 'right' })
await page.getByRole('menuitem', { name: 'Generate Transcripts' }).click()
}
await openDialog()
const dialog = page.getByRole('dialog', { name: 'Generate Transcripts' })
const language = dialog.getByRole('combobox', { name: 'Language' })
const generate = dialog.getByRole('button', { name: 'Generate', exact: true })
await expect(dialog.getByRole('status')).toHaveText('Transcript generated.')
await expect(language).toHaveValue('Auto')
await language.fill('Chi')
await dialog.getByRole('option', { name: 'Chinese' }).click()
await expect(language).toHaveValue('Chinese')
await dialog.getByRole('button', { name: 'Generate', exact: true }).click()
await expect(dialog.getByRole('status')).toHaveText('Transcript generated.')
await generate.click()
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
await dialog.getByRole('button', { name: 'Close', exact: true }).click()
await expect(dialog).toBeHidden()
status = { taskId: status.taskId, status: 'completed' }
await openDialog()
await expect(generate).toBeEnabled()
await language.fill('Eng')
await dialog.getByRole('option', { name: 'English' }).click()
await generate.click()
await expect(dialog.getByRole('status')).toHaveText('Generating transcript…')
status = { taskId: status.taskId, status: 'completed' }
await expect(dialog).toBeHidden()
await expect(page.getByText('Transcript generated.', { exact: true })).toBeVisible()
})
@@ -164,6 +164,7 @@ export function FileBrowser({
const [contextMenuItem, setContextMenuItem] = useState<AssetInfo | null>(null)
const [similarImage, setSimilarImage] = useState<AssetInfo | null>(null)
const [transcriptVideo, setTranscriptVideo] = useState<{ id: string; name: string } | null>(null)
const closeTranscriptDialog = useCallback(() => setTranscriptVideo(null), [])
const transcriptionEnabled = useServerFeatures().data?.transcriptionEnabled
const semanticSearchEnabled = useSemanticSearchEnabled(
teamId,
@@ -1196,7 +1197,7 @@ export function FileBrowser({
key={transcriptVideo.id}
assetId={transcriptVideo.id}
name={transcriptVideo.name}
onClose={() => setTranscriptVideo(null)}
onClose={closeTranscriptDialog}
/>
)}
@@ -54,6 +54,7 @@ export function GenerateTranscriptsDialog({
onClose: () => void
}) {
const dialogRef = useRef<HTMLDivElement>(null)
const activeTaskId = useRef<string>(undefined)
const queryClient = useQueryClient()
const [language, setLanguage] = useState('')
const param = { fileId: assetId }
@@ -79,12 +80,24 @@ export function GenerateTranscriptsDialog({
},
refetchInterval: (query) => (isActive(query.state.data) ? 2_000 : false),
})
const hasFreshJobStatus = job.isFetchedAfterMount && job.isSuccess
useEffect(() => {
if (job.data?.status === 'completed') {
void queryClient.invalidateQueries({ queryKey: savedTranscriptLanguagesKey(assetId) })
if (!job.data) return
if (isActive(job.data)) {
// Reopening the dialog can briefly show a cached status for a finished job.
if (hasFreshJobStatus) activeTaskId.current = job.data.taskId
return
}
}, [assetId, job.data, queryClient])
if (job.data.status !== 'completed') return
void queryClient.invalidateQueries({ queryKey: savedTranscriptLanguagesKey(assetId) })
if (activeTaskId.current === job.data.taskId) {
activeTaskId.current = undefined
toast.success(m.transcript_completed())
onClose()
}
}, [assetId, hasFreshJobStatus, job.data, onClose, queryClient])
const generate = useMutation({
mutationFn: async () => {
@@ -105,6 +118,7 @@ export function GenerateTranscriptsDialog({
)
return
}
activeTaskId.current = result.taskId
queryClient.setQueryData<TranscriptJobStatus>(statusKey, {
status: 'pending',
taskId: result.taskId,
@@ -74,10 +74,7 @@ const SegmentRow = memo(function SegmentRow({
<button
type="button"
aria-current={active ? 'true' : undefined}
className={cn(
'block w-full cursor-pointer select-text rounded-md px-3 py-2 text-start hover:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:outline-none',
active && 'bg-primary/10 font-medium text-foreground',
)}
className="block w-full cursor-pointer select-text rounded-md px-3 py-2 text-start hover:bg-accent focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring focus-visible:outline-none"
onClick={(event) => {
const selection = window.getSelection()
if (
@@ -95,7 +92,10 @@ const SegmentRow = memo(function SegmentRow({
{formatTranscriptTime(segment.startMs)} – {formatTranscriptTime(segment.endMs)}
</span>
<span
className="block text-sm leading-relaxed whitespace-pre-wrap wrap-anywhere"
className={cn(
'block text-sm leading-relaxed whitespace-pre-wrap wrap-anywhere',
active && 'font-bold text-primary',
)}
dir="auto"
>
{matches?.map((match) => {
@@ -108,7 +108,7 @@ const SegmentRow = memo(function SegmentRow({
<mark
data-current-match={selected ? '' : undefined}
className={cn(
'rounded-sm bg-primary/15 text-foreground',
'rounded-sm bg-primary/15 px-px text-foreground',
selected && 'bg-primary text-primary-foreground',
)}
>
@@ -19,7 +19,7 @@ export function TranscriptToggleButton({
aria-controls={open ? panelId : undefined}
title={m.transcript_view()}
className={cn(
'shrink-0 rounded transition-colors hover:text-primary focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none',
'shrink-0 cursor-pointer rounded transition-colors hover:text-primary focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none',
open && 'text-primary',
className,
)}
@@ -863,7 +863,7 @@ function FileViewPage() {
key={transcript.panel.assetId}
{...transcript.panel}
mediaControllerRef={mediaControllerRef}
className="w-[clamp(16rem,26vw,22rem)] max-w-[48%] border-r border-border"
className="w-[30vw] max-w-[48%] border-r border-border"
/>
)}
<div className={transcript?.panel ? 'hidden' : 'contents'}>