fix(artifacts): improve video previews - #298
Conversation
Summary by CodeRabbit
WalkthroughThe change adds AVI and MKV MIME detection and extension-based video classification. Local media previews request resource URLs before applying the 16 MiB inline limit. A dedicated video preview component handles playback errors, reports resource errors, and offers a system-application action. English and Chinese localization messages describe unsupported video formats or codecs. Tests cover MIME mapping, artifact classification, and large-video resource leases. Sequence Diagram(s)sequenceDiagram
participant ArtifactConsumablePreview
participant ArtifactVideoPreview
participant ResourceErrorHandler
participant SystemApplication
ArtifactConsumablePreview->>ArtifactVideoPreview: provide video source
ArtifactVideoPreview->>ArtifactVideoPreview: render video controls
ArtifactVideoPreview->>ResourceErrorHandler: report playback error
ArtifactVideoPreview->>SystemApplication: open unsupported video
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/routes/Chat/ArtifactPreviewPane.tsx`:
- Around line 452-454: Update the video error handling associated with the
source-reset effect and preview failure state to distinguish codec errors from
resource errors: map MEDIA_ERR_SRC_NOT_SUPPORTED to
artifacts.videoCodecUnsupported, while using the generic resource-error message
for network and other loading failures. Preserve the cache’s existing
one-reload-per-preview-key behavior and avoid adding an indefinite reload loop.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 673e12df-49b6-461f-8168-b37b1d86974b
📒 Files selected for processing (9)
electron/chat/artifacts.test.tselectron/chat/artifacts.tselectron/chat/previews.test.tselectron/chat/previews.tssrc/i18n/app-messages.en.tssrc/i18n/app-messages.zh.tssrc/routes/Chat/ArtifactPreviewPane.tsxsrc/routes/Chat/GeneratedArtifacts.test.tssrc/routes/Chat/artifact-metadata.ts
Summary
Wanta already rendered video artifacts with Chromium's native video element, but the main-process preview path rejected every audio or video file larger than 16 MiB before it could receive a streamable artifact URL. In practice, that made ordinary video outputs appear unsupported even though the custom resource protocol already supports byte ranges.
This change allows large media files to use the existing leased
wanta-resourcestream while preserving the size limit for the Base64 fallback path. It also recognizes AVI and MKV MIME types, falls back to common video filename extensions when MIME metadata is generic, and replaces a permanently broken video element with a localized codec/format error state that still lets the user open the file in a system application.No player or transcoding dependency is added. Chromium continues to provide the playback controls and codec support, so formats such as MKV, AVI, MOV, or HEVC are attempted but remain dependent on the codecs available in the packaged Electron runtime.
Verification
pnpm run lintpnpm run ts-checkpnpm test— 283 test files and 2144 tests passedgit diff --checkAdded regression coverage for large resource-backed MP4 previews, AVI/MKV MIME detection, and extension-based video recognition when MIME metadata is generic.
Safety and Compatibility