Compare commits

...
15 Commits
Author SHA1 Message Date
yiling 29cd5d807c test(scripts): find release by version in changelog integration test 2026-09-24 20:34:53 +08:00
yiling f6e27095a5 Release v0.4.8 2026-09-24 20:26:23 +08:00
Yiling-J 55637bc9a8 feat(transcode): optimize video proxy quality and fix videotoolbox first-frame blocking (#426)
- Fix first-frame macroblocking on VideoToolbox hardware acceleration by avoiding -maxrate/-bufsize which triggers Apple's DataRateLimits initial rate controller starvation, applying target -b:v instead.
- Optimize software encoding (libx264) quality by adjusting CRF from 26 to 23.
- Disable B-frames (-bf 0) for libx264 proxies to ensure zero-latency frame stepping (JKL) and scrubbing, matching Frame.io review proxy standards.
- Update unit tests to verify the new encoder configurations and bitrate calculation logic.
2026-09-24 17:16:02 +08:00
Yiling-J 0d6671c3e1 fix(webui): show play button and darken tint only before initial playback (#425)
* fix(webui): remove paused play button overlay and darken cover from video players

* fix(webui): show play button and darken tint only before initial playback
2026-09-24 15:19:46 +08:00
Yiling-J c3375ee935 feat(transcode): add HDR video proxy support and playback (#424)
* feat(transcode): add HDR output proxy support

* fix(transcode): auto-detect MoltenVK Vulkan ICD on macOS for libplacebo filters

* fix(transcode): split filter in generateSprite to ensure poster uses tone-mapped stream

* docs(changelog): update docs/changelog.mdx and ignore in prettier

* fix(transcode): respect video rotation metadata to preserve display aspect ratio

* fix(webui): render native video with hardware EDR acceleration instead of 2D canvas

* fix(webui): show HDR label on mobile video control bar

* fix(share): preserve hdr flag on watermarked video transcodes

* fix(webui): differentiate HDR download options in video player

* fix(transcode): handle Dolby Vision Profile 5 via standard HDR pipeline without libplacebo

* fix(transcode): prepend setparams filter to prevent zscale colorspace path error for DV P5

* refactor(transcode): simplify HDR proxies to always produce HDR without SDR setting
2026-09-24 14:32:47 +08:00
Yiling-J f579947770 feat(docs): add changelog section to mintlify documentation (#422) 2026-09-22 21:02:27 +08:00
Yiling-J 53c9485f10 fix(core): only manage PID files in daemon mode (#421) 2026-09-22 20:31:38 +08:00
Yiling-J 75bf9b3b88 fix(docker): stop publishing postgres port in compose files (#420)
The bundled PostgreSQL service published port 5432 on the host, which caused
docker compose up to fail when that port was already in use. A failed start
leaves the container without a network endpoint, so subsequent runs reuse the
broken container and the app cannot reach the database (Prisma P1001).

The app only needs the database inside the compose network, so the host port
mapping is unnecessary. Remove it from all local and temporal compose files.
2026-09-20 11:46:13 +08:00
yiling 657cd761bc Release v0.4.7 2026-09-19 16:01:20 +08:00
Yiling-J de634a5dc5 feat(asset): show poster and hover preview while video is transcoding (#419)
* feat(asset): show poster and hover preview while video is transcoding

Generate and persist the sprite (and its poster) before the proxy
transcodes run, so the poster/sprite are available in the file list
while the asset is still processing.

Render the preview in the file card behind a translucent processing
overlay instead of a blank skeleton, and replace hardcoded status text
with existing i18n keys.

* feat(asset): pulse the cover and show Preparing/Uploading labels while processing

Drop the processing text overlay on the file card preview in favour of a
subtle pulsing opacity on the cover, and show "Uploading..."/"Preparing..."
in the creator row so the real author and date only appear once the asset
is ready.

* feat(asset): use a hollow ring for the preparing placeholder

Match the geometry of the upload progress ring (empty inside, no
percentage) and hide the duration badge while processing, so the
upload-to-processing transition reads as one continuous animation.

* style(asset): shrink-only preparing ring in muted grey at fixed opacity

Animate only the ring size (1 -> 0.8 -> 1) and hold a constant 0.6
opacity, using a muted grey stroke instead of primary.
2026-09-19 15:25:41 +08:00
Yiling-J 09b65a1eb6 feat(asset): Recently Deleted previews, retention countdown, and version stack delete/restore (#418)
* feat(asset): improve Recently Deleted previews and retention indicators

- Include soft-deleted children when building folder previews for the
  Recently Deleted view, and resolve deleted version stacks to their
  latest version so a trashed folder shows what was inside it.
- Add a "days left" badge (clock + Nd) to file and folder cards in the
  Recently Deleted view, placed to the left of the comments badge.
- Fix an issue where deleting or restoring a version stack from the file
  list did nothing because the WebUI dropped version_stack items before
  calling the API.
- Share the 30-day trash retention window through TRASH_RETENTION_DAYS.

* test(asset): use typed MediaInfo in recently-deleted preview tests

Replace the explicit any cast with a fully typed MediaInfo object so the new tests comply with the no-explicit-any policy.
2026-09-19 11:36:14 +08:00
Yiling-J b52b2ce7d8 fix(transcode): preserve trashed status during background jobs and handle permanent purge (#416)
* fix(transcode): preserve trashed status during background jobs and handle permanent purge

* fix(workflow): clear heartbeat and add info logs on task cancellation

* fix(transcode): terminate media processes and guard task activities on cancellation

- Pass AbortSignal to ffmpeg and pdftoppm child processes in transcodeService to terminate processes on task cancellation
- Add local task AbortController context and cancellation guards in executeActivity to prevent subsequent workflow activities
- Forward taskId and cancellation signals in transcode, screenshot, and PDF activities
- Use updateMany instead of update in task activities to eliminate Prisma P2025 errors on purged task records

* fix(workflow): allow cleanup activities in finally blocks during task cancellation

Remove blanket cancellation check in executeActivity so that workflows can execute cleanup and failure handling activities in catch and finally blocks upon cancellation, while relying on AbortSignal in active activities to abort execution.

* docs(changelog): improve user friendliness of changelog entries and formatting example

* docs(agents): update changelog guidelines to emphasize end-user friendly descriptions

* fix(transcode): handle queued cancellation and delete races in media workflow
2026-09-19 10:40:49 +08:00
Yiling-J 145aa6bfb4 fix(webui,core): center breadcrumb menu on chevron and fix proxy download filename (#417) 2026-09-18 23:14:54 +08:00
Yiling-J a91d8c4521 feat(settings): add FFmpeg threads setting for media processing (#415)
* feat(settings): add FFmpeg threads setting for media processing

* style(settings): add bottom padding to media processing page
2026-09-18 13:30:33 +08:00
Yiling-J 3a509537fd feat(changelog): add CHANGELOG.md, release extraction script, and developer guidelines (#414)
* feat(changelog): add CHANGELOG.md, release extraction script, and developer guidelines

* docs(agents): simplify changelog guidelines for brevity
2026-09-18 11:57:25 +08:00
103 changed files with 7164 additions and 449 deletions
+26 -2
View File
@@ -68,18 +68,42 @@ jobs:
- name: Build NPM packages
run: bun run build-npm
- name: Generate release notes
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
CHANGELOG_NOTES=$(bun run scripts/extract-changelog.ts "${{ env.RELEASE_TAG }}" 2>/dev/null || true)
PR_NOTES=$(gh api "repos/${{ github.repository }}/releases/generate-notes" -f tag_name="${{ env.RELEASE_TAG }}" --jq .body 2>/dev/null || true)
{
if [ -n "$CHANGELOG_NOTES" ]; then
echo "$CHANGELOG_NOTES"
echo ""
echo "---"
echo ""
fi
if [ -n "$PR_NOTES" ]; then
echo "$PR_NOTES"
fi
} > /tmp/release-notes.md
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ ! -s /tmp/release-notes.md ]; then
NOTES_FLAG="--generate-notes"
else
NOTES_FLAG="--notes-file /tmp/release-notes.md"
fi
if gh release view "${{ env.RELEASE_TAG }}" >/dev/null 2>&1; then
gh release edit "${{ env.RELEASE_TAG }}" \
--title "${{ env.RELEASE_TAG }}" \
--generate-notes
$NOTES_FLAG
else
gh release create "${{ env.RELEASE_TAG }}" \
--title "${{ env.RELEASE_TAG }}" \
--generate-notes
$NOTES_FLAG
fi
- name: Upgrade npm for trusted publishing
+2 -1
View File
@@ -7,4 +7,5 @@ packages/core/src/generated
src/ui/components/ui
packages/webui/paraglide
*.md
**/*.md
**/*.md
docs/changelog.mdx
+17 -3
View File
@@ -14,9 +14,10 @@ Complete the task on that branch.
After finishing the work and verifying that all checks pass:
1. Stage and commit your changes.
2. Push the branch to `origin`.
3. Open a pull request using the GitHub CLI.
1. Update `CHANGELOG.md` under `## [Unreleased]` for user-facing changes (see [Changelog Guidelines](#changelog-guidelines)).
2. Stage and commit your changes.
3. Push the branch to `origin`.
4. Open a pull request using the GitHub CLI.
```bash
git add .
@@ -61,6 +62,19 @@ https://www.conventionalcommits.org/en/v1.0.0/#summary
---
## Changelog Guidelines
We maintain `CHANGELOG.md` following [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
Before opening a pull request, add an entry under `## [Unreleased]` for any user-facing changes:
- **End-User Friendly**: Make entries easy to understand for end users. For new features, explain what they actually do in plain language without heavy technical jargon. For bug fixes, describe what the bug was in a friendly, relatable way rather than focusing on internal code mechanics, file paths, or private symbols.
- **Formatting**: `- **<scope>**: <Description>` (e.g. `- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status`).
- **No PR Numbers**: Do not include PR numbers or links; the release pipeline automatically appends the detailed PR list.
- **Internal Changes**: Routine refactors, test additions, or internal chores without external behavior changes may omit changelog updates.
---
## Pull Request Template
```md
+733
View File
@@ -0,0 +1,733 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
## [Unreleased]
### Added
### Fixed
### Changed
## [0.4.8] - 2026-09-24
### Added
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
### Fixed
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
### Changed
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
## [0.4.7] - 2026-09-19
### Added
- **changelog**: Introduce Keep a Changelog support, historical release summaries, and automated release notes extraction
- **release**: Automatically populate GitHub release bodies from CHANGELOG.md and promote unreleased notes during version bumps
- **settings**: Add FFmpeg threads slider to team media processing settings
- **asset**: Show previews of a folder's contents and a "days left" countdown for each item in Recently Deleted
- **asset**: Show the poster and hover preview for a video in the file list while it is still transcoding, with a gently pulsing cover (or an animated waiting circle before the poster is ready), "Uploading..."/"Preparing..." labels, and the duration hidden until it is ready
### Fixed
- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status
- **transcode**: Immediately stop background video processing and transcoding when a file is permanently deleted from the trash
- **asset**: Fix proxy download filename using original file extension instead of proxy extension
- **asset**: Fix an issue where deleting or restoring a version stack from the file list did nothing
- **webui**: Center breadcrumb file action popup menu on the chevron icon
## [0.4.6] - 2026-09-17
### Added
- **comment**: Add emoji reaction support for comments ([#405](https://github.com/shumaiOne/shumai/pull/405))
- **premiere-uxp**: Introduce Adobe Premiere Pro UXP plugin for Shumai ([#407](https://github.com/shumaiOne/shumai/pull/407))
- **settings**: Add team appearance setting to hide agent features ([#411](https://github.com/shumaiOne/shumai/pull/411))
### Fixed
- **premiere-uxp**: Preserve remote cloud storage presigned URLs in asset resolution ([#408](https://github.com/shumaiOne/shumai/pull/408))
- **premiere-uxp**: Scope sequence links by server endpoint and surface sync errors ([#409](https://github.com/shumaiOne/shumai/pull/409))
- **api**: Enforce SHUMAI_DEMO_MODE for API token and CLI requests ([#413](https://github.com/shumaiOne/shumai/pull/413))
### Documentation
- Add NLE export and Premiere Pro UXP plugin documentation ([#412](https://github.com/shumaiOne/shumai/pull/412))
## [0.4.5] - 2026-09-13
### Added
- **core**: Export comments to FCP, Premiere, Media Composer, and Resolve ([#400](https://github.com/shumaiOne/shumai/pull/400))
- **webui**: Add NLE comments export and migrate export API to POST ([#401](https://github.com/shumaiOne/shumai/pull/401))
- **webui**: Add space key quick preview for files and folders ([#402](https://github.com/shumaiOne/shumai/pull/402))
- **webui**: Show comments count badge in file card preview area ([#403](https://github.com/shumaiOne/shumai/pull/403))
- **agent**: Use deterministic storage keys for preset avatars ([#404](https://github.com/shumaiOne/shumai/pull/404))
## [0.4.4] - 2026-09-09
### Added
- **upload**: S3 multipart upload with offline resume and wake lock ([#391](https://github.com/shumaiOne/shumai/pull/391))
- **transcode**: Optimize video operations using ffmpeg http range requests ([#393](https://github.com/shumaiOne/shumai/pull/393))
- **agent**: Enable read_asset tool for autofill agent ([#396](https://github.com/shumaiOne/shumai/pull/396))
- **sandbox**: Abstract SandboxService and hot-reload allowed domains ([#398](https://github.com/shumaiOne/shumai/pull/398))
### Fixed
- **s3**: Stream downloadToFile and putObject to prevent OOM on large files ([#392](https://github.com/shumaiOne/shumai/pull/392))
- **agent**: Pass agent thinkingLevel to session name generation ([#395](https://github.com/shumaiOne/shumai/pull/395))
- **agent**: Restrict pageCount and duration recommendations to matching media types ([#397](https://github.com/shumaiOne/shumai/pull/397))
- **transcode**: Co-locate screenshots and derived artifacts in asset storage directory ([#399](https://github.com/shumaiOne/shumai/pull/399))
## [0.4.3] - 2026-09-06
### Added
- **asset**: Record and display agent provenance on assets and audit logs ([#380](https://github.com/shumaiOne/shumai/pull/380))
- **agent**: Store preset avatars as real files in s3 storage ([#381](https://github.com/shumaiOne/shumai/pull/381))
- **agent**: Add built-in image and video generation tools and settings ([#382](https://github.com/shumaiOne/shumai/pull/382))
- **media-generation**: Add gemini-omni-1.1-flash video model and redesign settings UI ([#383](https://github.com/shumaiOne/shumai/pull/383))
- **settings**: Redesign image/video settings to provider dialog with model toggles ([#385](https://github.com/shumaiOne/shumai/pull/385))
- **agent**: Add asset management tools and CLI commands ([#387](https://github.com/shumaiOne/shumai/pull/387))
- **cli**: Control asset deletion via SHUMAI_ALLOW_DELETE env var ([#388](https://github.com/shumaiOne/shumai/pull/388))
### Fixed
- **webui**: Clamp file card creation info to 2 lines and show tooltip on hover ([#390](https://github.com/shumaiOne/shumai/pull/390))
### Documentation
- **agents**: Add documentation for image and video generation settings ([#389](https://github.com/shumaiOne/shumai/pull/389))
### Maintenance
- **deps**: Upgrade bun to 1.4.2 and update packages ([#384](https://github.com/shumaiOne/shumai/pull/384))
- **i18n**: Update paraglide-js to 2.25.0 and stop checking in generated code ([#386](https://github.com/shumaiOne/shumai/pull/386))
## [0.4.2] - 2026-09-03
### Added
- **chat**: Support markups, attachments, and timestamps in agent 1-to-1 chat ([#368](https://github.com/shumaiOne/shumai/pull/368))
- **agent**: Move thread metadata to structured context XML ([#373](https://github.com/shumaiOne/shumai/pull/373))
- **agent**: Improve timestamp precision and proxy selection for video screenshots ([#374](https://github.com/shumaiOne/shumai/pull/374))
- **agent**: Support dynamic annotationId resolution across chat and comments ([#375](https://github.com/shumaiOne/shumai/pull/375))
- **agent**: Consolidate media tools into read_asset and add S3 key support to download_asset ([#376](https://github.com/shumaiOne/shumai/pull/376))
- **provider**: Optimize provider and model configuration management ([#377](https://github.com/shumaiOne/shumai/pull/377))
- **provider**: Add provider and model sync feature with vendored generator ([#378](https://github.com/shumaiOne/shumai/pull/378))
### Fixed
- **agent**: Set empty details in asset tool results to avoid data duplication ([#370](https://github.com/shumaiOne/shumai/pull/370))
- **webui**: Strip styles and preserve multiline text on paste in chat input ([#371](https://github.com/shumaiOne/shumai/pull/371))
- **agent**: Hide main comment sessions in dashboard sessions list ([#372](https://github.com/shumaiOne/shumai/pull/372))
### Changed
- **webui**: Use semantic system colors in notification settings ([#379](https://github.com/shumaiOne/shumai/pull/379))
## [0.4.1] - 2026-08-30
### Added
- **webui**: Add manage versions option to file card context menu ([#364](https://github.com/shumaiOne/shumai/pull/364))
- **agent**: Refactor message context into unified shumai_message ([#365](https://github.com/shumaiOne/shumai/pull/365))
- **webui**: Redesign comment attachment display into compact rows ([#366](https://github.com/shumaiOne/shumai/pull/366))
### Fixed
- **asset,webui**: Disallow dropping version stacks onto files and version stacks ([#363](https://github.com/shumaiOne/shumai/pull/363))
- **webui**: Prevent empty folder flash during initial loading ([#367](https://github.com/shumaiOne/shumai/pull/367))
### Changed
- **agent**: Remove executeAgentToolWorkflow and invoke core services directly ([#362](https://github.com/shumaiOne/shumai/pull/362))
## [0.4.0] - 2026-08-28
### Added
- **transcode**: Add hardware-accelerated video transcoding support ([#352](https://github.com/shumaiOne/shumai/pull/352))
- **webui**: Truncate long file names with 100ms hover tooltip ([#355](https://github.com/shumaiOne/shumai/pull/355))
- **webui**: Add simplified mobile-friendly layout for file and share lists ([#356](https://github.com/shumaiOne/shumai/pull/356))
- **webui**: Add mobile friendly file detail and public share view ([#359](https://github.com/shumaiOne/shumai/pull/359))
### Fixed
- **transcode**: Apply team hardware acceleration and source bitrate capping to watermark transcoding ([#353](https://github.com/shumaiOne/shumai/pull/353))
- **share**: Hide and soft-delete symlinks when target assets are trashed ([#354](https://github.com/shumaiOne/shumai/pull/354))
- **webui**: Fix breadcrumb file dropdown trigger stretching and alignment ([#360](https://github.com/shumaiOne/shumai/pull/360))
- **webui**: Align mobile comment cards and thread vertical indicator ([#361](https://github.com/shumaiOne/shumai/pull/361))
### Documentation
- Add SECURITY.md with a private disclosure path ([#357](https://github.com/shumaiOne/shumai/pull/357))
## [0.3.11] - 2026-08-25
### Added
- **auth**: Add admin password reset CLI command and reset password web UI ([#347](https://github.com/shumaiOne/shumai/pull/347))
- **project**: Add recent viewed files section to project folder tree ([#348](https://github.com/shumaiOne/shumai/pull/348))
### Fixed
- **webui**: Prevent left carousel remounting and scroll jump on file selection ([#351](https://github.com/shumaiOne/shumai/pull/351))
## [0.3.10] - 2026-08-23
### Added
- **agentic kanban**: Phase 1 not-agentic kanban board ([#330](https://github.com/shumaiOne/shumai/pull/330))
- **kanban**: Resolve latest version for linked version stack assets and update demo login text ([#342](https://github.com/shumaiOne/shumai/pull/342))
- **kanban**: Update task status permissions, reporter defaults, and participant access ([#345](https://github.com/shumaiOne/shumai/pull/345))
### Fixed
- **kanban**: Use true thumbnail and poster for task asset previews ([#343](https://github.com/shumaiOne/shumai/pull/343))
- **webui**: Sidebar selection styling, kanban active state, pointer cursors, and owner dashboard ([#344](https://github.com/shumaiOne/shumai/pull/344))
- **kanban**: Improve drag-drop to column bottom, remove empty drop line, and fix timeline alignment ([#346](https://github.com/shumaiOne/shumai/pull/346))
## [0.3.9] - 2026-08-18
### Added
- **agent**: Add permission controls for chat agents ([#313](https://github.com/shumaiOne/shumai/pull/313))
- **authz**: Enforce project-aware roles for agent/skill/mcp permissions ([#314](https://github.com/shumaiOne/shumai/pull/314))
- **webui**: Use project members for asset comment mentions ([#315](https://github.com/shumaiOne/shumai/pull/315))
- **quota**: Add 2-level database-backed resource quota system ([#318](https://github.com/shumaiOne/shumai/pull/318))
- **settings**: Reorganize settings into personal, team, and AI sections ([#324](https://github.com/shumaiOne/shumai/pull/324))
- **quota**: Move usage monitoring to team dashboard ([#327](https://github.com/shumaiOne/shumai/pull/327))
### Fixed
- **webui**: Preserve selected chatbot agent preference on reload ([#323](https://github.com/shumaiOne/shumai/pull/323))
- **quota**: Exclude agents from quota rules and usage records ([#325](https://github.com/shumaiOne/shumai/pull/325))
### Documentation
- **team-settings**: Add resource quotas documentation and update readme features ([#326](https://github.com/shumaiOne/shumai/pull/326))
## [0.3.8] - 2026-08-15
### Added
- **webui**: Replace legacy markdown editor with new lexical wysiwyg editor ([#308](https://github.com/shumaiOne/shumai/pull/308))
- **agent**: Add nested agents.md support across backend and webui ([#309](https://github.com/shumaiOne/shumai/pull/309))
- **webui**: Improve AGENTS.md editor placeholder and read-only notice ([#310](https://github.com/shumaiOne/shumai/pull/310))
- **version-stack**: Add manage versions dialog and version removal ([#311](https://github.com/shumaiOne/shumai/pull/311))
### Fixed
- **core**: Rename latest version child record on version stack rename ([#312](https://github.com/shumaiOne/shumai/pull/312))
## [0.3.7] - 2026-08-14
### Added
- **metadata**: Replace aiAutofill boolean with autofillSource enum ([#302](https://github.com/shumaiOne/shumai/pull/302))
- **agent**: Type-safe CREATION_CONTEXT metadata on create_file/create_version ([#303](https://github.com/shumaiOne/shumai/pull/303))
- **sandbox**: Default Network Sandbox to off and add settings toggle switch ([#304](https://github.com/shumaiOne/shumai/pull/304))
- **webui**: Redesign select metadata fields and improve long text field widget ([#305](https://github.com/shumaiOne/shumai/pull/305))
- **agent**: Support dynamic newOption in select and selectMulti metadata fields ([#306](https://github.com/shumaiOne/shumai/pull/306))
### Fixed
- **webui**: Fix select field height and multi-select overflow/interaction issues ([#307](https://github.com/shumaiOne/shumai/pull/307))
## [0.3.6] - 2026-08-12
### Added
- **mcp**: Add MCP server support with proxy tool and OAuth flow ([#289](https://github.com/shumaiOne/shumai/pull/289))
- **mcp**: Support tool-level directTools array and 3-state UI configuration ([#297](https://github.com/shumaiOne/shumai/pull/297))
- **webui**: Direct canvas PDF rendering with selectable text ([#299](https://github.com/shumaiOne/shumai/pull/299))
### Fixed
- **agent**: Prevent agents from accessing disabled skills ([#292](https://github.com/shumaiOne/shumai/pull/292))
- **agent**: Resolve version stack name and size in list_assets ([#296](https://github.com/shumaiOne/shumai/pull/296))
- **webui**: Content-only pinch-zoom and two-finger pan in media viewers ([#298](https://github.com/shumaiOne/shumai/pull/298))
- **i18n**: Update Chinese translation for dashboard to 仪表板 ([#301](https://github.com/shumaiOne/shumai/pull/301))
### Documentation
- **mcp**: Add MCP support documentation to README and docs ([#300](https://github.com/shumaiOne/shumai/pull/300))
## [0.3.5] - 2026-08-09
### Added
- **transcode**: Add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies ([#283](https://github.com/shumaiOne/shumai/pull/283))
### Fixed
- **webui**: Resolve upload card freeze for unsupported files ([#284](https://github.com/shumaiOne/shumai/pull/284))
- **webui**: Exclude file extension when selecting file name during inline rename ([#285](https://github.com/shumaiOne/shumai/pull/285))
- Use renamed asset name in download Content-Disposition ([#286](https://github.com/shumaiOne/shumai/pull/286))
- **webui**: Batch download no longer flashes a tab per file ([#287](https://github.com/shumaiOne/shumai/pull/287))
- **webui**: Enable rename and delete actions in file detail top bar breadcrumb ([#288](https://github.com/shumaiOne/shumai/pull/288))
## [0.3.4] - 2026-08-08
### Added
- **sharelink**: Add sharelink watermark support ([#270](https://github.com/shumaiOne/shumai/pull/270))
- **webui**: Remove original-file display fallbacks, use proxies only ([#273](https://github.com/shumaiOne/shumai/pull/273))
- **share**: Add allow download config to share links ([#275](https://github.com/shumaiOne/shumai/pull/275))
- **transcode**: Update preview thumbnail resolution to 300p with max length constraint ([#281](https://github.com/shumaiOne/shumai/pull/281))
### Fixed
- **share**: Resolve symlink asset downloads in public share pages ([#274](https://github.com/shumaiOne/shumai/pull/274))
- **webui**: Persist project sorting and prevent full page flash ([#276](https://github.com/shumaiOne/shumai/pull/276))
### Documentation
- **share-links**: Document allow download and lazy watermark settings ([#278](https://github.com/shumaiOne/shumai/pull/278))
- **agent**: Clarify create_file/create_version context param guidance ([#282](https://github.com/shumaiOne/shumai/pull/282))
### Maintenance
- **e2e**: Watermarked download-disabled share link coverage (image + video) ([#277](https://github.com/shumaiOne/shumai/pull/277))
- **e2e**: Stabilize watermark share spec on Firefox ([#279](https://github.com/shumaiOne/shumai/pull/279))
- Split e2e scripts into app and webui targets ([#280](https://github.com/shumaiOne/shumai/pull/280))
## [0.3.3] - 2026-08-05
### Added
- **agent**: Enable LLM API call retries in AgentHarness ([#250](https://github.com/shumaiOne/shumai/pull/250))
- **audit**: Add audit log support for APIs and WebUI dashboard ([#251](https://github.com/shumaiOne/shumai/pull/251))
- **webui**: Persist agent preference in localStorage ([#254](https://github.com/shumaiOne/shumai/pull/254))
- **e2e**: Add file domain comment and draw tests ([#260](https://github.com/shumaiOne/shumai/pull/260))
- **agent**: Restrict bash access for non-owner users ([#262](https://github.com/shumaiOne/shumai/pull/262))
- **agent**: Allow create_file tool to create files directly from content ([#263](https://github.com/shumaiOne/shumai/pull/263))
- **agent**: Propagate autofill context from chat to autofill workflow ([#264](https://github.com/shumaiOne/shumai/pull/264))
- **webui**: Render select options in field creation mode and pick random option color ([#265](https://github.com/shumaiOne/shumai/pull/265))
- **project**: Include team-scoped members in project member list and add 3-section dialog layout ([#267](https://github.com/shumaiOne/shumai/pull/267))
- **webui**: Disable role dropdown for project-scoped members in team view ([#269](https://github.com/shumaiOne/shumai/pull/269))
### Fixed
- **webui**: Mention popup avatars, keyboard auto-scroll, and non-sticky section headers ([#256](https://github.com/shumaiOne/shumai/pull/256))
- **webui**: Persist field order on drag and drop ([#266](https://github.com/shumaiOne/shumai/pull/266))
### Changed
- **agent**: Load models directly from database without pi fallback ([#253](https://github.com/shumaiOne/shumai/pull/253))
- **core**: Replace generated provider files with pi-ai dynamic methods ([#255](https://github.com/shumaiOne/shumai/pull/255))
### Maintenance
- **core**: Add missing tests for methods introduced in 97069042 ([#252](https://github.com/shumaiOne/shumai/pull/252))
- **e2e**: Add domain-based auth and project web app e2e tests ([#257](https://github.com/shumaiOne/shumai/pull/257))
- **e2e**: Add file, share, and collection web app e2e tests ([#258](https://github.com/shumaiOne/shumai/pull/258))
- **e2e**: Add project-level invite and file-move e2e tests ([#259](https://github.com/shumaiOne/shumai/pull/259))
- **e2e**: Add search in file list and save-search-as-collection cases ([#261](https://github.com/shumaiOne/shumai/pull/261))
- **e2e**: Add member permission change tests ([#268](https://github.com/shumaiOne/shumai/pull/268))
## [0.3.2] - 2026-07-30
### Added
- **agent**: Add output truncation and streaming limits to sandboxed bash tool ([#248](https://github.com/shumaiOne/shumai/pull/248))
### Fixed
- **agent**: Download original document asset instead of pdf proxy ([#247](https://github.com/shumaiOne/shumai/pull/247))
- **webui**: Persist chatbot sidebar input text across route navigation ([#249](https://github.com/shumaiOne/shumai/pull/249))
## [0.3.1] - 2026-07-30
### Added
- **transcode**: Trigger ai metadata autofill post transcode ([#234](https://github.com/shumaiOne/shumai/pull/234))
- **dashboard**: Add agent sessions view for team owners ([#237](https://github.com/shumaiOne/shumai/pull/237))
- **db**: Preserve agent sessions on asset deletion by setting onDelete to SetNull ([#240](https://github.com/shumaiOne/shumai/pull/240))
- **agent**: Add download_asset tool and prompt instructions ([#242](https://github.com/shumaiOne/shumai/pull/242))
- **db**: Update Asset.sizeByte and AiUsage token fields to BigInt ([#244](https://github.com/shumaiOne/shumai/pull/244))
### Fixed
- **agent**: Include select option labels and field name in autofill schema ([#235](https://github.com/shumaiOne/shumai/pull/235))
- **agent**: Scope agent comment sessions to thread sessions anchored at root comments ([#239](https://github.com/shumaiOne/shumai/pull/239))
- **agent**: Disable tools for session naming and make naming non-blocking ([#241](https://github.com/shumaiOne/shumai/pull/241))
- **webui**: Update file size formatting to SI decimal standard ([#245](https://github.com/shumaiOne/shumai/pull/245))
- **s3**: Enforce property syntax in S3Service interface and fix ReadableStream handling in S3StorageService ([#246](https://github.com/shumaiOne/shumai/pull/246))
## [0.3.0] - 2026-07-28
### Added
- **file-browser**: Add copy name and path option to context menu ([#225](https://github.com/shumaiOne/shumai/pull/225))
- **agent**: Inject user name and role into chat context ([#226](https://github.com/shumaiOne/shumai/pull/226))
- **agent**: Refactor database session storage to normalized DAG entries and lazy thread sync ([#229](https://github.com/shumaiOne/shumai/pull/229))
- **agent**: Support ENABLE_WEAKER_NESTED_SANDBOX environment variable ([#233](https://github.com/shumaiOne/shumai/pull/233))
### Fixed
- **agent**: Ensure atomic appendEntry and persist leaf entries in DatabaseSessionStorage ([#224](https://github.com/shumaiOne/shumai/pull/224))
- Sharp version mismatch bug ([#230](https://github.com/shumaiOne/shumai/pull/230))
- **agent**: Resolve S3 MIME type detection and prompt parameter in image analysis ([#232](https://github.com/shumaiOne/shumai/pull/232))
### Changed
- **agent**: Remove implicit agent mention trigger in comment threads ([#227](https://github.com/shumaiOne/shumai/pull/227))
### Maintenance
- **workflow**: Add docker compose deployment verification job ([#231](https://github.com/shumaiOne/shumai/pull/231))
## [0.2.3] - 2026-07-25
### Fixed
- **webui**: Show right sidebar by default on file detail page ([#219](https://github.com/shumaiOne/shumai/pull/219))
- **webui**: Refresh file list and detail when agent executes asset creation tools ([#220](https://github.com/shumaiOne/shumai/pull/220))
- **webui**: Fix space key drag overlay and shift range selection for version stacks ([#221](https://github.com/shumaiOne/shumai/pull/221))
- **transcode**: Handle timestamp rounding tolerance for screenshot annotations ([#223](https://github.com/shumaiOne/shumai/pull/223))
### Changed
- **e2e**: Split transcode workflow E2E tests into per-workflow test files ([#222](https://github.com/shumaiOne/shumai/pull/222))
## [0.2.2] - 2026-07-23
### Added
- **webui**: Integrate AI usage API into dashboard page ([#216](https://github.com/shumaiOne/shumai/pull/216))
- **ai-usage**: Add team and member token usage tracking and APIs ([#215](https://github.com/shumaiOne/shumai/pull/215))
- **transcode**: Add PSD support via ImageMagick and enforce sRGB conversion ([#217](https://github.com/shumaiOne/shumai/pull/217))
### Fixed
- **search**: Fix buildSqlCondition date range, numeric metadata, and string parsing bugs ([#213](https://github.com/shumaiOne/shumai/pull/213))
- **webui**: Prevent horizontal overflow in search dialog result rows ([#214](https://github.com/shumaiOne/shumai/pull/214))
- **webui**: Invalidate upload tasks query when upload task starts and completes ([#218](https://github.com/shumaiOne/shumai/pull/218))
## [0.2.1] - 2026-07-22
### Added
- **skill**: Add team owner skill permission control ([#209](https://github.com/shumaiOne/shumai/pull/209))
### Fixed
- **agent**: Handle non-builtin models in getModelFromDb and upgrade pi-ai ([#211](https://github.com/shumaiOne/shumai/pull/211))
- **provider**: Preserve model ids on provider update ([#212](https://github.com/shumaiOne/shumai/pull/212))
### Changed
- **core**: Split generated providers into per-provider files ([#210](https://github.com/shumaiOne/shumai/pull/210))
## [0.2.0] - 2026-07-21
### Added
- **transcode**: Add PDF preview, sprite generation, and annotation support ([#193](https://github.com/shumaiOne/shumai/pull/193))
- **web**: Register pdf.worker route in production ([#195](https://github.com/shumaiOne/shumai/pull/195))
- **agent**: Add read_pdf_pages tool and PDF page context support ([#196](https://github.com/shumaiOne/shumai/pull/196))
- **transcode**: Split monolithic transcodeMedia into focused workflows ([#197](https://github.com/shumaiOne/shumai/pull/197))
- **transcode**: Add PDF proxy support for TXT and CSV files ([#199](https://github.com/shumaiOne/shumai/pull/199))
- **asset**: Replace mediaType/mimeType logic with proxyType ([#200](https://github.com/shumaiOne/shumai/pull/200))
- **docker**: Install fonts-noto-cjk in runner stage ([#202](https://github.com/shumaiOne/shumai/pull/202))
- **transcode**: Add markdown file to pdf proxy support ([#203](https://github.com/shumaiOne/shumai/pull/203))
- **chat**: Track context asset changes and update agent context ([#204](https://github.com/shumaiOne/shumai/pull/204))
- **agent**: Refactor media tools to static injection with mandatory assetId and authz ([#208](https://github.com/shumaiOne/shumai/pull/208))
### Fixed
- **transcode**: Mark pdfkit as external and extract for docker runtime ([#201](https://github.com/shumaiOne/shumai/pull/201))
- **agent**: Include skill id in formatSkillsForPrompt ([#205](https://github.com/shumaiOne/shumai/pull/205))
- **asset**: Exclude soft-deleted children from latestChildren preview ([#206](https://github.com/shumaiOne/shumai/pull/206))
- **agent**: Pass latest version asset from version stack to prompt builder ([#207](https://github.com/shumaiOne/shumai/pull/207))
## [0.1.10] - 2026-07-16
### Added
- **workflow-e2e**: Add E2E tests for agentAutofillMedia workflow ([#188](https://github.com/shumaiOne/shumai/pull/188))
- **comments**: Support comment deletion and video player shortcuts ([#191](https://github.com/shumaiOne/shumai/pull/191))
- **agent**: Support disabling specific tools for agents ([#192](https://github.com/shumaiOne/shumai/pull/192))
### Maintenance
- **e2e**: Add E2E workflow tests for remaining agent and transcode services ([#189](https://github.com/shumaiOne/shumai/pull/189))
## [0.1.9] - 2026-07-14
### Added
- **e2e**: Set up fullstack app-level e2e test framework and signup test case ([#184](https://github.com/shumaiOne/shumai/pull/184))
- **chat**: Chatbot UI ([#185](https://github.com/shumaiOne/shumai/pull/185))
- **agent**: Support aborting agent execution ([#186](https://github.com/shumaiOne/shumai/pull/186))
### Changed
- **api/chat**: Remove direct Prisma query from API layer ([#187](https://github.com/shumaiOne/shumai/pull/187))
## [0.1.8] - 2026-07-10
### Added
- **chatbot**: Implement type-safe Chat APIs with compaction support ([#180](https://github.com/shumaiOne/shumai/pull/180))
### Fixed
- **webui**: Enable build splitting and code-split all page routes ([#183](https://github.com/shumaiOne/shumai/pull/183))
### Documentation
- **readme**: Clarify displayed file size represents original file size ([#182](https://github.com/shumaiOne/shumai/pull/182))
## [0.1.7] - 2026-07-06
### Added
- **audio**: Support frame-accurate audio playback, comments, and AI safeguards ([#175](https://github.com/shumaiOne/shumai/pull/175))
- **i18n**: Localize members dialog, notifications, uploads, user menus, dates, and players ([#178](https://github.com/shumaiOne/shumai/pull/178))
- **comments**: Allow marking comments as complete or incomplete ([#179](https://github.com/shumaiOne/shumai/pull/179))
### Fixed
- **upload**: Resolve empty and generic MIME types in confirmFileUpload ([#176](https://github.com/shumaiOne/shumai/pull/176))
### Changed
- **webui**: Modularize file viewer components into registry-driven architecture ([#174](https://github.com/shumaiOne/shumai/pull/174))
### Documentation
- Improve documentation and examples for S3 compatible storage ([#177](https://github.com/shumaiOne/shumai/pull/177))
## [0.1.6] - 2026-07-04
### Added
- **file-browser**: Show video duration on file card preview ([#170](https://github.com/shumaiOne/shumai/pull/170))
- **webui**: Compare versions view for version stacks ([#171](https://github.com/shumaiOne/shumai/pull/171))
### Fixed
- **webui**: Resolve conditional hooks and setState-in-render errors ([#167](https://github.com/shumaiOne/shumai/pull/167))
- **webui**: Resolve video player total frames mismatch ([#172](https://github.com/shumaiOne/shumai/pull/172))
- **version-stack**: Resolve correct latest version ID of version stack ([#173](https://github.com/shumaiOne/shumai/pull/173))
### Maintenance
- **webui**: Video player e2e framework + Safari playhead fix ([#166](https://github.com/shumaiOne/shumai/pull/166))
- **webui**: Add frame-accurate comment seek roundtrip e2e ([#168](https://github.com/shumaiOne/shumai/pull/168))
- **webui**: Verify video player restarts playback after end ([#169](https://github.com/shumaiOne/shumai/pull/169))
## [0.1.5] - 2026-07-02
### Changed
- **storage**: Use original filenames for stored files ([#165](https://github.com/shumaiOne/shumai/pull/165))
### Maintenance
- **release**: Add Aliyun ACR push to release workflow ([#164](https://github.com/shumaiOne/shumai/pull/164))
## [0.1.4] - 2026-07-01
### Added
- **transcode**: Change video poster resolution to 480p ([#161](https://github.com/shumaiOne/shumai/pull/161))
- **auth**: Allow setting user locale on signup ([#163](https://github.com/shumaiOne/shumai/pull/163))
### Fixed
- **webui**: Preserve video ended state by skipping playhead snap on ended ([#162](https://github.com/shumaiOne/shumai/pull/162))
## [0.1.3] - 2026-06-30
### Added
- **webui**: Add i18n support using paraglide-js ([#156](https://github.com/shumaiOne/shumai/pull/156))
- **video**: Add frame-accurate video player, SMPTE timecodes, and format switcher ([#157](https://github.com/shumaiOne/shumai/pull/157))
### Fixed
- **webui**: Align video timeline duration and formatting with frameio ([#158](https://github.com/shumaiOne/shumai/pull/158))
- **webui**: Fix missing left sidebar for nested folders ([#159](https://github.com/shumaiOne/shumai/pull/159))
- **api**: Fix update team settings and make request schema type-safe ([#160](https://github.com/shumaiOne/shumai/pull/160))
## [0.1.2] - 2026-06-25
### Changed
- **s3**: Remove automatic port appending to AWS_ENDPOINT_URL_S3 ([#155](https://github.com/shumaiOne/shumai/pull/155))
## [0.1.1] - 2026-06-23
### Added
- **docker**: Add root entrypoint with privilege dropping for data volumes ([#151](https://github.com/shumaiOne/shumai/pull/151))
## [0.1.0] - 2026-06-22
### Added
- **share**: Secure share info API and fix wrong password feedback ([#150](https://github.com/shumaiOne/shumai/pull/150))
### Fixed
- **webui**: Truncate long folder, collection, and share link names in sidebar ([#149](https://github.com/shumaiOne/shumai/pull/149))
## [0.0.11] - 2026-06-22
### Added
- **cli**: Add shumai-cli and token authentication ([#144](https://github.com/shumaiOne/shumai/pull/144))
- **settings**: Use singular headers and remove collapse/counters for single agent types ([#145](https://github.com/shumaiOne/shumai/pull/145))
- **folders**: Auto expand folder tree in left sidebar on navigation ([#146](https://github.com/shumaiOne/shumai/pull/146))
- **metadata**: Add single user and multiple user custom fields ([#147](https://github.com/shumaiOne/shumai/pull/147))
### Maintenance
- **cli**: Rename npm package to @shumai-one/shumai-cli ([#148](https://github.com/shumaiOne/shumai/pull/148))
## [0.0.10] - 2026-06-21
### Changed
- **web**: Dynamically register production HTML bundle routes ([#142](https://github.com/shumaiOne/shumai/pull/142))
### Documentation
- **readme**: Polish structure, correct grammar, and add dependencies table ([#143](https://github.com/shumaiOne/shumai/pull/143))
## [0.0.9] - 2026-06-20
### Added
- **webui**: Show app version in avatar menu ([#139](https://github.com/shumaiOne/shumai/pull/139))
- **cli**: Add background daemonization and subcommands ([#141](https://github.com/shumaiOne/shumai/pull/141))
### Maintenance
- **release**: Add smoke tests to local release stage ([#140](https://github.com/shumaiOne/shumai/pull/140))
## [0.0.8] - 2026-06-19
### Added
- **api**: Implement read-only mode for reviewers ([#122](https://github.com/shumaiOne/shumai/pull/122))
- **server**: Allow customizing server port via SHUMAI_SERVER_PORT ([#124](https://github.com/shumaiOne/shumai/pull/124))
- **embedding**: Defer embedding workflow, use transcoded assets, and execute chunks in separate activities ([#125](https://github.com/shumaiOne/shumai/pull/125))
- **webui**: Add external drag-and-drop file and folder upload support ([#126](https://github.com/shumaiOne/shumai/pull/126))
- **agent**: Implement overlapping video chunks for semantic search ([#127](https://github.com/shumaiOne/shumai/pull/127))
- **webui**: Support jumping to video timestamp from search results ([#128](https://github.com/shumaiOne/shumai/pull/128))
- **auth**: Add demo mode support ([#131](https://github.com/shumaiOne/shumai/pull/131))
- **auth**: Refine demo mode support ([#132](https://github.com/shumaiOne/shumai/pull/132))
- **webui**: Default right sidebar to collapsed for new users ([#133](https://github.com/shumaiOne/shumai/pull/133))
- **webui**: Use Shadcn Switch in toggle field and Rating component in search filter panel ([#137](https://github.com/shumaiOne/shumai/pull/137))
- **upload**: Track byte-level progress with XMLHttpRequest ([#138](https://github.com/shumaiOne/shumai/pull/138))
### Fixed
- **transcode**: Handle high-precision FPS using rational fractions ([#123](https://github.com/shumaiOne/shumai/pull/123))
- **db**: Automatically update project updatedAt on asset modification ([#129](https://github.com/shumaiOne/shumai/pull/129))
- **webui**: Use system colors for fields and improve search filter select options ([#130](https://github.com/shumaiOne/shumai/pull/130))
- **search**: Fix hasAny and hasNone operators on metadata filter ([#134](https://github.com/shumaiOne/shumai/pull/134))
- **webui**: Resolve folder tree sync, search dialog reset, and sidebar actions issues ([#136](https://github.com/shumaiOne/shumai/pull/136))
### Changed
- **webui**: Fix search dialog layout height, scroll areas, and restrict filter toggle click ([#135](https://github.com/shumaiOne/shumai/pull/135))
## [0.0.7] - 2026-06-17
### Added
- **workflow**: Configure transcode and agent concurrency via environment variables ([#116](https://github.com/shumaiOne/shumai/pull/116))
- **webui**: Replace hardcoded colors with system tokens ([#119](https://github.com/shumaiOne/shumai/pull/119))
- **webui**: Replace native overflow with shadcn ScrollArea in settings ([#120](https://github.com/shumaiOne/shumai/pull/120))
- **api**: Use enum for API protocol in provider config ([#121](https://github.com/shumaiOne/shumai/pull/121))
### Fixed
- **webui**: Reload video player and reset state when switching assets ([#114](https://github.com/shumaiOne/shumai/pull/114))
### Changed
- **transcode**: Relocate TranscodeService to core and flatten API package ([#115](https://github.com/shumaiOne/shumai/pull/115))
### Documentation
- Improve and restructure shumai documentation ([#118](https://github.com/shumaiOne/shumai/pull/118))
## [0.0.6] - 2026-06-15
### Added
- **sandbox**: Add pending domains support for network sandbox ([#109](https://github.com/shumaiOne/shumai/pull/109))
- **webui**: Always show right sidebar and implement left vertical carousel ([#111](https://github.com/shumaiOne/shumai/pull/111))
### Fixed
- **build**: Propagate termination signals to active child process in wrappers ([#102](https://github.com/shumaiOne/shumai/pull/102))
- **transcode**: Make deterministic transcode activity failures non-retryable in Temporal ([#104](https://github.com/shumaiOne/shumai/pull/104))
- **player**: Implement seekbar dragging and match hover highlight color ([#108](https://github.com/shumaiOne/shumai/pull/108))
- **webui**: Avoid refetching all pages on file/folder reorder ([#112](https://github.com/shumaiOne/shumai/pull/112))
- **webui**: Force video-player mime type to video/mp4 ([#113](https://github.com/shumaiOne/shumai/pull/113))
### Changed
- **webui**: Use system color design tokens in video player components ([#106](https://github.com/shumaiOne/shumai/pull/106))
- **webui**: Use requestAnimationFrame for smooth video progress bar updates ([#107](https://github.com/shumaiOne/shumai/pull/107))
- **webui**: Fetch agents in mention input list dynamically ([#110](https://github.com/shumaiOne/shumai/pull/110))
### Documentation
- **readme**: Add comprehensive README.md ([#103](https://github.com/shumaiOne/shumai/pull/103))
- **readme**: Improve remote deployment and temporal execution instructions ([#105](https://github.com/shumaiOne/shumai/pull/105))
## [0.0.5] - 2026-06-13
### Added
- **npm**: Auto deploy database migrations on package start ([#101](https://github.com/shumaiOne/shumai/pull/101))
## [0.0.4] - 2026-06-12
### Fixed
- **cli/docker**: Resolve global CLI external dependencies and fix Docker 404 error ([#100](https://github.com/shumaiOne/shumai/pull/100))
## [0.0.3] - 2026-06-12
### Fixed
- **cli**: Resolve platform binary path resolution under nested node_modules ([#99](https://github.com/shumaiOne/shumai/pull/99))
## [0.0.2] - 2026-06-12
### Fixed
- **npm**: Add repository metadata to package.json for provenance verification ([#98](https://github.com/shumaiOne/shumai/pull/98))
### Maintenance
- Add release-npm.yaml workflow ([#97](https://github.com/shumaiOne/shumai/pull/97))
## [0.0.1] - 2026-06-12
### Added
- Initial release of Shumai
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent-app",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/cli",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/premiere-uxp",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "commonjs",
"scripts": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode-app",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"bin": {
+4
View File
@@ -73,6 +73,8 @@ apps/web/e2e/
| Owner creates a project with a cover image | `tests/project/create-project.spec.ts` |
| Owner uploads a file or an unsupported file via the "Upload File" context menu action | `tests/project/upload-file.spec.ts` |
| Owner deletes a file, finds it in recently deleted, and restores it | `tests/project/delete-restore.spec.ts` |
| Owner deletes a folder and still sees its contents preview and countdown in recently deleted | `tests/project/delete-restore.spec.ts` |
| Owner deletes a version stack and restores it from recently deleted | `tests/project/delete-restore.spec.ts` |
| Owner creates a share link from a file context menu and lands on the share page | `tests/project/create-share-link.spec.ts` |
| Owner protects a share with a password; guests must enter it to view | `tests/project/share-password.spec.ts` |
| Owner creates a collection from the sidebar; the collection shows project files | `tests/project/create-collection.spec.ts` |
@@ -103,6 +105,8 @@ apps/web/e2e/
| Upload an image file, wait for transcode, and create a comment with draw | `tests/file/image-draw-comment.spec.ts` |
| Upload a video file, wait for transcode, and create a comment with draw at a non-zero timestamp | `tests/file/video-draw-comment.spec.ts` |
| Upload an audio file, wait for transcode, and create a comment at a non-zero timestamp | `tests/file/audio-timestamp-comment.spec.ts` |
| Show a breathing poster preview and "Preparing..." while a video is still transcoding | `tests/file/processing-preview.spec.ts` |
| Show a preparing circle before the poster is generated | `tests/file/processing-preview.spec.ts` |
## Conventions
@@ -0,0 +1,82 @@
import { expect, test } from '../../fixtures'
import { fileCard } from '../../helpers/files'
// Uploaded as a binary file so no real transcode task races with the simulated mid-transcode
// state we set up directly in the database.
test.use({ fileOptions: { mediaType: 'binary' } })
test('shows the poster preview and "Preparing..." while a video is still transcoding', async ({
file,
prisma,
}) => {
const { page, projectId, fileId, fileName } = file
// Simulate a video that is mid-transcode: the poster/sprite preview already exists, but the
// asset is still marked as processing.
const assetDir = `files/e2e/${fileId}`
await prisma.asset.update({
where: { id: fileId },
data: {
status: 'processing',
mediaType: 'video/mp4',
media: {
duration: 10,
filesize: 0,
frames: 300,
proxyType: 'video',
imageTranscodes: [],
videoTranscodes: [],
sprite: { key: `${assetDir}/sprite.webp`, frames: 100, tileX: 10, tileY: 10 },
poster: { key: `${assetDir}/poster.webp` },
finishedAt: new Date().toISOString(),
metadata: {
originalWidth: 1920,
originalHeight: 1080,
hasAudio: false,
duration: 10,
bitRate: 0,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
format: {},
},
original: { key: `${assetDir}/original.mp4`, filesizeInBytes: 0, codec: '' },
},
},
})
await page.goto(`/projects/${projectId}`)
const card = fileCard(page, fileName)
await expect(card).toBeVisible()
// The preview (poster thumbnail used as the sprite scrubber base) is rendered instead of a
// blank placeholder, and its opacity breathes while transcoding is in progress.
await expect(card.locator('img[alt="Thumbnail"]')).toBeVisible()
await expect(card.getByTestId('file-card-preview-media')).toHaveClass(/animate-pulse/)
// The creator row is replaced by a "Preparing..." label while transcoding.
await expect(card.getByText(/Preparing|准备中/i)).toBeVisible()
// The duration badge is hidden until the asset is ready.
await expect(card.getByText('00:10')).toHaveCount(0)
})
test('shows a preparing circle before the poster is generated', async ({ file, prisma }) => {
const { page, projectId, fileId, fileName } = file
// Simulate an asset whose upload finished but whose poster does not exist yet.
await prisma.asset.update({
where: { id: fileId },
data: { status: 'processing', mediaType: 'video/mp4' },
})
await page.goto(`/projects/${projectId}`)
const card = fileCard(page, fileName)
await expect(card).toBeVisible()
// A size-breathing circle stands in until the poster is available, with a "Preparing..." label.
await expect(card.getByTestId('file-card-preparing-circle')).toBeVisible()
await expect(card.getByText(/Preparing|准备中/i)).toBeVisible()
})
@@ -1,4 +1,5 @@
import { expect, test } from '../../fixtures'
import { seedFile, seedFolder } from '../../helpers/assets'
import { fileCard } from '../../helpers/files'
test('owner deletes a file, finds it in recently deleted, and restores it', async ({
@@ -43,3 +44,121 @@ test('owner deletes a file, finds it in recently deleted, and restores it', asyn
await page.goto(`/projects/${projectId}`)
await expect(fileCard(page, fileName)).toBeVisible()
})
test('owner deletes a folder and still sees its contents preview and countdown in recently deleted', async ({
project,
prisma,
}) => {
const { page, projectId, rootFolderId } = project
const folderName = `e2e-deleted-folder-${Date.now()}`
const folder = await seedFolder(prisma, projectId, rootFolderId, folderName)
await seedFile(prisma, projectId, folder.id, 'inside-1.png')
await seedFile(prisma, projectId, folder.id, 'inside-2.png')
await page.goto(`/projects/${projectId}`)
await expect(fileCard(page, folderName)).toBeVisible()
// Delete the folder through the context menu + confirmation dialog
await fileCard(page, folderName).click({ button: 'right' })
await page.getByRole('menuitem', { name: 'Delete' }).click()
const deleteDialog = page.getByRole('alertdialog')
await expect(deleteDialog.getByText('Delete Asset?')).toBeVisible()
await deleteDialog.getByRole('button', { name: 'Delete' }).click()
await expect(fileCard(page, folderName)).not.toBeVisible()
// Navigate to the Recently Deleted view
await page.getByText('Recently Deleted').click()
await expect(page).toHaveURL(/\/recently-deleted/)
const deletedFolderCard = fileCard(page, folderName)
await expect(deletedFolderCard).toBeVisible()
// The folder still shows previews of the files that were deleted with it
await expect(deletedFolderCard.getByTestId('folder-preview-grid')).toBeVisible()
// And each item shows how many days are left before permanent deletion
await expect(deletedFolderCard.getByTestId('folder-card-days-left')).toHaveText(/30\s*(d|天)/)
})
test('owner deletes a version stack and restores it from recently deleted', async ({
project,
prisma,
}) => {
const { page, projectId, rootFolderId } = project
const latestVersionName = `e2e-stack-latest-${Date.now()}.png`
const olderVersionName = `e2e-stack-older-${Date.now()}.png`
const stack = await prisma.asset.create({
data: {
name: `e2e-stack-${Date.now()}`,
type: 'version_stack',
status: 'processed',
projectId,
parentId: rootFolderId,
fileCount: 2,
sizeByte: 20,
},
})
await prisma.asset.create({
data: {
name: latestVersionName,
type: 'file',
status: 'processed',
sizeByte: 10,
sortIndex: 'a0',
projectId,
parentId: stack.id,
},
})
await prisma.asset.create({
data: {
name: olderVersionName,
type: 'file',
status: 'processed',
sizeByte: 10,
sortIndex: 'a1',
projectId,
parentId: stack.id,
},
})
// The stack card is labelled with its latest version's name
await page.goto(`/projects/${projectId}`)
await expect(fileCard(page, latestVersionName)).toBeVisible()
await fileCard(page, latestVersionName).click({ button: 'right' })
await page.getByRole('menuitem', { name: 'Delete' }).click()
const deleteDialog = page.getByRole('alertdialog')
await expect(deleteDialog.getByText('Delete Asset?')).toBeVisible()
await deleteDialog.getByRole('button', { name: 'Delete' }).click()
await expect(fileCard(page, latestVersionName)).not.toBeVisible()
// The whole stack is soft-deleted, including its versions
await expect
.poll(async () => {
const row = await prisma.asset.findUnique({ where: { id: stack.id } })
return row?.isDeleted
})
.toBe(true)
// Restore it from the Recently Deleted view
await page.getByText('Recently Deleted').click()
await expect(page).toHaveURL(/\/recently-deleted/)
await expect(fileCard(page, latestVersionName)).toBeVisible()
await fileCard(page, latestVersionName).click({ button: 'right' })
await page.getByRole('menuitem', { name: 'Restore' }).click()
await expect(fileCard(page, latestVersionName)).not.toBeVisible()
await expect
.poll(async () => {
const row = await prisma.asset.findUnique({ where: { id: stack.id } })
return row?.isDeleted
})
.toBe(false)
// Back at the project root the stack is visible again
await page.goto(`/projects/${projectId}`)
await expect(fileCard(page, latestVersionName)).toBeVisible()
})
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/web-app",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"dependencies": {
+15 -15
View File
@@ -33,7 +33,7 @@
},
"apps/agent": {
"name": "@shumai/agent-app",
"version": "0.4.6",
"version": "0.4.8",
"bin": {
"shumai-agent": "./src/index.ts",
},
@@ -45,7 +45,7 @@
},
"apps/cli": {
"name": "@shumai/cli",
"version": "0.4.6",
"version": "0.4.8",
"bin": {
"shumai-cli": "./src/index.ts",
},
@@ -60,7 +60,7 @@
},
"apps/premiere-uxp": {
"name": "@shumai/premiere-uxp",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@shumai/api": "workspace:*",
"@shumai/dtos": "workspace:*",
@@ -114,7 +114,7 @@
},
"apps/transcode": {
"name": "@shumai/transcode-app",
"version": "0.4.6",
"version": "0.4.8",
"bin": {
"shumai-transcode": "./src/index.ts",
},
@@ -126,7 +126,7 @@
},
"apps/web": {
"name": "@shumai/web-app",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@shumai/agent": "workspace:*",
"@shumai/api": "workspace:*",
@@ -146,7 +146,7 @@
},
"packages/agent": {
"name": "@shumai/agent",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@anthropic-ai/sandbox-runtime": "0.0.74",
"@earendil-works/pi-agent-core": "0.82.1",
@@ -171,7 +171,7 @@
},
"packages/api": {
"name": "@shumai/api",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@hono/zod-validator": "0.7.6",
"@shumai/core": "workspace:*",
@@ -185,7 +185,7 @@
},
"packages/core": {
"name": "@shumai/core",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@ai-sdk/alibaba": "2.0.38",
"@ai-sdk/amazon-bedrock": "5.0.67",
@@ -242,7 +242,7 @@
},
"packages/db": {
"name": "@shumai/db",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"@prisma/adapter-pg": "7.10.0",
@@ -258,7 +258,7 @@
},
"packages/dtos": {
"name": "@shumai/dtos",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"zod": "4.5.4",
@@ -266,7 +266,7 @@
},
"packages/e2e": {
"name": "@shumai/e2e",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"@google/genai": "2.19.0",
@@ -281,11 +281,11 @@
},
"packages/tableprinter": {
"name": "@shumai/tableprinter",
"version": "0.4.6",
"version": "0.4.8",
},
"packages/transcode": {
"name": "@shumai/transcode",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -299,7 +299,7 @@
},
"packages/webui": {
"name": "@shumai/webui",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@base-ui/react": "1.7.0",
"@dnd-kit/abstract": "0.5.0",
@@ -401,7 +401,7 @@
},
"packages/workflow-core": {
"name": "@shumai/workflow-core",
"version": "0.4.6",
"version": "0.4.8",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -6,8 +6,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/18/docker
healthcheck:
-2
View File
@@ -6,8 +6,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/18/docker
healthcheck:
@@ -7,8 +7,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql
healthcheck:
+817
View File
@@ -0,0 +1,817 @@
---
title: "Changelog"
description: "Recent updates, new features, and improvements in Shumai"
---
<Update label="v0.4.8" description="September 24, 2026">
### Added
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
### Fixed
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
### Changed
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
</Update>
<Update label="v0.4.7" description="September 19, 2026">
### Added
- **changelog**: Introduce Keep a Changelog support, historical release summaries, and automated release notes extraction
- **release**: Automatically populate GitHub release bodies from CHANGELOG.md and promote unreleased notes during version bumps
- **settings**: Add FFmpeg threads slider to team media processing settings
- **asset**: Show previews of a folder's contents and a "days left" countdown for each item in Recently Deleted
- **asset**: Show the poster and hover preview for a video in the file list while it is still transcoding, with a gently pulsing cover (or an animated waiting circle before the poster is ready), "Uploading..."/"Preparing..." labels, and the duration hidden until it is ready
### Fixed
- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status
- **transcode**: Immediately stop background video processing and transcoding when a file is permanently deleted from the trash
- **asset**: Fix proxy download filename using original file extension instead of proxy extension
- **asset**: Fix an issue where deleting or restoring a version stack from the file list did nothing
- **webui**: Center breadcrumb file action popup menu on the chevron icon
</Update>
<Update label="v0.4.6" description="September 17, 2026">
### Added
- **comment**: Add emoji reaction support for comments ([#405](https://github.com/shumaiOne/shumai/pull/405))
- **premiere-uxp**: Introduce Adobe Premiere Pro UXP plugin for Shumai ([#407](https://github.com/shumaiOne/shumai/pull/407))
- **settings**: Add team appearance setting to hide agent features ([#411](https://github.com/shumaiOne/shumai/pull/411))
### Fixed
- **premiere-uxp**: Preserve remote cloud storage presigned URLs in asset resolution ([#408](https://github.com/shumaiOne/shumai/pull/408))
- **premiere-uxp**: Scope sequence links by server endpoint and surface sync errors ([#409](https://github.com/shumaiOne/shumai/pull/409))
- **api**: Enforce SHUMAI_DEMO_MODE for API token and CLI requests ([#413](https://github.com/shumaiOne/shumai/pull/413))
### Documentation
- Add NLE export and Premiere Pro UXP plugin documentation ([#412](https://github.com/shumaiOne/shumai/pull/412))
</Update>
<Update label="v0.4.5" description="September 13, 2026">
### Added
- **core**: Export comments to FCP, Premiere, Media Composer, and Resolve ([#400](https://github.com/shumaiOne/shumai/pull/400))
- **webui**: Add NLE comments export and migrate export API to POST ([#401](https://github.com/shumaiOne/shumai/pull/401))
- **webui**: Add space key quick preview for files and folders ([#402](https://github.com/shumaiOne/shumai/pull/402))
- **webui**: Show comments count badge in file card preview area ([#403](https://github.com/shumaiOne/shumai/pull/403))
- **agent**: Use deterministic storage keys for preset avatars ([#404](https://github.com/shumaiOne/shumai/pull/404))
</Update>
<Update label="v0.4.4" description="September 9, 2026">
### Added
- **upload**: S3 multipart upload with offline resume and wake lock ([#391](https://github.com/shumaiOne/shumai/pull/391))
- **transcode**: Optimize video operations using ffmpeg http range requests ([#393](https://github.com/shumaiOne/shumai/pull/393))
- **agent**: Enable read_asset tool for autofill agent ([#396](https://github.com/shumaiOne/shumai/pull/396))
- **sandbox**: Abstract SandboxService and hot-reload allowed domains ([#398](https://github.com/shumaiOne/shumai/pull/398))
### Fixed
- **s3**: Stream downloadToFile and putObject to prevent OOM on large files ([#392](https://github.com/shumaiOne/shumai/pull/392))
- **agent**: Pass agent thinkingLevel to session name generation ([#395](https://github.com/shumaiOne/shumai/pull/395))
- **agent**: Restrict pageCount and duration recommendations to matching media types ([#397](https://github.com/shumaiOne/shumai/pull/397))
- **transcode**: Co-locate screenshots and derived artifacts in asset storage directory ([#399](https://github.com/shumaiOne/shumai/pull/399))
</Update>
<Update label="v0.4.3" description="September 6, 2026">
### Added
- **asset**: Record and display agent provenance on assets and audit logs ([#380](https://github.com/shumaiOne/shumai/pull/380))
- **agent**: Store preset avatars as real files in s3 storage ([#381](https://github.com/shumaiOne/shumai/pull/381))
- **agent**: Add built-in image and video generation tools and settings ([#382](https://github.com/shumaiOne/shumai/pull/382))
- **media-generation**: Add gemini-omni-1.1-flash video model and redesign settings UI ([#383](https://github.com/shumaiOne/shumai/pull/383))
- **settings**: Redesign image/video settings to provider dialog with model toggles ([#385](https://github.com/shumaiOne/shumai/pull/385))
- **agent**: Add asset management tools and CLI commands ([#387](https://github.com/shumaiOne/shumai/pull/387))
- **cli**: Control asset deletion via SHUMAI_ALLOW_DELETE env var ([#388](https://github.com/shumaiOne/shumai/pull/388))
### Fixed
- **webui**: Clamp file card creation info to 2 lines and show tooltip on hover ([#390](https://github.com/shumaiOne/shumai/pull/390))
### Documentation
- **agents**: Add documentation for image and video generation settings ([#389](https://github.com/shumaiOne/shumai/pull/389))
### Maintenance
- **deps**: Upgrade bun to 1.4.2 and update packages ([#384](https://github.com/shumaiOne/shumai/pull/384))
- **i18n**: Update paraglide-js to 2.25.0 and stop checking in generated code ([#386](https://github.com/shumaiOne/shumai/pull/386))
</Update>
<Update label="v0.4.2" description="September 3, 2026">
### Added
- **chat**: Support markups, attachments, and timestamps in agent 1-to-1 chat ([#368](https://github.com/shumaiOne/shumai/pull/368))
- **agent**: Move thread metadata to structured context XML ([#373](https://github.com/shumaiOne/shumai/pull/373))
- **agent**: Improve timestamp precision and proxy selection for video screenshots ([#374](https://github.com/shumaiOne/shumai/pull/374))
- **agent**: Support dynamic annotationId resolution across chat and comments ([#375](https://github.com/shumaiOne/shumai/pull/375))
- **agent**: Consolidate media tools into read_asset and add S3 key support to download_asset ([#376](https://github.com/shumaiOne/shumai/pull/376))
- **provider**: Optimize provider and model configuration management ([#377](https://github.com/shumaiOne/shumai/pull/377))
- **provider**: Add provider and model sync feature with vendored generator ([#378](https://github.com/shumaiOne/shumai/pull/378))
### Fixed
- **agent**: Set empty details in asset tool results to avoid data duplication ([#370](https://github.com/shumaiOne/shumai/pull/370))
- **webui**: Strip styles and preserve multiline text on paste in chat input ([#371](https://github.com/shumaiOne/shumai/pull/371))
- **agent**: Hide main comment sessions in dashboard sessions list ([#372](https://github.com/shumaiOne/shumai/pull/372))
### Changed
- **webui**: Use semantic system colors in notification settings ([#379](https://github.com/shumaiOne/shumai/pull/379))
</Update>
<Update label="v0.4.1" description="August 30, 2026">
### Added
- **webui**: Add manage versions option to file card context menu ([#364](https://github.com/shumaiOne/shumai/pull/364))
- **agent**: Refactor message context into unified shumai_message ([#365](https://github.com/shumaiOne/shumai/pull/365))
- **webui**: Redesign comment attachment display into compact rows ([#366](https://github.com/shumaiOne/shumai/pull/366))
### Fixed
- **asset,webui**: Disallow dropping version stacks onto files and version stacks ([#363](https://github.com/shumaiOne/shumai/pull/363))
- **webui**: Prevent empty folder flash during initial loading ([#367](https://github.com/shumaiOne/shumai/pull/367))
### Changed
- **agent**: Remove executeAgentToolWorkflow and invoke core services directly ([#362](https://github.com/shumaiOne/shumai/pull/362))
</Update>
<Update label="v0.4.0" description="August 28, 2026">
### Added
- **transcode**: Add hardware-accelerated video transcoding support ([#352](https://github.com/shumaiOne/shumai/pull/352))
- **webui**: Truncate long file names with 100ms hover tooltip ([#355](https://github.com/shumaiOne/shumai/pull/355))
- **webui**: Add simplified mobile-friendly layout for file and share lists ([#356](https://github.com/shumaiOne/shumai/pull/356))
- **webui**: Add mobile friendly file detail and public share view ([#359](https://github.com/shumaiOne/shumai/pull/359))
### Fixed
- **transcode**: Apply team hardware acceleration and source bitrate capping to watermark transcoding ([#353](https://github.com/shumaiOne/shumai/pull/353))
- **share**: Hide and soft-delete symlinks when target assets are trashed ([#354](https://github.com/shumaiOne/shumai/pull/354))
- **webui**: Fix breadcrumb file dropdown trigger stretching and alignment ([#360](https://github.com/shumaiOne/shumai/pull/360))
- **webui**: Align mobile comment cards and thread vertical indicator ([#361](https://github.com/shumaiOne/shumai/pull/361))
### Documentation
- Add SECURITY.md with a private disclosure path ([#357](https://github.com/shumaiOne/shumai/pull/357))
</Update>
<Update label="v0.3.11" description="August 25, 2026">
### Added
- **auth**: Add admin password reset CLI command and reset password web UI ([#347](https://github.com/shumaiOne/shumai/pull/347))
- **project**: Add recent viewed files section to project folder tree ([#348](https://github.com/shumaiOne/shumai/pull/348))
### Fixed
- **webui**: Prevent left carousel remounting and scroll jump on file selection ([#351](https://github.com/shumaiOne/shumai/pull/351))
</Update>
<Update label="v0.3.10" description="August 23, 2026">
### Added
- **agentic kanban**: Phase 1 not-agentic kanban board ([#330](https://github.com/shumaiOne/shumai/pull/330))
- **kanban**: Resolve latest version for linked version stack assets and update demo login text ([#342](https://github.com/shumaiOne/shumai/pull/342))
- **kanban**: Update task status permissions, reporter defaults, and participant access ([#345](https://github.com/shumaiOne/shumai/pull/345))
### Fixed
- **kanban**: Use true thumbnail and poster for task asset previews ([#343](https://github.com/shumaiOne/shumai/pull/343))
- **webui**: Sidebar selection styling, kanban active state, pointer cursors, and owner dashboard ([#344](https://github.com/shumaiOne/shumai/pull/344))
- **kanban**: Improve drag-drop to column bottom, remove empty drop line, and fix timeline alignment ([#346](https://github.com/shumaiOne/shumai/pull/346))
</Update>
<Update label="v0.3.9" description="August 18, 2026">
### Added
- **agent**: Add permission controls for chat agents ([#313](https://github.com/shumaiOne/shumai/pull/313))
- **authz**: Enforce project-aware roles for agent/skill/mcp permissions ([#314](https://github.com/shumaiOne/shumai/pull/314))
- **webui**: Use project members for asset comment mentions ([#315](https://github.com/shumaiOne/shumai/pull/315))
- **quota**: Add 2-level database-backed resource quota system ([#318](https://github.com/shumaiOne/shumai/pull/318))
- **settings**: Reorganize settings into personal, team, and AI sections ([#324](https://github.com/shumaiOne/shumai/pull/324))
- **quota**: Move usage monitoring to team dashboard ([#327](https://github.com/shumaiOne/shumai/pull/327))
### Fixed
- **webui**: Preserve selected chatbot agent preference on reload ([#323](https://github.com/shumaiOne/shumai/pull/323))
- **quota**: Exclude agents from quota rules and usage records ([#325](https://github.com/shumaiOne/shumai/pull/325))
### Documentation
- **team-settings**: Add resource quotas documentation and update readme features ([#326](https://github.com/shumaiOne/shumai/pull/326))
</Update>
<Update label="v0.3.8" description="August 15, 2026">
### Added
- **webui**: Replace legacy markdown editor with new lexical wysiwyg editor ([#308](https://github.com/shumaiOne/shumai/pull/308))
- **agent**: Add nested agents.md support across backend and webui ([#309](https://github.com/shumaiOne/shumai/pull/309))
- **webui**: Improve AGENTS.md editor placeholder and read-only notice ([#310](https://github.com/shumaiOne/shumai/pull/310))
- **version-stack**: Add manage versions dialog and version removal ([#311](https://github.com/shumaiOne/shumai/pull/311))
### Fixed
- **core**: Rename latest version child record on version stack rename ([#312](https://github.com/shumaiOne/shumai/pull/312))
</Update>
<Update label="v0.3.7" description="August 14, 2026">
### Added
- **metadata**: Replace aiAutofill boolean with autofillSource enum ([#302](https://github.com/shumaiOne/shumai/pull/302))
- **agent**: Type-safe CREATION_CONTEXT metadata on create_file/create_version ([#303](https://github.com/shumaiOne/shumai/pull/303))
- **sandbox**: Default Network Sandbox to off and add settings toggle switch ([#304](https://github.com/shumaiOne/shumai/pull/304))
- **webui**: Redesign select metadata fields and improve long text field widget ([#305](https://github.com/shumaiOne/shumai/pull/305))
- **agent**: Support dynamic newOption in select and selectMulti metadata fields ([#306](https://github.com/shumaiOne/shumai/pull/306))
### Fixed
- **webui**: Fix select field height and multi-select overflow/interaction issues ([#307](https://github.com/shumaiOne/shumai/pull/307))
</Update>
<Update label="v0.3.6" description="August 12, 2026">
### Added
- **mcp**: Add MCP server support with proxy tool and OAuth flow ([#289](https://github.com/shumaiOne/shumai/pull/289))
- **mcp**: Support tool-level directTools array and 3-state UI configuration ([#297](https://github.com/shumaiOne/shumai/pull/297))
- **webui**: Direct canvas PDF rendering with selectable text ([#299](https://github.com/shumaiOne/shumai/pull/299))
### Fixed
- **agent**: Prevent agents from accessing disabled skills ([#292](https://github.com/shumaiOne/shumai/pull/292))
- **agent**: Resolve version stack name and size in list_assets ([#296](https://github.com/shumaiOne/shumai/pull/296))
- **webui**: Content-only pinch-zoom and two-finger pan in media viewers ([#298](https://github.com/shumaiOne/shumai/pull/298))
- **i18n**: Update Chinese translation for dashboard to 仪表板 ([#301](https://github.com/shumaiOne/shumai/pull/301))
### Documentation
- **mcp**: Add MCP support documentation to README and docs ([#300](https://github.com/shumaiOne/shumai/pull/300))
</Update>
<Update label="v0.3.5" description="August 9, 2026">
### Added
- **transcode**: Add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies ([#283](https://github.com/shumaiOne/shumai/pull/283))
### Fixed
- **webui**: Resolve upload card freeze for unsupported files ([#284](https://github.com/shumaiOne/shumai/pull/284))
- **webui**: Exclude file extension when selecting file name during inline rename ([#285](https://github.com/shumaiOne/shumai/pull/285))
- Use renamed asset name in download Content-Disposition ([#286](https://github.com/shumaiOne/shumai/pull/286))
- **webui**: Batch download no longer flashes a tab per file ([#287](https://github.com/shumaiOne/shumai/pull/287))
- **webui**: Enable rename and delete actions in file detail top bar breadcrumb ([#288](https://github.com/shumaiOne/shumai/pull/288))
</Update>
<Update label="v0.3.4" description="August 8, 2026">
### Added
- **sharelink**: Add sharelink watermark support ([#270](https://github.com/shumaiOne/shumai/pull/270))
- **webui**: Remove original-file display fallbacks, use proxies only ([#273](https://github.com/shumaiOne/shumai/pull/273))
- **share**: Add allow download config to share links ([#275](https://github.com/shumaiOne/shumai/pull/275))
- **transcode**: Update preview thumbnail resolution to 300p with max length constraint ([#281](https://github.com/shumaiOne/shumai/pull/281))
### Fixed
- **share**: Resolve symlink asset downloads in public share pages ([#274](https://github.com/shumaiOne/shumai/pull/274))
- **webui**: Persist project sorting and prevent full page flash ([#276](https://github.com/shumaiOne/shumai/pull/276))
### Documentation
- **share-links**: Document allow download and lazy watermark settings ([#278](https://github.com/shumaiOne/shumai/pull/278))
- **agent**: Clarify create_file/create_version context param guidance ([#282](https://github.com/shumaiOne/shumai/pull/282))
### Maintenance
- **e2e**: Watermarked download-disabled share link coverage (image + video) ([#277](https://github.com/shumaiOne/shumai/pull/277))
- **e2e**: Stabilize watermark share spec on Firefox ([#279](https://github.com/shumaiOne/shumai/pull/279))
- Split e2e scripts into app and webui targets ([#280](https://github.com/shumaiOne/shumai/pull/280))
</Update>
<Update label="v0.3.3" description="August 5, 2026">
### Added
- **agent**: Enable LLM API call retries in AgentHarness ([#250](https://github.com/shumaiOne/shumai/pull/250))
- **audit**: Add audit log support for APIs and WebUI dashboard ([#251](https://github.com/shumaiOne/shumai/pull/251))
- **webui**: Persist agent preference in localStorage ([#254](https://github.com/shumaiOne/shumai/pull/254))
- **e2e**: Add file domain comment and draw tests ([#260](https://github.com/shumaiOne/shumai/pull/260))
- **agent**: Restrict bash access for non-owner users ([#262](https://github.com/shumaiOne/shumai/pull/262))
- **agent**: Allow create_file tool to create files directly from content ([#263](https://github.com/shumaiOne/shumai/pull/263))
- **agent**: Propagate autofill context from chat to autofill workflow ([#264](https://github.com/shumaiOne/shumai/pull/264))
- **webui**: Render select options in field creation mode and pick random option color ([#265](https://github.com/shumaiOne/shumai/pull/265))
- **project**: Include team-scoped members in project member list and add 3-section dialog layout ([#267](https://github.com/shumaiOne/shumai/pull/267))
- **webui**: Disable role dropdown for project-scoped members in team view ([#269](https://github.com/shumaiOne/shumai/pull/269))
### Fixed
- **webui**: Mention popup avatars, keyboard auto-scroll, and non-sticky section headers ([#256](https://github.com/shumaiOne/shumai/pull/256))
- **webui**: Persist field order on drag and drop ([#266](https://github.com/shumaiOne/shumai/pull/266))
### Changed
- **agent**: Load models directly from database without pi fallback ([#253](https://github.com/shumaiOne/shumai/pull/253))
- **core**: Replace generated provider files with pi-ai dynamic methods ([#255](https://github.com/shumaiOne/shumai/pull/255))
### Maintenance
- **core**: Add missing tests for methods introduced in 97069042 ([#252](https://github.com/shumaiOne/shumai/pull/252))
- **e2e**: Add domain-based auth and project web app e2e tests ([#257](https://github.com/shumaiOne/shumai/pull/257))
- **e2e**: Add file, share, and collection web app e2e tests ([#258](https://github.com/shumaiOne/shumai/pull/258))
- **e2e**: Add project-level invite and file-move e2e tests ([#259](https://github.com/shumaiOne/shumai/pull/259))
- **e2e**: Add search in file list and save-search-as-collection cases ([#261](https://github.com/shumaiOne/shumai/pull/261))
- **e2e**: Add member permission change tests ([#268](https://github.com/shumaiOne/shumai/pull/268))
</Update>
<Update label="v0.3.2" description="July 30, 2026">
### Added
- **agent**: Add output truncation and streaming limits to sandboxed bash tool ([#248](https://github.com/shumaiOne/shumai/pull/248))
### Fixed
- **agent**: Download original document asset instead of pdf proxy ([#247](https://github.com/shumaiOne/shumai/pull/247))
- **webui**: Persist chatbot sidebar input text across route navigation ([#249](https://github.com/shumaiOne/shumai/pull/249))
</Update>
<Update label="v0.3.1" description="July 30, 2026">
### Added
- **transcode**: Trigger ai metadata autofill post transcode ([#234](https://github.com/shumaiOne/shumai/pull/234))
- **dashboard**: Add agent sessions view for team owners ([#237](https://github.com/shumaiOne/shumai/pull/237))
- **db**: Preserve agent sessions on asset deletion by setting onDelete to SetNull ([#240](https://github.com/shumaiOne/shumai/pull/240))
- **agent**: Add download_asset tool and prompt instructions ([#242](https://github.com/shumaiOne/shumai/pull/242))
- **db**: Update Asset.sizeByte and AiUsage token fields to BigInt ([#244](https://github.com/shumaiOne/shumai/pull/244))
### Fixed
- **agent**: Include select option labels and field name in autofill schema ([#235](https://github.com/shumaiOne/shumai/pull/235))
- **agent**: Scope agent comment sessions to thread sessions anchored at root comments ([#239](https://github.com/shumaiOne/shumai/pull/239))
- **agent**: Disable tools for session naming and make naming non-blocking ([#241](https://github.com/shumaiOne/shumai/pull/241))
- **webui**: Update file size formatting to SI decimal standard ([#245](https://github.com/shumaiOne/shumai/pull/245))
- **s3**: Enforce property syntax in S3Service interface and fix ReadableStream handling in S3StorageService ([#246](https://github.com/shumaiOne/shumai/pull/246))
</Update>
<Update label="v0.3.0" description="July 28, 2026">
### Added
- **file-browser**: Add copy name and path option to context menu ([#225](https://github.com/shumaiOne/shumai/pull/225))
- **agent**: Inject user name and role into chat context ([#226](https://github.com/shumaiOne/shumai/pull/226))
- **agent**: Refactor database session storage to normalized DAG entries and lazy thread sync ([#229](https://github.com/shumaiOne/shumai/pull/229))
- **agent**: Support ENABLE_WEAKER_NESTED_SANDBOX environment variable ([#233](https://github.com/shumaiOne/shumai/pull/233))
### Fixed
- **agent**: Ensure atomic appendEntry and persist leaf entries in DatabaseSessionStorage ([#224](https://github.com/shumaiOne/shumai/pull/224))
- Sharp version mismatch bug ([#230](https://github.com/shumaiOne/shumai/pull/230))
- **agent**: Resolve S3 MIME type detection and prompt parameter in image analysis ([#232](https://github.com/shumaiOne/shumai/pull/232))
### Changed
- **agent**: Remove implicit agent mention trigger in comment threads ([#227](https://github.com/shumaiOne/shumai/pull/227))
### Maintenance
- **workflow**: Add docker compose deployment verification job ([#231](https://github.com/shumaiOne/shumai/pull/231))
</Update>
<Update label="v0.2.3" description="July 25, 2026">
### Fixed
- **webui**: Show right sidebar by default on file detail page ([#219](https://github.com/shumaiOne/shumai/pull/219))
- **webui**: Refresh file list and detail when agent executes asset creation tools ([#220](https://github.com/shumaiOne/shumai/pull/220))
- **webui**: Fix space key drag overlay and shift range selection for version stacks ([#221](https://github.com/shumaiOne/shumai/pull/221))
- **transcode**: Handle timestamp rounding tolerance for screenshot annotations ([#223](https://github.com/shumaiOne/shumai/pull/223))
### Changed
- **e2e**: Split transcode workflow E2E tests into per-workflow test files ([#222](https://github.com/shumaiOne/shumai/pull/222))
</Update>
<Update label="v0.2.2" description="July 23, 2026">
### Added
- **webui**: Integrate AI usage API into dashboard page ([#216](https://github.com/shumaiOne/shumai/pull/216))
- **ai-usage**: Add team and member token usage tracking and APIs ([#215](https://github.com/shumaiOne/shumai/pull/215))
- **transcode**: Add PSD support via ImageMagick and enforce sRGB conversion ([#217](https://github.com/shumaiOne/shumai/pull/217))
### Fixed
- **search**: Fix buildSqlCondition date range, numeric metadata, and string parsing bugs ([#213](https://github.com/shumaiOne/shumai/pull/213))
- **webui**: Prevent horizontal overflow in search dialog result rows ([#214](https://github.com/shumaiOne/shumai/pull/214))
- **webui**: Invalidate upload tasks query when upload task starts and completes ([#218](https://github.com/shumaiOne/shumai/pull/218))
</Update>
<Update label="v0.2.1" description="July 22, 2026">
### Added
- **skill**: Add team owner skill permission control ([#209](https://github.com/shumaiOne/shumai/pull/209))
### Fixed
- **agent**: Handle non-builtin models in getModelFromDb and upgrade pi-ai ([#211](https://github.com/shumaiOne/shumai/pull/211))
- **provider**: Preserve model ids on provider update ([#212](https://github.com/shumaiOne/shumai/pull/212))
### Changed
- **core**: Split generated providers into per-provider files ([#210](https://github.com/shumaiOne/shumai/pull/210))
</Update>
<Update label="v0.2.0" description="July 21, 2026">
### Added
- **transcode**: Add PDF preview, sprite generation, and annotation support ([#193](https://github.com/shumaiOne/shumai/pull/193))
- **web**: Register pdf.worker route in production ([#195](https://github.com/shumaiOne/shumai/pull/195))
- **agent**: Add read_pdf_pages tool and PDF page context support ([#196](https://github.com/shumaiOne/shumai/pull/196))
- **transcode**: Split monolithic transcodeMedia into focused workflows ([#197](https://github.com/shumaiOne/shumai/pull/197))
- **transcode**: Add PDF proxy support for TXT and CSV files ([#199](https://github.com/shumaiOne/shumai/pull/199))
- **asset**: Replace mediaType/mimeType logic with proxyType ([#200](https://github.com/shumaiOne/shumai/pull/200))
- **docker**: Install fonts-noto-cjk in runner stage ([#202](https://github.com/shumaiOne/shumai/pull/202))
- **transcode**: Add markdown file to pdf proxy support ([#203](https://github.com/shumaiOne/shumai/pull/203))
- **chat**: Track context asset changes and update agent context ([#204](https://github.com/shumaiOne/shumai/pull/204))
- **agent**: Refactor media tools to static injection with mandatory assetId and authz ([#208](https://github.com/shumaiOne/shumai/pull/208))
### Fixed
- **transcode**: Mark pdfkit as external and extract for docker runtime ([#201](https://github.com/shumaiOne/shumai/pull/201))
- **agent**: Include skill id in formatSkillsForPrompt ([#205](https://github.com/shumaiOne/shumai/pull/205))
- **asset**: Exclude soft-deleted children from latestChildren preview ([#206](https://github.com/shumaiOne/shumai/pull/206))
- **agent**: Pass latest version asset from version stack to prompt builder ([#207](https://github.com/shumaiOne/shumai/pull/207))
</Update>
<Update label="v0.1.10" description="July 16, 2026">
### Added
- **workflow-e2e**: Add E2E tests for agentAutofillMedia workflow ([#188](https://github.com/shumaiOne/shumai/pull/188))
- **comments**: Support comment deletion and video player shortcuts ([#191](https://github.com/shumaiOne/shumai/pull/191))
- **agent**: Support disabling specific tools for agents ([#192](https://github.com/shumaiOne/shumai/pull/192))
### Maintenance
- **e2e**: Add E2E workflow tests for remaining agent and transcode services ([#189](https://github.com/shumaiOne/shumai/pull/189))
</Update>
<Update label="v0.1.9" description="July 14, 2026">
### Added
- **e2e**: Set up fullstack app-level e2e test framework and signup test case ([#184](https://github.com/shumaiOne/shumai/pull/184))
- **chat**: Chatbot UI ([#185](https://github.com/shumaiOne/shumai/pull/185))
- **agent**: Support aborting agent execution ([#186](https://github.com/shumaiOne/shumai/pull/186))
### Changed
- **api/chat**: Remove direct Prisma query from API layer ([#187](https://github.com/shumaiOne/shumai/pull/187))
</Update>
<Update label="v0.1.8" description="July 10, 2026">
### Added
- **chatbot**: Implement type-safe Chat APIs with compaction support ([#180](https://github.com/shumaiOne/shumai/pull/180))
### Fixed
- **webui**: Enable build splitting and code-split all page routes ([#183](https://github.com/shumaiOne/shumai/pull/183))
### Documentation
- **readme**: Clarify displayed file size represents original file size ([#182](https://github.com/shumaiOne/shumai/pull/182))
</Update>
<Update label="v0.1.7" description="July 6, 2026">
### Added
- **audio**: Support frame-accurate audio playback, comments, and AI safeguards ([#175](https://github.com/shumaiOne/shumai/pull/175))
- **i18n**: Localize members dialog, notifications, uploads, user menus, dates, and players ([#178](https://github.com/shumaiOne/shumai/pull/178))
- **comments**: Allow marking comments as complete or incomplete ([#179](https://github.com/shumaiOne/shumai/pull/179))
### Fixed
- **upload**: Resolve empty and generic MIME types in confirmFileUpload ([#176](https://github.com/shumaiOne/shumai/pull/176))
### Changed
- **webui**: Modularize file viewer components into registry-driven architecture ([#174](https://github.com/shumaiOne/shumai/pull/174))
### Documentation
- Improve documentation and examples for S3 compatible storage ([#177](https://github.com/shumaiOne/shumai/pull/177))
</Update>
<Update label="v0.1.6" description="July 4, 2026">
### Added
- **file-browser**: Show video duration on file card preview ([#170](https://github.com/shumaiOne/shumai/pull/170))
- **webui**: Compare versions view for version stacks ([#171](https://github.com/shumaiOne/shumai/pull/171))
### Fixed
- **webui**: Resolve conditional hooks and setState-in-render errors ([#167](https://github.com/shumaiOne/shumai/pull/167))
- **webui**: Resolve video player total frames mismatch ([#172](https://github.com/shumaiOne/shumai/pull/172))
- **version-stack**: Resolve correct latest version ID of version stack ([#173](https://github.com/shumaiOne/shumai/pull/173))
### Maintenance
- **webui**: Video player e2e framework + Safari playhead fix ([#166](https://github.com/shumaiOne/shumai/pull/166))
- **webui**: Add frame-accurate comment seek roundtrip e2e ([#168](https://github.com/shumaiOne/shumai/pull/168))
- **webui**: Verify video player restarts playback after end ([#169](https://github.com/shumaiOne/shumai/pull/169))
</Update>
<Update label="v0.1.5" description="July 2, 2026">
### Changed
- **storage**: Use original filenames for stored files ([#165](https://github.com/shumaiOne/shumai/pull/165))
### Maintenance
- **release**: Add Aliyun ACR push to release workflow ([#164](https://github.com/shumaiOne/shumai/pull/164))
</Update>
<Update label="v0.1.4" description="July 1, 2026">
### Added
- **transcode**: Change video poster resolution to 480p ([#161](https://github.com/shumaiOne/shumai/pull/161))
- **auth**: Allow setting user locale on signup ([#163](https://github.com/shumaiOne/shumai/pull/163))
### Fixed
- **webui**: Preserve video ended state by skipping playhead snap on ended ([#162](https://github.com/shumaiOne/shumai/pull/162))
</Update>
<Update label="v0.1.3" description="June 30, 2026">
### Added
- **webui**: Add i18n support using paraglide-js ([#156](https://github.com/shumaiOne/shumai/pull/156))
- **video**: Add frame-accurate video player, SMPTE timecodes, and format switcher ([#157](https://github.com/shumaiOne/shumai/pull/157))
### Fixed
- **webui**: Align video timeline duration and formatting with frameio ([#158](https://github.com/shumaiOne/shumai/pull/158))
- **webui**: Fix missing left sidebar for nested folders ([#159](https://github.com/shumaiOne/shumai/pull/159))
- **api**: Fix update team settings and make request schema type-safe ([#160](https://github.com/shumaiOne/shumai/pull/160))
</Update>
<Update label="v0.1.2" description="June 25, 2026">
### Changed
- **s3**: Remove automatic port appending to AWS_ENDPOINT_URL_S3 ([#155](https://github.com/shumaiOne/shumai/pull/155))
</Update>
<Update label="v0.1.1" description="June 23, 2026">
### Added
- **docker**: Add root entrypoint with privilege dropping for data volumes ([#151](https://github.com/shumaiOne/shumai/pull/151))
</Update>
<Update label="v0.1.0" description="June 22, 2026">
### Added
- **share**: Secure share info API and fix wrong password feedback ([#150](https://github.com/shumaiOne/shumai/pull/150))
### Fixed
- **webui**: Truncate long folder, collection, and share link names in sidebar ([#149](https://github.com/shumaiOne/shumai/pull/149))
</Update>
<Update label="v0.0.11" description="June 22, 2026">
### Added
- **cli**: Add shumai-cli and token authentication ([#144](https://github.com/shumaiOne/shumai/pull/144))
- **settings**: Use singular headers and remove collapse/counters for single agent types ([#145](https://github.com/shumaiOne/shumai/pull/145))
- **folders**: Auto expand folder tree in left sidebar on navigation ([#146](https://github.com/shumaiOne/shumai/pull/146))
- **metadata**: Add single user and multiple user custom fields ([#147](https://github.com/shumaiOne/shumai/pull/147))
### Maintenance
- **cli**: Rename npm package to @shumai-one/shumai-cli ([#148](https://github.com/shumaiOne/shumai/pull/148))
</Update>
<Update label="v0.0.10" description="June 21, 2026">
### Changed
- **web**: Dynamically register production HTML bundle routes ([#142](https://github.com/shumaiOne/shumai/pull/142))
### Documentation
- **readme**: Polish structure, correct grammar, and add dependencies table ([#143](https://github.com/shumaiOne/shumai/pull/143))
</Update>
<Update label="v0.0.9" description="June 20, 2026">
### Added
- **webui**: Show app version in avatar menu ([#139](https://github.com/shumaiOne/shumai/pull/139))
- **cli**: Add background daemonization and subcommands ([#141](https://github.com/shumaiOne/shumai/pull/141))
### Maintenance
- **release**: Add smoke tests to local release stage ([#140](https://github.com/shumaiOne/shumai/pull/140))
</Update>
<Update label="v0.0.8" description="June 19, 2026">
### Added
- **api**: Implement read-only mode for reviewers ([#122](https://github.com/shumaiOne/shumai/pull/122))
- **server**: Allow customizing server port via SHUMAI_SERVER_PORT ([#124](https://github.com/shumaiOne/shumai/pull/124))
- **embedding**: Defer embedding workflow, use transcoded assets, and execute chunks in separate activities ([#125](https://github.com/shumaiOne/shumai/pull/125))
- **webui**: Add external drag-and-drop file and folder upload support ([#126](https://github.com/shumaiOne/shumai/pull/126))
- **agent**: Implement overlapping video chunks for semantic search ([#127](https://github.com/shumaiOne/shumai/pull/127))
- **webui**: Support jumping to video timestamp from search results ([#128](https://github.com/shumaiOne/shumai/pull/128))
- **auth**: Add demo mode support ([#131](https://github.com/shumaiOne/shumai/pull/131))
- **auth**: Refine demo mode support ([#132](https://github.com/shumaiOne/shumai/pull/132))
- **webui**: Default right sidebar to collapsed for new users ([#133](https://github.com/shumaiOne/shumai/pull/133))
- **webui**: Use Shadcn Switch in toggle field and Rating component in search filter panel ([#137](https://github.com/shumaiOne/shumai/pull/137))
- **upload**: Track byte-level progress with XMLHttpRequest ([#138](https://github.com/shumaiOne/shumai/pull/138))
### Fixed
- **transcode**: Handle high-precision FPS using rational fractions ([#123](https://github.com/shumaiOne/shumai/pull/123))
- **db**: Automatically update project updatedAt on asset modification ([#129](https://github.com/shumaiOne/shumai/pull/129))
- **webui**: Use system colors for fields and improve search filter select options ([#130](https://github.com/shumaiOne/shumai/pull/130))
- **search**: Fix hasAny and hasNone operators on metadata filter ([#134](https://github.com/shumaiOne/shumai/pull/134))
- **webui**: Resolve folder tree sync, search dialog reset, and sidebar actions issues ([#136](https://github.com/shumaiOne/shumai/pull/136))
### Changed
- **webui**: Fix search dialog layout height, scroll areas, and restrict filter toggle click ([#135](https://github.com/shumaiOne/shumai/pull/135))
</Update>
<Update label="v0.0.7" description="June 17, 2026">
### Added
- **workflow**: Configure transcode and agent concurrency via environment variables ([#116](https://github.com/shumaiOne/shumai/pull/116))
- **webui**: Replace hardcoded colors with system tokens ([#119](https://github.com/shumaiOne/shumai/pull/119))
- **webui**: Replace native overflow with shadcn ScrollArea in settings ([#120](https://github.com/shumaiOne/shumai/pull/120))
- **api**: Use enum for API protocol in provider config ([#121](https://github.com/shumaiOne/shumai/pull/121))
### Fixed
- **webui**: Reload video player and reset state when switching assets ([#114](https://github.com/shumaiOne/shumai/pull/114))
### Changed
- **transcode**: Relocate TranscodeService to core and flatten API package ([#115](https://github.com/shumaiOne/shumai/pull/115))
### Documentation
- Improve and restructure shumai documentation ([#118](https://github.com/shumaiOne/shumai/pull/118))
</Update>
<Update label="v0.0.6" description="June 15, 2026">
### Added
- **sandbox**: Add pending domains support for network sandbox ([#109](https://github.com/shumaiOne/shumai/pull/109))
- **webui**: Always show right sidebar and implement left vertical carousel ([#111](https://github.com/shumaiOne/shumai/pull/111))
### Fixed
- **build**: Propagate termination signals to active child process in wrappers ([#102](https://github.com/shumaiOne/shumai/pull/102))
- **transcode**: Make deterministic transcode activity failures non-retryable in Temporal ([#104](https://github.com/shumaiOne/shumai/pull/104))
- **player**: Implement seekbar dragging and match hover highlight color ([#108](https://github.com/shumaiOne/shumai/pull/108))
- **webui**: Avoid refetching all pages on file/folder reorder ([#112](https://github.com/shumaiOne/shumai/pull/112))
- **webui**: Force video-player mime type to video/mp4 ([#113](https://github.com/shumaiOne/shumai/pull/113))
### Changed
- **webui**: Use system color design tokens in video player components ([#106](https://github.com/shumaiOne/shumai/pull/106))
- **webui**: Use requestAnimationFrame for smooth video progress bar updates ([#107](https://github.com/shumaiOne/shumai/pull/107))
- **webui**: Fetch agents in mention input list dynamically ([#110](https://github.com/shumaiOne/shumai/pull/110))
### Documentation
- **readme**: Add comprehensive README.md ([#103](https://github.com/shumaiOne/shumai/pull/103))
- **readme**: Improve remote deployment and temporal execution instructions ([#105](https://github.com/shumaiOne/shumai/pull/105))
</Update>
<Update label="v0.0.5" description="June 13, 2026">
### Added
- **npm**: Auto deploy database migrations on package start ([#101](https://github.com/shumaiOne/shumai/pull/101))
</Update>
<Update label="v0.0.4" description="June 12, 2026">
### Fixed
- **cli/docker**: Resolve global CLI external dependencies and fix Docker 404 error ([#100](https://github.com/shumaiOne/shumai/pull/100))
</Update>
<Update label="v0.0.3" description="June 12, 2026">
### Fixed
- **cli**: Resolve platform binary path resolution under nested node_modules ([#99](https://github.com/shumaiOne/shumai/pull/99))
</Update>
<Update label="v0.0.2" description="June 12, 2026">
### Fixed
- **npm**: Add repository metadata to package.json for provenance verification ([#98](https://github.com/shumaiOne/shumai/pull/98))
### Maintenance
- Add release-npm.yaml workflow ([#97](https://github.com/shumaiOne/shumai/pull/97))
</Update>
<Update label="v0.0.1" description="June 12, 2026">
### Added
- Initial release of Shumai
</Update>
+12
View File
@@ -12,6 +12,14 @@
"light": "#F5B895",
"dark": "#A8384D"
},
"navbar": {
"links": [
{
"label": "Changelog",
"href": "/changelog"
}
]
},
"navigation": {
"groups": [
{
@@ -67,6 +75,10 @@
{
"group": "Temporal Deployment",
"pages": ["configuration/temporal"]
},
{
"group": "Releases",
"pages": ["changelog"]
}
]
}
+5 -2
View File
@@ -1,6 +1,6 @@
{
"name": "shumai",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"repository": {
@@ -38,7 +38,10 @@
"release:local": "bun run scripts/release-local.ts",
"release:patch": "bun run scripts/release.ts patch",
"release:minor": "bun run scripts/release.ts minor",
"release:major": "bun run scripts/release.ts major"
"release:major": "bun run scripts/release.ts major",
"changelog:extract": "bun run scripts/extract-changelog.ts",
"docs:changelog": "bun run scripts/generate-docs-changelog.ts",
"docs:changelog:check": "bun run scripts/generate-docs-changelog.ts --check"
},
"devDependencies": {
"@eslint/js": "10.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/api",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1
View File
@@ -55,6 +55,7 @@ async function applyWatermarkToAssetMedia(
width: vt.width ?? 0,
height: vt.height ?? 0,
size: 0,
hdr: vt.hdr,
})),
)
: []
+45
View File
@@ -418,6 +418,51 @@ describe('Share API', () => {
expect(body.media.imageTranscodes).toEqual([])
})
test('serves watermarked transcodes with hdr flags preserved when watermark enabled and completed', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(
new Map([
[
'file1',
watermarkMediaInfo({
videoTranscodes: [
{ key: 'files/watermarked-1080p.mp4', width: 1920, height: 1080, hdr: false },
{ key: 'files/watermarked-1080p-hdr.mp4', width: 1920, height: 1080, hdr: true },
],
}),
],
]),
)
const res = await app.request('/shares/share1/files/file1', {
method: 'GET',
headers: { 'x-share-password': 'pass' },
})
expect(res.status).toBe(200)
const body = await res.json()
expect(body.media.videoTranscodes).toEqual([
{
id: 'files/watermarked-1080p.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-1080p.mp4',
width: 1920,
height: 1080,
size: 0,
hdr: false,
},
{
id: 'files/watermarked-1080p-hdr.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-1080p-hdr.mp4',
width: 1920,
height: 1080,
size: 0,
hdr: true,
},
])
})
test('serves empty transcode arrays while watermark transcoding is in flight', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
+38
View File
@@ -260,6 +260,44 @@ describe('team api', () => {
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.hardwareAcceleration', 'auto')
})
it('PATCH /teams/:teamId/settings updates transcode.threads', async () => {
mockUpdateSettings.mockResolvedValue({ transcode: { threads: 8 } })
const res = await app.request('/teams/t1/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'transcode.threads', value: 8 }),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.transcode.threads).toBe(8)
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.threads', 8)
})
it('PATCH /teams/:teamId/settings rejects invalid transcode.threads', async () => {
const resNegative = await app.request('/teams/t1/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'transcode.threads', value: -1 }),
})
expect(resNegative.status).toBe(400)
const resTooLarge = await app.request('/teams/t1/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'transcode.threads', value: 33 }),
})
expect(resTooLarge.status).toBe(400)
const resFloat = await app.request('/teams/t1/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'transcode.threads', value: 4.5 }),
})
expect(resFloat.status).toBe(400)
})
it('PATCH /teams/:teamId/settings updates appearance.hideAgent', async () => {
mockUpdateSettings.mockResolvedValue({ appearance: { hideAgent: true } })
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/core",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+395 -2
View File
@@ -3,13 +3,14 @@ import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { HTTPException } from 'hono/http-exception'
import { AssetType, AssetStatus, Prisma } from '@shumai/db'
import { AssetType, AssetStatus, Prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
import { s3Service } from '@shumai/core/src/s3/s3'
import { uploadService } from '@shumai/core/src/upload/upload'
import { metadataService } from '@shumai/core/src/metadata/metadata'
import { AssetService } from './asset'
import { ensureJpegInStorage } from '@shumai/core/src/s3/preview-converter'
import { workflowService } from '@shumai/workflow-core'
vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: {
@@ -2529,6 +2530,209 @@ describe('AssetService', () => {
expect(updatedEntry?.sessionId).toBe(session.id)
})
})
describe('listChildren with showDeleted', () => {
const createImageFile = async (params: {
name: string
projectId: string
parentId: string
creatorId: string
thumbnailKey: string
duration?: number
sortIndex?: string
}) => {
return prisma.asset.create({
data: {
name: params.name,
type: AssetType.file,
status: AssetStatus.processed,
isDeleted: true,
projectId: params.projectId,
parentId: params.parentId,
creatorId: params.creatorId,
sizeByte: 100,
sortIndex: params.sortIndex,
mediaType: 'image/png',
media: {
duration: 0,
filesize: 0,
frames: 0,
imageTranscodes: [],
videoTranscodes: [],
finishedAt: new Date(0).toISOString(),
metadata:
params.duration === undefined
? null
: {
originalHeight: 0,
originalWidth: 0,
hasAudio: false,
duration: params.duration,
bitRate: 0,
frameRate: 0,
totalFrames: 0,
startTimecode: '00:00:00:00',
format: null,
},
original: null,
proxyType: 'image',
thumbnail: {
key: params.thumbnailKey,
width: 0,
height: 0,
quality: 0,
format: 'png',
},
},
},
})
}
it('returns previews for children of a folder trashed via deleteAssets', async () => {
const { project, user, assets } = await setupBasicAssets()
const folder = await prisma.asset.create({
data: {
name: 'Trashed Folder',
type: AssetType.folder,
status: AssetStatus.uploaded,
projectId: project.id,
parentId: assets.root.id,
creatorId: user.id,
},
})
await createImageFile({
name: 'inside-1.png',
projectId: project.id,
parentId: folder.id,
creatorId: user.id,
thumbnailKey: 'thumb-1',
})
await createImageFile({
name: 'inside-2.png',
projectId: project.id,
parentId: folder.id,
creatorId: user.id,
thumbnailKey: 'thumb-2',
})
await assetService.deleteAssets([folder.id])
const result = await assetService.listChildren({
projectId: project.id,
showDeleted: true,
assetType: 'folder',
})
expect(result.data).toHaveLength(1)
expect(result.data[0].id).toBe(folder.id)
expect(result.data[0].deletedAt).not.toBeNull()
expect(result.data[0].latestChildren).toHaveLength(2)
expect(result.data[0].latestChildren?.every((c) => c.preview?.thumbnailUrl)).toBe(true)
})
it('resolves the latest deleted version for a trashed version stack child', async () => {
const { project, user, assets } = await setupBasicAssets()
const folder = await prisma.asset.create({
data: {
name: 'Trashed Folder With Stack',
type: AssetType.folder,
status: AssetStatus.uploaded,
projectId: project.id,
parentId: assets.root.id,
creatorId: user.id,
},
})
const stack = await prisma.asset.create({
data: {
name: 'clip',
type: AssetType.version_stack,
status: AssetStatus.processed,
projectId: project.id,
parentId: folder.id,
creatorId: user.id,
},
})
await createImageFile({
name: 'clip-v1.png',
projectId: project.id,
parentId: stack.id,
creatorId: user.id,
thumbnailKey: 'v1-thumb',
duration: 11,
sortIndex: 'a1',
})
await createImageFile({
name: 'clip-v2.png',
projectId: project.id,
parentId: stack.id,
creatorId: user.id,
thumbnailKey: 'v2-thumb',
duration: 42,
sortIndex: 'a0',
})
await assetService.deleteAssets([folder.id])
const result = await assetService.listChildren({
projectId: project.id,
showDeleted: true,
assetType: 'folder',
})
const previews = result.data[0].latestChildren ?? []
expect(previews).toHaveLength(1)
// The latest version (lowest sortIndex) must be the one used for the preview
expect(previews[0].preview?.duration).toBe(42)
expect(previews[0].preview?.thumbnailUrl).toBeDefined()
})
it('still hides soft-deleted children when browsing a folder normally', async () => {
const { project, user, assets } = await setupBasicAssets()
const folder = await prisma.asset.create({
data: {
name: 'Active Folder',
type: AssetType.folder,
status: AssetStatus.uploaded,
projectId: project.id,
parentId: assets.root.id,
creatorId: user.id,
},
})
await prisma.asset.create({
data: {
name: 'active.png',
type: AssetType.file,
status: AssetStatus.processed,
isDeleted: false,
projectId: project.id,
parentId: folder.id,
creatorId: user.id,
},
})
await prisma.asset.create({
data: {
name: 'deleted.png',
type: AssetType.file,
status: AssetStatus.processed,
isDeleted: true,
deletedAt: new Date(),
projectId: project.id,
parentId: folder.id,
creatorId: user.id,
},
})
const folderInfo = await assetService.getAsset({ assetId: folder.id })
expect(folderInfo.latestChildren).toHaveLength(1)
})
})
})
describe('AssetService — natural sort by name', () => {
@@ -3004,6 +3208,65 @@ describe('AssetService — natural sort by name', () => {
await expect(assetService.emptyTrash(project.id)).resolves.not.toThrow()
})
it('should purge trashed assets whose status was processed, cancel their in-flight tasks, and delete WorkflowTasks', async () => {
const cancelSpy = vi.spyOn(workflowService, 'cancel').mockResolvedValue(undefined)
const team = await prisma.team.create({ data: { name: 'Purge Task Team' } })
const project = await prisma.project.create({
data: { name: 'Purge Task Project', teamId: team.id },
})
const rootFolder = await prisma.asset.create({
data: {
name: 'root',
type: AssetType.folder,
projectId: project.id,
status: AssetStatus.uploaded,
},
})
const user = await prisma.user.create({
data: { name: 'Test User Purge', email: `test-purge-${Date.now()}@example.com` },
})
// Asset was deleted, but status was set to 'processed' by background activity
const file = await prisma.asset.create({
data: {
name: 'skewed-status.mp4',
type: AssetType.file,
status: AssetStatus.processed,
isDeleted: true,
deletedAt: new Date(),
project: { connect: { id: project.id } },
parent: { connect: { id: rootFolder.id } },
creator: { connect: { id: user.id } },
storageKey: { create: { key: 'files/skewed-status/raw.mp4' } },
},
})
// In-flight task for this asset
const task = await prisma.workflowTask.create({
data: {
assetId: file.id,
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.processing,
},
})
await assetService.emptyTrash(project.id)
// Asset should be deleted from DB
const assetInDb = await prisma.asset.findUnique({ where: { id: file.id } })
expect(assetInDb).toBeNull()
// Task should be cancelled
expect(cancelSpy).toHaveBeenCalledWith(task.id)
// WorkflowTask should be deleted from DB
const taskInDb = await prisma.workflowTask.findUnique({ where: { id: task.id } })
expect(taskInDb).toBeNull()
cancelSpy.mockRestore()
})
})
describe('expireTrashedAssets', () => {
@@ -3116,7 +3379,53 @@ describe('AssetService — natural sort by name', () => {
'files/01TESTULID000000000000000/test-720p.mp4',
'GET',
true,
'test.mp4',
'test-720p.mp4',
)
})
it('downloading video proxy for test.mov should use proxy filename with mp4 extension instead of test.mov', async () => {
const asset = await prisma.asset.create({
data: {
name: 'test.mov',
type: AssetType.file,
status: AssetStatus.uploaded,
storageKey: {
create: { key: 'files/01TESTULID000000000000000/test.mov' },
},
},
})
await assetService.getDownloadUrl(asset.id, 'files/01TESTULID000000000000000/test-1080p.mp4')
expect(s3Service.presign).toHaveBeenCalledWith(
expect.any(String),
'files/01TESTULID000000000000000/test-1080p.mp4',
'GET',
true,
'test-1080p.mp4',
)
})
it('downloading proxy for a renamed asset should preserve new stem with proxy resolution and extension', async () => {
const asset = await prisma.asset.create({
data: {
name: 'awesome.mov',
type: AssetType.file,
status: AssetStatus.uploaded,
storageKey: {
create: { key: 'files/01TESTULID000000000000000/test.mov' },
},
},
})
await assetService.getDownloadUrl(asset.id, 'files/01TESTULID000000000000000/test-1080p.mp4')
expect(s3Service.presign).toHaveBeenCalledWith(
expect.any(String),
'files/01TESTULID000000000000000/test-1080p.mp4',
'GET',
true,
'awesome-1080p.mp4',
)
})
@@ -4858,4 +5167,88 @@ describe('AssetService — natural sort by name', () => {
expect(stackInfo?.commentsCount).toBe(1)
})
})
describe('restoreAssets with in-flight transcoding', () => {
it('should restore asset with status "processing" if a transcode task is still active', async () => {
const team = await prisma.team.create({ data: { name: 'Restore Transcode Team' } })
const project = await prisma.project.create({
data: { name: 'Restore Transcode Project', teamId: team.id },
})
const rootFolder = await prisma.asset.create({
data: {
name: 'root',
type: AssetType.folder,
projectId: project.id,
status: AssetStatus.uploaded,
},
})
const file = await prisma.asset.create({
data: {
name: 'transcoding-video.mp4',
type: AssetType.file,
projectId: project.id,
parentId: rootFolder.id,
status: AssetStatus.trashed,
isDeleted: true,
deletedAt: new Date(),
},
})
// Create an active transcode task
await prisma.workflowTask.create({
data: {
assetId: file.id,
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.processing,
},
})
await assetService.restoreAssets([file.id])
const restored = await prisma.asset.findUnique({ where: { id: file.id } })
expect(restored?.isDeleted).toBe(false)
expect(restored?.status).toBe(AssetStatus.processing)
})
it('should restore asset with status "processed" if no active transcode task exists', async () => {
const team = await prisma.team.create({ data: { name: 'Restore Completed Team' } })
const project = await prisma.project.create({
data: { name: 'Restore Completed Project', teamId: team.id },
})
const rootFolder = await prisma.asset.create({
data: {
name: 'root',
type: AssetType.folder,
projectId: project.id,
status: AssetStatus.uploaded,
},
})
const file = await prisma.asset.create({
data: {
name: 'completed-video.mp4',
type: AssetType.file,
projectId: project.id,
parentId: rootFolder.id,
status: AssetStatus.trashed,
isDeleted: true,
deletedAt: new Date(),
},
})
// Completed transcode task
await prisma.workflowTask.create({
data: {
assetId: file.id,
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.completed,
},
})
await assetService.restoreAssets([file.id])
const restored = await prisma.asset.findUnique({ where: { id: file.id } })
expect(restored?.isDeleted).toBe(false)
expect(restored?.status).toBe(AssetStatus.processed)
})
})
})
+161 -22
View File
@@ -1,4 +1,4 @@
import { prisma } from '@shumai/db'
import { cancelWorkflowTask, prisma } from '@shumai/db'
import {
AncestorFolder,
AssetInfo,
@@ -20,6 +20,7 @@ import {
ListRecentsRequest,
CommentExportFormat,
PreviewFormat,
TRASH_RETENTION_DAYS,
} from '@shumai/dtos'
import {
exportCommentsToFormat,
@@ -28,7 +29,15 @@ import {
type ExportOptions,
type ExportResult,
} from './comments-export'
import { type Asset, AssetStatus, AssetType, Prisma, type StorageKey } from '@shumai/db'
import {
type Asset,
AssetStatus,
AssetType,
Prisma,
type StorageKey,
WorkflowTaskStatus,
WorkflowTaskType,
} from '@shumai/db'
import { HTTPException } from 'hono/http-exception'
import { logger } from '@shumai/core/src/logger'
import { PaginatedData, paginateQuery, PaginationParams } from '@shumai/core/src/pagination'
@@ -46,6 +55,8 @@ import { getAgentRequiredLevel, getRoleLevel } from '@shumai/core/src/agent/perm
import { resolveEffectiveRole } from '@shumai/core/src/authz/authz'
import { metadataService } from '@shumai/core/src/metadata/metadata'
import { uploadService } from '@shumai/core/src/upload/upload'
import path from 'path'
import { stemFromKey } from '@shumai/core/src/utils/filename'
export const assetInclude = {
creator: true,
@@ -88,6 +99,31 @@ export type AssetWithIncludes = Prisma.AssetGetPayload<{
include: typeof assetInclude
}>
/**
* Same shape as {@link assetInclude}, but keeps soft-deleted children.
*
* The "Recently Deleted" view needs this because deleting a folder soft-deletes
* all of its descendants by cascade, so filtering out deleted children leaves
* the folder card with no previews of what was inside it.
*/
export const assetIncludeIncludingDeletedChildren = {
...assetInclude,
target: {
...assetInclude.target,
include: {
...assetInclude.target.include,
children: {
...assetInclude.target.include.children,
where: {},
},
},
},
children: {
...assetInclude.children,
where: {},
},
} as const
type CommentWithIncludes = Prisma.AssetCommentGetPayload<{
include: {
creator: true
@@ -688,7 +724,7 @@ export class AssetService {
throw new Error('ProjectID is required when ShowDeleted is true')
}
const thirtyDaysAgo = new Date()
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30)
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - TRASH_RETENTION_DAYS)
where = {
projectId: req.projectId,
@@ -741,11 +777,13 @@ export class AssetService {
break
}
const include = req.showDeleted ? assetIncludeIncludingDeletedChildren : assetInclude
const { data: assets, pageInfo } = await paginateQuery(
async (skip, take) => {
return this.prismaClient.asset.findMany({
where,
include: assetInclude,
include,
orderBy,
skip,
take,
@@ -755,7 +793,9 @@ export class AssetService {
req,
)
const infos = await this.toAssetInfos(assets)
const infos = await this.toAssetInfos(assets, undefined, {
includeDeletedChildren: req.showDeleted,
})
return { data: infos, pageInfo }
}
@@ -1341,7 +1381,7 @@ export class AssetService {
private async cascadeStatusToPendingPurge(rootIds: string[]): Promise<void> {
if (rootIds.length === 0) return
await this.prismaClient.$executeRaw`
const rows = await this.prismaClient.$queryRaw<{ id: string }[]>`
WITH RECURSIVE descendant AS (
SELECT id FROM assets WHERE id = ANY(${rootIds})
UNION ALL
@@ -1356,15 +1396,35 @@ export class AssetService {
WHERE s.type = 'symlink' AND s.target_id IN (SELECT id FROM all_purging_targets)
)
UPDATE assets SET status = 'pending_purge', updated_at = NOW()
WHERE id IN (SELECT id FROM all_purging_targets) OR id IN (SELECT id FROM all_affected_symlinks);
WHERE id IN (SELECT id FROM all_purging_targets) OR id IN (SELECT id FROM all_affected_symlinks)
RETURNING id;
`
const affectedIds = rows.map((r) => r.id)
if (affectedIds.length > 0) {
const inFlightTasks = await this.prismaClient.workflowTask.findMany({
where: {
assetId: { in: affectedIds },
status: { in: [WorkflowTaskStatus.pending, WorkflowTaskStatus.processing] },
},
select: { id: true },
})
for (const task of inFlightTasks) {
try {
logger.info({ taskId: task.id }, 'Cancelling in-flight workflow task for purging asset')
await cancelWorkflowTask(task.id)
} catch (err) {
logger.warn({ taskId: task.id, err }, 'Failed to cancel workflow task during purge')
}
}
}
}
async emptyTrash(projectId: string): Promise<void> {
const trashedRoots = await this.prismaClient.asset.findMany({
where: {
projectId,
status: 'trashed',
isDeleted: true,
},
select: { id: true },
@@ -1411,14 +1471,14 @@ export class AssetService {
* Cascade the 'pending_purge' status to all their descendants.
*/
private async expireTrashedAssets() {
const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)
const thirtyDaysAgo = new Date(Date.now() - TRASH_RETENTION_DAYS * 24 * 60 * 60 * 1000)
// Find up to 100 expired roots, ordered by oldest first to avoid starvation
const expiredRoots = await this.prismaClient.asset.findMany({
where: {
status: 'trashed',
deletedAt: { lt: thirtyDaysAgo },
isDeleted: true,
status: { not: AssetStatus.pending_purge },
deletedAt: { lt: thirtyDaysAgo },
},
orderBy: { deletedAt: 'asc' },
select: { id: true },
@@ -1433,6 +1493,35 @@ export class AssetService {
* Stage 2: Delete DB records for assets marked as 'pending_purge'.
*/
private async purgePendingAssets() {
const pendingAssets = await this.prismaClient.asset.findMany({
where: { status: AssetStatus.pending_purge },
select: { id: true },
})
const pendingAssetIds = pendingAssets.map((a) => a.id)
if (pendingAssetIds.length > 0) {
const inFlightTasks = await this.prismaClient.workflowTask.findMany({
where: {
assetId: { in: pendingAssetIds },
status: { in: [WorkflowTaskStatus.pending, WorkflowTaskStatus.processing] },
},
select: { id: true },
})
for (const task of inFlightTasks) {
try {
logger.info({ taskId: task.id }, 'Cancelling in-flight workflow task before purge')
await cancelWorkflowTask(task.id)
} catch (err) {
logger.warn({ taskId: task.id, err }, 'Failed to cancel workflow task during purge')
}
}
await this.prismaClient.workflowTask.deleteMany({
where: { assetId: { in: pendingAssetIds } },
})
}
const { count } = await this.prismaClient.asset.deleteMany({
where: { status: AssetStatus.pending_purge },
})
@@ -1575,11 +1664,30 @@ export class AssetService {
}
}
const activeTask = await tx.workflowTask.findFirst({
where: {
assetId: a.id,
status: { in: [WorkflowTaskStatus.pending, WorkflowTaskStatus.processing] },
type: {
in: [
WorkflowTaskType.transcode,
WorkflowTaskType.transcode_video,
WorkflowTaskType.transcode_image,
WorkflowTaskType.transcode_pdf,
WorkflowTaskType.transcode_pdf_pages,
WorkflowTaskType.transcode_screenshot,
WorkflowTaskType.transcode_image_annotation,
WorkflowTaskType.transcode_watermark,
],
},
},
})
await tx.asset.update({
where: { id: a.id },
data: {
isDeleted: false,
status: 'processed',
status: activeTask ? AssetStatus.processing : AssetStatus.processed,
deletedAt: null,
},
})
@@ -2045,7 +2153,9 @@ export class AssetService {
async toAssetInfos(
assets: AssetWithIncludes[],
previewFormat?: PreviewFormat,
options?: { includeDeletedChildren?: boolean },
): Promise<AssetInfo[]> {
const includeDeletedChildren = options?.includeDeletedChildren ?? false
const stackIds = new Set<string>()
for (const a of assets) {
@@ -2076,7 +2186,10 @@ export class AssetService {
const versionsMap = new Map<string, AssetWithIncludes['children'][0][]>()
if (stackIds.size > 0) {
const allVersions = await this.prismaClient.asset.findMany({
where: { parentId: { in: Array.from(stackIds) }, isDeleted: false },
where: {
parentId: { in: Array.from(stackIds) },
...(includeDeletedChildren ? {} : { isDeleted: false }),
},
include: {
creator: true,
agent: { include: { user: true } },
@@ -2202,7 +2315,7 @@ export class AssetService {
folderForPreview.children
) {
for (const child of folderForPreview.children) {
if (child.isDeleted) continue
if (!includeDeletedChildren && child.isDeleted) continue
let previewAsset = child as Asset
let mediaType = child.mediaType
@@ -2594,6 +2707,7 @@ export class AssetService {
let storageKey = asset.storageKey.key
let assetDir = storageKey.substring(0, storageKey.lastIndexOf('/') + 1)
let targetName = asset.name
if (!key.startsWith(assetDir) && asset.parentId) {
// Check if requested key belongs to another version in the same version stack
@@ -2603,11 +2717,14 @@ export class AssetService {
isDeleted: false,
storageKey: { key: { startsWith: key.substring(0, key.lastIndexOf('/') + 1) } },
},
select: { storageKey: { select: { key: true } } },
select: { name: true, storageKey: { select: { key: true } } },
})
if (sibling?.storageKey?.key) {
storageKey = sibling.storageKey.key
assetDir = storageKey.substring(0, storageKey.lastIndexOf('/') + 1)
if (sibling.name) {
targetName = sibling.name
}
}
}
@@ -2615,13 +2732,35 @@ export class AssetService {
throw new Error('Key does not belong to this asset')
}
return s3Service.presign(
process.env.S3_BUCKET || 'shumai',
key,
'GET',
true,
asset.name ?? undefined,
)
let downloadFilename: string | undefined
if (key === storageKey) {
downloadFilename = targetName ?? undefined
} else {
const keyBasename = path.posix.basename(key)
const originalStem = stemFromKey(storageKey)
const assetStem = targetName ? stemFromKey(targetName) : originalStem
if (
originalStem &&
assetStem &&
originalStem !== assetStem &&
keyBasename.startsWith(originalStem + '-')
) {
downloadFilename = assetStem + keyBasename.slice(originalStem.length)
} else if (
originalStem &&
assetStem &&
originalStem !== assetStem &&
keyBasename.startsWith('watermark-' + originalStem + '-')
) {
downloadFilename =
'watermark-' + assetStem + keyBasename.slice(('watermark-' + originalStem).length)
} else {
downloadFilename = keyBasename
}
}
return s3Service.presign(process.env.S3_BUCKET || 'shumai', key, 'GET', true, downloadFilename)
}
async toPreviewInfo(
+22 -2
View File
@@ -2,6 +2,7 @@ import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { teamService } from '@shumai/core/src/team/team'
import { describe, expect, it } from 'vitest'
import type { TeamSettingsResponse } from '@shumai/dtos'
describe('TeamService', () => {
setupTestDbHooks()
@@ -10,6 +11,7 @@ describe('TeamService', () => {
const team = await teamService.ensureDefaultTeam()
expect(team).toBeDefined()
expect(team.name).toBe('Default Team')
expect((team.settings as TeamSettingsResponse | null)?.transcode?.threads).toBe(0)
})
it('should create team', async () => {
@@ -363,7 +365,15 @@ describe('TeamService', () => {
})
const settings = await teamService.getSettings(team.id)
expect(settings).toEqual({ semanticSearchEnabled: false, appearance: { hideAgent: false } })
expect(settings).toEqual({
semanticSearchEnabled: false,
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
},
appearance: { hideAgent: false },
})
await teamService.updateSettings(team.id, 'theme', 'dark')
@@ -371,17 +381,27 @@ describe('TeamService', () => {
expect(newSettings).toEqual({
theme: 'dark',
semanticSearchEnabled: false,
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
},
appearance: { hideAgent: false },
})
await teamService.updateSettings(team.id, 'transcode.videoStrategy', 'all')
await teamService.updateSettings(team.id, 'transcode.hardwareAcceleration', 'auto')
await teamService.updateSettings(team.id, 'transcode.threads', 4)
await teamService.updateSettings(team.id, 'appearance.hideAgent', true)
const finalSettings = await teamService.getSettings(team.id)
expect(finalSettings).toEqual({
theme: 'dark',
transcode: { videoStrategy: 'all', hardwareAcceleration: 'auto' },
transcode: {
videoStrategy: 'all',
hardwareAcceleration: 'auto',
threads: 4,
},
appearance: { hideAgent: true },
semanticSearchEnabled: false,
})
+19 -1
View File
@@ -33,7 +33,11 @@ export class TeamService {
data: {
name: 'Default Team',
settings: {
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off' },
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
},
},
sandbox: { create: {} },
},
@@ -301,6 +305,14 @@ export class TeamService {
})
settings.semanticSearchEnabled = !!embeddingAgent
if (!settings.transcode) {
settings.transcode = {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
}
}
if (!settings.appearance) {
settings.appearance = { hideAgent: false }
} else if (settings.appearance.hideAgent === undefined) {
@@ -332,6 +344,12 @@ export class TeamService {
TeamSettingsResponse['transcode']
>['hardwareAcceleration']
delete settings['transcode.hardwareAcceleration']
} else if (key === 'transcode.threads') {
if (!settings.transcode) {
settings.transcode = {}
}
settings.transcode.threads = Number(value)
delete settings['transcode.threads']
} else if (key === 'appearance.hideAgent') {
if (!settings.appearance) {
settings.appearance = {}
+662 -11
View File
@@ -7,6 +7,7 @@ import {
getDefaultBitrateBps,
calculateMaxBitrate,
H264_ENCODER_CONFIGS,
buildSdrToneMapFilterChain,
} from './transcode'
import { s3Service } from '@shumai/core/src/s3/s3'
import * as path from 'path'
@@ -614,6 +615,76 @@ describe('TranscodeService', () => {
)
})
it('transcodeAudio should pass -threads when threads > 0', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation((file: string, args: string[], cb: any) => {
cb(null, { stdout: '', stderr: '' })
})
await transcodeService.transcodeAudio({
inputFile: 'input.wav',
outputFile: 'output.mp4',
bitrate: '128k',
threads: 4,
})
expect(child_process.execFile).toHaveBeenCalledWith(
'ffmpeg',
[
'-y',
'-loglevel',
'warning',
'-i',
'input.wav',
'-vn',
'-c:a',
'aac',
'-b:a',
'128k',
'-ac',
'2',
'-threads',
'4',
'output.mp4',
],
expect.any(Function),
)
})
it('transcodeAudio should omit -threads when threads is 0', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation((file: string, args: string[], cb: any) => {
cb(null, { stdout: '', stderr: '' })
})
await transcodeService.transcodeAudio({
inputFile: 'input.wav',
outputFile: 'output.mp4',
bitrate: '128k',
threads: 0,
})
expect(child_process.execFile).toHaveBeenCalledWith(
'ffmpeg',
[
'-y',
'-loglevel',
'warning',
'-i',
'input.wav',
'-vn',
'-c:a',
'aac',
'-b:a',
'128k',
'-ac',
'2',
'output.mp4',
],
expect.any(Function),
)
})
it('should generate PDF sprite sheet and poster using pdftoppm, ffmpeg, and sharp', async () => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation(
@@ -1241,7 +1312,7 @@ describe('TranscodeService', () => {
const encoder = await transcodeService.selectH264Encoder('auto', 'darwin')
expect(encoder.name).toBe('h264_videotoolbox')
expect(encoder.presetArgs).toEqual(['-q:v', '74'])
expect(encoder.presetArgs).toEqual([])
})
it('selectH264Encoder should select h264_nvenc on linux when available', async () => {
@@ -1377,10 +1448,10 @@ describe('TranscodeService', () => {
const encoder = await transcodeService.selectH264Encoder('auto', 'linux')
expect(encoder.name).toBe('libx264')
expect(encoder.presetArgs).toEqual(['-preset', 'fast', '-crf', '26'])
expect(encoder.presetArgs).toEqual(['-preset', 'fast', '-crf', '23', '-bf', '0'])
})
it('transcodeVideo with hardwareAcceleration off should use libx264, preset fast, crf 26, maxrate, and yuv420p', async () => {
it('transcodeVideo with hardwareAcceleration off should use libx264, preset fast, crf 23, -bf 0, maxrate, and yuv420p', async () => {
vi.mocked(execFile).mockImplementation(
(
_cmd: unknown,
@@ -1416,7 +1487,9 @@ describe('TranscodeService', () => {
'-preset',
'fast',
'-crf',
'26',
'23',
'-bf',
'0',
'-maxrate',
'720k',
'-bufsize',
@@ -1428,7 +1501,7 @@ describe('TranscodeService', () => {
)
})
it('transcodeVideo with hardwareAcceleration auto and videotoolbox should use -q:v 74 and -maxrate', async () => {
it('transcodeVideo with hardwareAcceleration auto and videotoolbox should use -b:v and no maxrate', async () => {
vi.spyOn(transcodeService, 'selectH264Encoder').mockResolvedValue(
H264_ENCODER_CONFIGS.h264_videotoolbox,
)
@@ -1465,17 +1538,16 @@ describe('TranscodeService', () => {
expect.arrayContaining([
'-c:v',
'h264_videotoolbox',
'-q:v',
'74',
'-maxrate',
'-b:v',
'720k',
'-bufsize',
'1440k',
'-pix_fmt',
'yuv420p',
]),
expect.any(Function),
)
const callArgs = vi.mocked(child_process.execFile).mock.calls[0][1] as string[]
expect(callArgs).not.toContain('-maxrate')
expect(callArgs).not.toContain('-bufsize')
})
it('transcodeVideo with hardwareAcceleration auto and nvenc should use -preset p4, -rc:v vbr, -cq:v 26, -b:v 0, and -maxrate', async () => {
@@ -1624,7 +1696,9 @@ describe('TranscodeService', () => {
'-preset',
'fast',
'-crf',
'26',
'23',
'-bf',
'0',
'-b:v',
'1500k',
'-pix_fmt',
@@ -1638,5 +1712,582 @@ describe('TranscodeService', () => {
expect.any(Function),
)
})
it('transcodeVideo with threads > 0 should pass -threads to ffmpeg', async () => {
vi.mocked(execFile).mockImplementation(
(
_cmd: unknown,
_args: unknown,
callback: unknown,
): ReturnType<typeof child_process.execFile> => {
const cb = callback as (
err: Error | null,
result: { stdout: string; stderr: string },
) => void
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
return {} as ReturnType<typeof child_process.execFile>
},
)
const outputFile = path.join(tempDir, 'out_threads.mp4')
await transcodeService.transcodeVideo({
inputFile: 'input.mp4',
outputFile,
width: 1280,
height: 720,
threads: 6,
})
expect(child_process.execFile).toHaveBeenCalledWith(
'ffmpeg',
expect.arrayContaining(['-threads', '6']),
expect.any(Function),
)
})
it('transcodeVideo with threads 0 or undefined should omit -threads', async () => {
vi.mocked(execFile).mockImplementation(
(
_cmd: unknown,
_args: unknown,
callback: unknown,
): ReturnType<typeof child_process.execFile> => {
const cb = callback as (
err: Error | null,
result: { stdout: string; stderr: string },
) => void
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
return {} as ReturnType<typeof child_process.execFile>
},
)
const outputFile = path.join(tempDir, 'out_threads_0.mp4')
await transcodeService.transcodeVideo({
inputFile: 'input.mp4',
outputFile,
width: 1280,
height: 720,
threads: 0,
})
expect(child_process.execFile).not.toHaveBeenCalledWith(
'ffmpeg',
expect.arrayContaining(['-threads']),
expect.any(Function),
)
})
it('transcodeVideo with signal should pass signal to execFile', async () => {
vi.mocked(execFile).mockImplementation(
(
_cmd: unknown,
_args: unknown,
optionsOrCallback: unknown,
maybeCallback?: unknown,
): ReturnType<typeof child_process.execFile> => {
const cb = (
typeof optionsOrCallback === 'function' ? optionsOrCallback : maybeCallback
) as (err: Error | null, result: { stdout: string; stderr: string }) => void
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
return {} as ReturnType<typeof child_process.execFile>
},
)
const controller = new AbortController()
const outputFile = path.join(tempDir, 'out_signal.mp4')
await transcodeService.transcodeVideo({
inputFile: 'input.mp4',
outputFile,
width: 1280,
height: 720,
signal: controller.signal,
})
expect(child_process.execFile).toHaveBeenCalledWith(
'ffmpeg',
expect.any(Array),
{ signal: controller.signal },
expect.any(Function),
)
})
})
describe('HDR detection, tone mapping, and transcoding', () => {
it('buildSdrToneMapFilterChain constructs zscale + tonemap filter chain for PQ and HLG', () => {
const available = new Set(['zscale', 'tonemap'])
const pqChain = buildSdrToneMapFilterChain({
hdrType: 'pq',
availableFilters: available,
})
expect(pqChain).toContain(
'setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc',
)
expect(pqChain).toContain('zscale=tin=smpte2084:pin=bt2020:min=bt2020nc')
expect(pqChain).toContain('tonemap=tonemap=hable:desat=0:peak=100')
expect(pqChain).toContain('format=yuv420p')
const hlgChain = buildSdrToneMapFilterChain({
hdrType: 'hlg',
availableFilters: available,
})
expect(hlgChain).toContain(
'setparams=color_primaries=bt2020:color_trc=arib-std-b67:colorspace=bt2020nc',
)
expect(hlgChain).toContain('zscale=tin=arib-std-b67:pin=bt2020:min=bt2020nc')
expect(hlgChain).toContain('tonemap=tonemap=hable')
})
it('buildSdrToneMapFilterChain throws error if zscale or tonemap is missing for PQ/HLG', () => {
expect(() =>
buildSdrToneMapFilterChain({
hdrType: 'pq',
availableFilters: new Set(['zscale']),
}),
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
expect(() =>
buildSdrToneMapFilterChain({
hdrType: 'hlg',
availableFilters: new Set(['tonemap']),
}),
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
})
it('buildSdrToneMapFilterChain constructs zscale + tonemap filter chain for Dolby Vision Profile 5', () => {
const chain = buildSdrToneMapFilterChain({
hdrType: 'dovi_p5',
availableFilters: new Set(['zscale', 'tonemap']),
})
expect(chain).toContain(
'setparams=color_primaries=bt2020:color_trc=smpte2084:colorspace=bt2020nc',
)
expect(chain).toContain('tin=smpte2084')
expect(chain).toContain('tonemap=tonemap=hable')
expect(chain).toContain('m=bt709')
})
it('buildSdrToneMapFilterChain throws error if zscale or tonemap is missing for Dolby Vision Profile 5', () => {
expect(() =>
buildSdrToneMapFilterChain({
hdrType: 'dovi_p5',
availableFilters: new Set(['tonemap']),
}),
).toThrow(/zscale and tonemap filters are required for HDR tone mapping/)
})
const mockExecFileStdout = (mockOutput: string) => {
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, _args, cb) => {
cb(null, { stdout: mockOutput, stderr: '' })
})
}
it('getVideoInfo detects PQ HDR from smpte2084 color_transfer', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 3840,
height: 2160,
r_frame_rate: '24/1',
color_transfer: 'smpte2084',
color_primaries: 'bt2020',
color_space: 'bt2020nc',
bits_per_raw_sample: '10',
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('hdr-pq.mp4')
expect(info.isHdr).toBe(true)
expect(info.hdrType).toBe('pq')
expect(info.colorTransfer).toBe('smpte2084')
})
it('getVideoInfo detects HLG HDR from arib-std-b67 color_transfer', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
color_transfer: 'arib-std-b67',
color_primaries: 'bt2020',
color_space: 'bt2020nc',
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('hdr-hlg.mp4')
expect(info.isHdr).toBe(true)
expect(info.hdrType).toBe('hlg')
expect(info.colorTransfer).toBe('arib-std-b67')
})
it('getVideoInfo treats 10-bit Rec.709 with BT.709 transfer as SDR', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'h264',
width: 1920,
height: 1080,
r_frame_rate: '24/1',
color_transfer: 'bt709',
color_primaries: 'bt709',
color_space: 'bt709',
bits_per_raw_sample: '10',
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('10bit-sdr.mp4')
expect(info.isHdr).toBe(false)
expect(info.hdrType).toBe('sdr')
})
it('getVideoInfo detects Dolby Vision Profile 5 via side data', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '25000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 3840,
height: 2160,
r_frame_rate: '24/1',
side_data_list: [
{
side_data_type: 'DOVI configuration record',
dv_profile: 5,
dv_level: 6,
},
],
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('dovi-p5.mp4')
expect(info.isHdr).toBe(true)
expect(info.hdrType).toBe('dovi_p5')
expect(info.dvProfile).toBe(5)
})
it('getVideoInfo treats Dolby Vision Profile 8 with BT.709 transfer as SDR', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '25000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 1920,
height: 1080,
r_frame_rate: '24/1',
color_transfer: 'bt709',
color_primaries: 'bt709',
color_space: 'bt709',
side_data_list: [
{
side_data_type: 'DOVI configuration record',
dv_profile: 8,
},
],
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('dovi-p8-sdr.mp4')
expect(info.isHdr).toBe(false)
expect(info.hdrType).toBe('sdr')
expect(info.dvProfile).toBe(8)
})
it('getVideoInfo swaps width and height when Display Matrix side data has rotation -90', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'hevc',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
side_data_list: [
{
side_data_type: 'Display Matrix',
rotation: -90,
},
],
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('vertical-display-matrix.mp4')
expect(info.originalWidth).toBe(1080)
expect(info.originalHeight).toBe(1920)
expect(info.rotation).toBe(-90)
})
it('getVideoInfo swaps width and height when tags.rotate is 90 or 270', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'h264',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
tags: {
rotate: '90',
},
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('vertical-tag.mp4')
expect(info.originalWidth).toBe(1080)
expect(info.originalHeight).toBe(1920)
expect(info.rotation).toBe(90)
})
it('getVideoInfo preserves width and height when rotation is 180 degrees', async () => {
/* eslint-disable @typescript-eslint/naming-convention */
const mockOutput = JSON.stringify({
format: { duration: '10.0', bit_rate: '20000000' },
streams: [
{
codec_type: 'video',
codec_name: 'h264',
width: 1920,
height: 1080,
r_frame_rate: '30/1',
tags: {
rotate: '180',
},
},
],
})
/* eslint-enable @typescript-eslint/naming-convention */
mockExecFileStdout(mockOutput)
const info = await transcodeService.getVideoInfo('upside-down.mp4')
expect(info.originalWidth).toBe(1920)
expect(info.originalHeight).toBe(1080)
expect(info.rotation).toBe(180)
})
it('transcodeVideo preserves HDR parameters and tags when hdr is true', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
if (args.includes('-filters')) {
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
return {}
}
if (args.includes('-encoders')) {
cb(null, { stdout: ' V..... libx264 ', stderr: '' })
return {}
}
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const outputFile = path.join(tempDir, 'hdr_output.mp4')
await transcodeService.transcodeVideo({
inputFile: 'hdr_input.mp4',
outputFile,
width: 1920,
height: 1080,
hdr: true,
sourceIsHdr: true,
sourceHdrType: 'pq',
sourceColorTransfer: 'smpte2084',
})
expect(executedArgs).toContain('-color_primaries')
expect(executedArgs).toContain('bt2020')
expect(executedArgs).toContain('-color_trc')
expect(executedArgs).toContain('smpte2084')
expect(executedArgs).toContain('-colorspace')
expect(executedArgs).toContain('bt2020nc')
expect(executedArgs).toContain('-x264-params')
expect(executedArgs).toContain('colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc')
})
it('transcodeVideo transcodes Dolby Vision Profile 5 to HDR proxy without libplacebo', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
if (args.includes('-filters')) {
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
return {}
}
if (args.includes('-encoders')) {
cb(null, { stdout: ' V..... libx264 ', stderr: '' })
return {}
}
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const outputFile = path.join(tempDir, 'dovi_p5_hdr.mp4')
await transcodeService.transcodeVideo({
inputFile: 'dovi_p5_input.mp4',
outputFile,
width: 1920,
height: 1080,
hdr: true,
sourceIsHdr: true,
sourceHdrType: 'dovi_p5',
})
const filterIdx = executedArgs.indexOf('-filter_complex')
expect(filterIdx).toBeGreaterThan(-1)
const filterComplex = executedArgs[filterIdx + 1]
expect(filterComplex).not.toContain('libplacebo')
expect(executedArgs).toContain('-color_primaries')
expect(executedArgs).toContain('bt2020')
expect(executedArgs).toContain('-color_trc')
expect(executedArgs).toContain('smpte2084')
})
it('generateSprite uses split=2 filterComplex for HDR inputs', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
if (args.includes('-filters')) {
cb(null, { stdout: ' ... zscale ... \n ... tonemap ... ', stderr: '' })
return {}
}
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const spritePath = path.join(tempDir, 'sprite.webp')
const posterPath = path.join(tempDir, 'poster.webp')
await transcodeService.generateSprite('input.mp4', spritePath, posterPath, 100, undefined, {
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
})
const filterIdx = executedArgs.indexOf('-filter_complex')
expect(filterIdx).toBeGreaterThan(-1)
const filterStr = executedArgs[filterIdx + 1]
expect(filterStr).toContain('split=2[v_sprite][v_thumb]')
expect(filterStr).toContain('[v_sprite]fps=')
expect(filterStr).toContain('[v_thumb]scale=')
})
it('generateSprite uses split=2 filterComplex for SDR inputs', async () => {
let executedArgs: string[] = []
;(
child_process.execFile as unknown as {
mockImplementation: (
fn: (
file: string,
args: string[],
cb: (err: Error | null, res: { stdout: string; stderr: string }) => void,
) => unknown,
) => void
}
).mockImplementation((_file, args, cb) => {
executedArgs = args
cb(null, { stdout: '', stderr: '' })
return {}
})
const spritePath = path.join(tempDir, 'sprite.webp')
const posterPath = path.join(tempDir, 'poster.webp')
await transcodeService.generateSprite('input.mp4', spritePath, posterPath, 100)
const filterIdx = executedArgs.indexOf('-filter_complex')
expect(filterIdx).toBeGreaterThan(-1)
const filterStr = executedArgs[filterIdx + 1]
expect(filterStr).toContain('[0:v]split=2[v_sprite][v_thumb]')
expect(filterStr).toContain('[v_sprite]fps=')
expect(filterStr).toContain('[v_thumb]scale=')
})
})
})
+301 -39
View File
@@ -87,6 +87,8 @@ export function parseCsvContent(content: string): string[][] {
}
}
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
export interface MediaMetadata {
originalWidth: number
originalHeight: number
@@ -103,6 +105,14 @@ export interface MediaMetadata {
audioSampleRate?: number
audioBitDepth?: number
mimeType: string
colorTransfer?: string
colorPrimaries?: string
colorSpace?: string
isHdr?: boolean
hdrType?: HdrType
dvProfile?: number
dvCompatibilityId?: number
rotation?: number
}
export interface TranscodeVideoParams {
@@ -116,6 +126,14 @@ export interface TranscodeVideoParams {
hardwareAcceleration?: 'off' | 'auto'
videoBitrate?: string
sourceVideoBitrate?: number
threads?: number
signal?: AbortSignal
hdr?: boolean
sourceIsHdr?: boolean
sourceHdrType?: HdrType
sourceColorTransfer?: string
sourceColorPrimaries?: string
sourceColorSpace?: string
}
export interface EncoderConfig {
@@ -138,11 +156,11 @@ export const H264_ENCODER_CONFIGS: Record<string, EncoderConfig> = {
},
h264_videotoolbox: {
name: 'h264_videotoolbox',
presetArgs: ['-q:v', '74'],
presetArgs: [],
},
libx264: {
name: 'libx264',
presetArgs: ['-preset', 'fast', '-crf', '26'],
presetArgs: ['-preset', 'fast', '-crf', '23', '-bf', '0'],
},
}
@@ -178,12 +196,12 @@ export function getDefaultBitrate(height: number, width?: number): string {
return `${Math.round(bps / 1000)}k`
}
export function calculateMaxBitrate(
export function calculateEffectiveBitrateBps(
targetHeight: number,
targetWidth?: number,
sourceVideoBitrate?: number,
targetFps?: number | string,
): { maxrate: string; bufsize: string } {
): number {
let configuredMaxBps = getDefaultBitrateBps(targetHeight, targetWidth)
// If frame rate is downsampled (e.g. 180p preview with < 24 fps), scale the bitrate ceiling proportionally
@@ -205,13 +223,27 @@ export function calculateMaxBitrate(
}
}
let effectiveMaxBps =
const effectiveMaxBps =
sourceVideoBitrate && sourceVideoBitrate > 0
? Math.min(configuredMaxBps, Math.round(sourceVideoBitrate * 1.2))
: configuredMaxBps
const minFloor = targetFps ? 50_000 : 100_000
effectiveMaxBps = Math.max(minFloor, effectiveMaxBps)
return Math.max(minFloor, effectiveMaxBps)
}
export function calculateMaxBitrate(
targetHeight: number,
targetWidth?: number,
sourceVideoBitrate?: number,
targetFps?: number | string,
): { maxrate: string; bufsize: string } {
const effectiveMaxBps = calculateEffectiveBitrateBps(
targetHeight,
targetWidth,
sourceVideoBitrate,
targetFps,
)
const maxrateKbps = Math.max(50, Math.round(effectiveMaxBps / 1000))
const bufsizeKbps = maxrateKbps * 2
@@ -222,6 +254,24 @@ export function calculateMaxBitrate(
}
}
export function buildSdrToneMapFilterChain(options: {
hdrType?: HdrType
availableFilters?: Set<string>
colorTransfer?: string
}): string {
if (options.availableFilters) {
if (!options.availableFilters.has('zscale') || !options.availableFilters.has('tonemap')) {
throw new Error('zscale and tonemap filters are required for HDR tone mapping')
}
}
const tin =
options.hdrType === 'hlg' || options.colorTransfer === 'arib-std-b67'
? 'arib-std-b67'
: 'smpte2084'
return `setparams=color_primaries=bt2020:color_trc=${tin}:colorspace=bt2020nc,zscale=tin=${tin}:pin=bt2020:min=bt2020nc:t=linear:npl=100,format=gbrpf32le,zscale=p=bt709,tonemap=tonemap=hable:desat=0:peak=100,zscale=t=bt709:m=bt709:out_range=full,format=yuv420p`
}
export interface ExtractVideoFramesParams {
inputFile: string
outputDir: string
@@ -430,9 +480,101 @@ export class TranscodeService {
}
}
const colorTransfer =
typeof videoStream.color_transfer === 'string'
? videoStream.color_transfer.toLowerCase()
: undefined
const colorPrimaries =
typeof videoStream.color_primaries === 'string'
? videoStream.color_primaries.toLowerCase()
: undefined
const colorSpace =
typeof videoStream.color_space === 'string'
? videoStream.color_space.toLowerCase()
: undefined
let dvProfile: number | undefined
let dvCompatibilityId: number | undefined
if (Array.isArray(videoStream.side_data_list)) {
const dovi = videoStream.side_data_list.find(
(sd: unknown): sd is Record<string, unknown> =>
typeof (sd as Record<string, unknown>)?.side_data_type === 'string' &&
String((sd as Record<string, unknown>).side_data_type)
.toLowerCase()
.includes('dovi'),
)
if (dovi) {
dvProfile = this.safeParseInt(dovi.dv_profile)
dvCompatibilityId = this.safeParseInt(dovi.dv_bl_signal_compatibility_id)
}
}
let isHdr: boolean
let hdrType: HdrType
if (dvProfile === 5) {
isHdr = true
hdrType = 'dovi_p5'
} else if (dvProfile !== undefined) {
if (colorTransfer === 'smpte2084') {
isHdr = true
hdrType = 'pq'
} else if (colorTransfer === 'arib-std-b67') {
isHdr = true
hdrType = 'hlg'
} else {
isHdr = false
hdrType = 'sdr'
}
} else {
if (colorTransfer === 'smpte2084') {
isHdr = true
hdrType = 'pq'
} else if (colorTransfer === 'arib-std-b67') {
isHdr = true
hdrType = 'hlg'
} else {
isHdr = false
hdrType = 'sdr'
}
}
let rotation = 0
if (Array.isArray(videoStream.side_data_list)) {
const displayMatrix = videoStream.side_data_list.find(
(sd: unknown): sd is Record<string, unknown> =>
typeof (sd as Record<string, unknown>)?.side_data_type === 'string' &&
String((sd as Record<string, unknown>).side_data_type).toLowerCase() === 'display matrix',
)
if (displayMatrix && typeof displayMatrix.rotation === 'number') {
rotation = displayMatrix.rotation
}
}
if (!rotation) {
const rotateTag = videoStream.tags?.rotate || info.format?.tags?.rotate
if (rotateTag) {
const parsed = parseFloat(rotateTag)
if (Number.isFinite(parsed)) {
rotation = parsed
}
}
}
const normalizedRotation = ((Math.round(rotation) % 360) + 360) % 360
const isRotatedVertical = normalizedRotation === 90 || normalizedRotation === 270
const rawWidth = typeof videoStream.width === 'number' ? videoStream.width : 0
const rawHeight = typeof videoStream.height === 'number' ? videoStream.height : 0
const originalWidth = isRotatedVertical ? rawHeight : rawWidth
const originalHeight = isRotatedVertical ? rawWidth : rawHeight
return {
originalWidth: videoStream.width,
originalHeight: videoStream.height,
originalWidth,
originalHeight,
rotation: rotation || undefined,
duration,
bitRate: parseFloat(info.format.bit_rate),
videoBitRate,
@@ -448,6 +590,13 @@ export class TranscodeService {
this.safeParseInt(audioStream?.bits_per_raw_sample) ??
this.safeParseInt(audioStream?.bits_per_sample),
mimeType: '',
colorTransfer,
colorPrimaries,
colorSpace,
isHdr,
hdrType,
dvProfile,
dvCompatibilityId,
}
}
@@ -537,6 +686,34 @@ export class TranscodeService {
}
}
private availableFiltersCache: Set<string> | null = null
clearFiltersCache(): void {
this.availableFiltersCache = null
}
async getAvailableFilters(): Promise<Set<string>> {
if (this.availableFiltersCache) {
return this.availableFiltersCache
}
try {
const { stdout } = await execFileAsync('ffmpeg', ['-filters'])
const filters = new Set<string>()
const lines = stdout.split('\n')
for (const line of lines) {
const match = line.match(/^\s*[A-Z.]{2,4}\s+([a-zA-Z0-9_-]+)/)
if (match) {
filters.add(match[1])
}
}
this.availableFiltersCache = filters
return filters
} catch (err) {
console.warn('Failed to probe ffmpeg filters:', err)
return new Set<string>()
}
}
async selectH264Encoder(
hardwareAcceleration?: 'off' | 'auto',
platform: NodeJS.Platform = process.platform,
@@ -557,14 +734,22 @@ export class TranscodeService {
}
async transcodeVideo(params: TranscodeVideoParams): Promise<void> {
const isSourceHdr =
params.sourceIsHdr ||
params.sourceHdrType === 'pq' ||
params.sourceHdrType === 'hlg' ||
params.sourceHdrType === 'dovi_p5'
const isHdrOutput = Boolean(params.hdr)
let filterComplex: string
const args: string[] = ['-i', params.inputFile]
const baseScale = `scale=w=${params.width}:h=${params.height}:force_original_aspect_ratio=decrease,scale=w='trunc(iw/2)*2':h='trunc(ih/2)*2'`
if (params.overlayFile) {
args.push('-i', params.overlayFile)
filterComplex = `[0:v]scale=${params.width}:${params.height}[vscaled];[vscaled][1:v]overlay=0:0`
} else {
filterComplex = `[0:v]scale=w=${params.width}:h=${params.height}:force_original_aspect_ratio=decrease,scale=w='trunc(iw/2)*2':h='trunc(ih/2)*2'`
filterComplex = `[0:v]${baseScale}`
}
if (params.frameRate) {
@@ -609,27 +794,61 @@ export class TranscodeService {
args.push(...encoder.presetArgs)
}
if (params.videoBitrate) {
args.push('-b:v', params.videoBitrate)
if (encoder.name === 'h264_videotoolbox') {
if (params.videoBitrate) {
args.push('-b:v', params.videoBitrate)
} else {
const targetBps = calculateEffectiveBitrateBps(
params.height,
params.width,
params.sourceVideoBitrate,
params.frameRate,
)
const targetKbps = Math.max(50, Math.round(targetBps / 1000))
args.push('-b:v', `${targetKbps}k`)
}
} else {
const { maxrate, bufsize } = calculateMaxBitrate(
params.height,
params.width,
params.sourceVideoBitrate,
params.frameRate,
)
args.push('-maxrate', maxrate, '-bufsize', bufsize)
if (params.videoBitrate) {
args.push('-b:v', params.videoBitrate)
} else {
const { maxrate, bufsize } = calculateMaxBitrate(
params.height,
params.width,
params.sourceVideoBitrate,
params.frameRate,
)
args.push('-maxrate', maxrate, '-bufsize', bufsize)
}
}
args.push('-pix_fmt', 'yuv420p')
if (isSourceHdr && isHdrOutput) {
const isHlg = params.sourceHdrType === 'hlg' || params.sourceColorTransfer === 'arib-std-b67'
const trc = isHlg ? 'arib-std-b67' : 'smpte2084'
args.push('-color_primaries', 'bt2020', '-color_trc', trc, '-colorspace', 'bt2020nc')
if (encoder.name === 'libx264') {
args.push('-x264-params', `colorprim=bt2020:transfer=${trc}:colormatrix=bt2020nc`)
}
}
if (!params.disableAudio) {
args.push('-c:a', 'aac', '-b:a', '128k')
}
if (params.threads && params.threads > 0) {
args.push('-threads', params.threads.toString())
}
args.push('-movflags', '+faststart', '-max_muxing_queue_size', '1024', params.outputFile)
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
if (params.signal) {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args], {
signal: params.signal,
})
} else {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
}
}
async transcodeImage(
@@ -736,9 +955,23 @@ export class TranscodeService {
outputSprite: string,
outputPoster: string,
duration: number,
signal?: AbortSignal,
hdrOptions?: { isHdr?: boolean; hdrType?: HdrType; colorTransfer?: string },
): Promise<void> {
const spriteFps = 100 / duration
const filterComplex = `[0:v]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[0:v]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
let filterComplex: string
if (hdrOptions?.isHdr) {
const availableFilters = await this.getAvailableFilters()
const tonemap = buildSdrToneMapFilterChain({
hdrType: hdrOptions.hdrType,
colorTransfer: hdrOptions.colorTransfer,
availableFilters,
})
filterComplex = `[0:v]${tonemap},split=2[v_sprite][v_thumb];[v_sprite]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[v_thumb]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
} else {
filterComplex = `[0:v]split=2[v_sprite][v_thumb];[v_sprite]fps=${spriteFps},scale=w=300:h=-2,tile=10x10[sprite_out];[v_thumb]scale=-2:300:force_original_aspect_ratio=decrease,select='eq(n\\,0)'[thumb_out]`
}
const args = [
'-i',
@@ -766,19 +999,30 @@ export class TranscodeService {
'1024',
outputPoster,
]
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
if (signal) {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args], { signal })
} else {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
}
}
async generatePdfSprite(
inputFile: string,
outputSprite: string,
outputPoster: string,
signal?: AbortSignal,
): Promise<{ pageCount: number; originalWidth: number; originalHeight: number }> {
const tmpDir = this.createTempDir('pdf-sprite-')
try {
const pagePrefix = path.join(tmpDir, 'page')
try {
await execFileAsync('pdftoppm', ['-png', '-f', '1', '-l', '100', inputFile, pagePrefix])
if (signal) {
await execFileAsync('pdftoppm', ['-png', '-f', '1', '-l', '100', inputFile, pagePrefix], {
signal,
})
} else {
await execFileAsync('pdftoppm', ['-png', '-f', '1', '-l', '100', inputFile, pagePrefix])
}
} catch (err) {
const errCode = (err as Record<string, unknown>)?.code
const msg = err instanceof Error ? err.message : String(err)
@@ -835,7 +1079,11 @@ export class TranscodeService {
'75',
outputSprite,
]
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...spriteArgs])
if (signal) {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...spriteArgs], { signal })
} else {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...spriteArgs])
}
await sharp(firstPagePath, { limitInputPixels: false })
.toColorspace('srgb')
@@ -1084,21 +1332,22 @@ export class TranscodeService {
inputFile: string
outputFile: string
bitrate?: string
threads?: number
signal?: AbortSignal
}): Promise<void> {
const bitrate = params.bitrate || '128k'
const args = [
'-i',
params.inputFile,
'-vn',
'-c:a',
'aac',
'-b:a',
bitrate,
'-ac',
'2',
params.outputFile,
]
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
const args = ['-i', params.inputFile, '-vn', '-c:a', 'aac', '-b:a', bitrate, '-ac', '2']
if (params.threads && params.threads > 0) {
args.push('-threads', params.threads.toString())
}
args.push(params.outputFile)
if (params.signal) {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args], {
signal: params.signal,
})
} else {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
}
}
async extractVideoFrames(params: ExtractVideoFramesParams): Promise<string[]> {
@@ -1199,6 +1448,7 @@ export class TranscodeService {
count: number
commentTimestamp?: number | null
annotations?: PrismaJson.AnnotationList | null
signal?: AbortSignal
}): Promise<Array<{ key: string; timestamp: number }>> {
const bucket = process.env.S3_BUCKET || 'shumai'
const tmpDir = this.createTempDir('screenshot-')
@@ -1260,7 +1510,13 @@ export class TranscodeService {
'80',
localShotPath,
]
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
if (params.signal) {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args], {
signal: params.signal,
})
} else {
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
}
const isMatch =
commentTimestamp !== undefined &&
@@ -1296,6 +1552,7 @@ export class TranscodeService {
end: number
commentTimestamp?: number | null
annotations?: PrismaJson.AnnotationList | null
signal?: AbortSignal
}): Promise<Array<{ key: string; page: number }>> {
const bucket = process.env.S3_BUCKET || 'shumai'
const tmpDir = this.createTempDir('pdf-pages-')
@@ -1308,7 +1565,7 @@ export class TranscodeService {
// 2. Render pages via pdftoppm (-png -f start -l end)
const pagePrefix = path.join(tmpDir, 'page')
try {
await execFileAsync('pdftoppm', [
const pdftoppmArgs = [
'-png',
'-f',
params.start.toString(),
@@ -1316,7 +1573,12 @@ export class TranscodeService {
params.end.toString(),
pdfPath,
pagePrefix,
])
]
if (params.signal) {
await execFileAsync('pdftoppm', pdftoppmArgs, { signal: params.signal })
} else {
await execFileAsync('pdftoppm', pdftoppmArgs)
}
} catch (err) {
const errCode = (err as Record<string, unknown>)?.code
const msg = err instanceof Error ? err.message : String(err)
+52
View File
@@ -195,6 +195,58 @@ describe('UploadService', () => {
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 0,
sprite: true,
poster: true,
},
})
})
it('should pass custom transcode.threads from team settings to transcode task', async () => {
await prisma.team.update({
where: { id: teamId },
data: {
settings: {
transcode: {
videoStrategy: 'all',
hardwareAcceleration: 'auto',
threads: 12,
},
},
},
})
const task = await prisma.task.create({
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
})
const asset = await prisma.asset.create({
data: {
name: 'video-custom-threads.mp4',
type: AssetType.file,
project: { connect: { id: projectId } },
parent: { connect: { id: parentId } },
status: AssetStatus.uploading,
storageKey: {
connectOrCreate: {
where: { key: 'test-key-threads' },
create: { key: 'test-key-threads' },
},
},
},
})
await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id })
const workflowTask = await prisma.workflowTask.findFirst({
where: { assetId: asset.id, type: WorkflowTaskType.transcode_video },
})
expect(workflowTask).toBeDefined()
expect(workflowTask?.payload).toEqual({
projectId: projectId,
transcode: {
videoStrategy: 'all',
hardwareAcceleration: 'auto',
threads: 12,
sprite: true,
poster: true,
},
+5 -1
View File
@@ -331,6 +331,7 @@ export class UploadService {
})
} else {
const settings = team.settings as PrismaJson.Settings | null
const threads = settings?.transcode?.threads ?? 0
if (isVideo) {
const strategy = settings?.transcode?.videoStrategy || 'best_match'
const hardwareAcceleration = settings?.transcode?.hardwareAcceleration || 'off'
@@ -338,12 +339,15 @@ export class UploadService {
await new VideoTranscoder(tx as any, asset.id, team.id, projectId)
.setStrategy(strategy)
.setHardwareAcceleration(hardwareAcceleration)
.setThreads(threads)
.withSprite()
.withPoster()
.submit()
} else if (isAudio) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await new VideoTranscoder(tx as any, asset.id, team.id, projectId).submit()
await new VideoTranscoder(tx as any, asset.id, team.id, projectId)
.setThreads(threads)
.submit()
} else if (isImage) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await new ImageTranscoder(tx as any, asset.id, team.id, projectId).withThumbnail().submit()
+36 -3
View File
@@ -67,15 +67,26 @@ describe('handleDaemonCommands', () => {
}
})
it('runs the runFn on normal startup', async () => {
it('runs the runFn on normal foreground startup without creating a PID file', async () => {
process.argv = ['node', 'script.js']
const runFn = vi.fn().mockResolvedValue(undefined)
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
expect(existsSync(pidFile)).toBe(true)
expect(readFileSync(pidFile, 'utf8').trim()).toBe(process.pid.toString())
expect(existsSync(pidFile)).toBe(false)
})
it('runs foreground startup even if a stale or conflicting PID file exists', async () => {
process.argv = ['node', 'script.js']
const runFn = vi.fn().mockResolvedValue(undefined)
mkdirSync(join(mockTempDir, '.shumai', 'pids'), { recursive: true })
writeFileSync(pidFile, '12345')
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
})
it('stops the process if stop command is passed', async () => {
@@ -122,4 +133,26 @@ describe('handleDaemonCommands', () => {
expect(spawn).toHaveBeenCalled()
expect(mockExit).toHaveBeenCalledWith(0)
})
it('runs and manages PID file when running as a daemonized child', async () => {
process.argv = ['node', 'script.js']
const originalEnv = process.env.SHUMAI_DAEMONIZED
process.env.SHUMAI_DAEMONIZED = 'true'
try {
const runFn = vi.fn().mockResolvedValue(undefined)
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
expect(existsSync(pidFile)).toBe(true)
expect(readFileSync(pidFile, 'utf8').trim()).toBe(process.pid.toString())
} finally {
if (originalEnv !== undefined) {
process.env.SHUMAI_DAEMONIZED = originalEnv
} else {
delete process.env.SHUMAI_DAEMONIZED
}
}
})
})
+19 -29
View File
@@ -17,6 +17,9 @@ const PID_DIR = join(SHUMAI_DIR, 'pids')
const LOG_DIR = join(SHUMAI_DIR, 'logs')
function isProcessRunning(pid: number): boolean {
if (pid <= 1) {
return false
}
try {
process.kill(pid, 0)
return true
@@ -35,7 +38,7 @@ async function stopProcess(appName: string, pidFile: string): Promise<boolean> {
}
const pid = parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
if (isNaN(pid)) {
if (isNaN(pid) || pid <= 1) {
console.log(`Invalid PID found in ${pidFile}. Cleaning up file.`)
try {
unlinkSync(pidFile)
@@ -180,18 +183,25 @@ export async function handleDaemonCommands(
appName: string,
runFn: () => Promise<void>,
): Promise<void> {
const pidFile = join(PID_DIR, `${appName}.pid`)
const logFile = join(LOG_DIR, `${appName}.log`)
// Ensure directories exist
mkdirSync(PID_DIR, { recursive: true })
mkdirSync(LOG_DIR, { recursive: true })
const args = process.argv.slice(2)
const isStop = args.includes('stop')
const isRestart = args.includes('restart')
const isLogs = args.includes('logs')
const isDaemon = args.includes('-d') && process.env.SHUMAI_DAEMONIZED !== 'true'
const isDaemonizedChild = process.env.SHUMAI_DAEMONIZED === 'true'
// Normal foreground startup: do not create, check, or track PID files
if (!isStop && !isRestart && !isLogs && !isDaemon && !isDaemonizedChild) {
await runFn()
return
}
const pidFile = join(PID_DIR, `${appName}.pid`)
const logFile = join(LOG_DIR, `${appName}.log`)
// Ensure directories exist for daemon commands
mkdirSync(PID_DIR, { recursive: true })
mkdirSync(LOG_DIR, { recursive: true })
if (isStop) {
await stopProcess(appName, pidFile)
@@ -216,27 +226,7 @@ export async function handleDaemonCommands(
process.exit(0)
}
// Normal Startup logic: check if already running
if (existsSync(pidFile)) {
const pid = parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
if (!isNaN(pid) && pid !== process.pid) {
if (isProcessRunning(pid)) {
console.error(
`${appName} is already running (PID: ${pid}). Use '${appName} stop' or '${appName} restart'.`,
)
process.exit(1)
} else {
// Process is dead, clean up PID file
try {
unlinkSync(pidFile)
} catch {
// Ignore
}
}
}
}
// Write the PID file
// Daemonized child startup (SHUMAI_DAEMONIZED === 'true')
writeFileSync(pidFile, process.pid.toString(), 'utf8')
const cleanPidFile = () => {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/db",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+14
View File
@@ -18,6 +18,20 @@ export function registerWorkflowTrigger(cb: WorkflowTriggerCallback) {
onWorkflowTaskCreated = cb
}
// Global callback for workflow task cancellation (decouples db/core packages from workflow engine)
type WorkflowCancelCallback = (taskId: string) => Promise<void>
let onWorkflowTaskCancelled: WorkflowCancelCallback | null = null
export function registerWorkflowCancel(cb: WorkflowCancelCallback) {
onWorkflowTaskCancelled = cb
}
export async function cancelWorkflowTask(taskId: string): Promise<void> {
if (onWorkflowTaskCancelled) {
await onWorkflowTaskCancelled(taskId)
}
}
const isTest = process.env.NODE_ENV === 'test'
const globalForPrisma = globalThis as unknown as {
+11
View File
@@ -50,6 +50,7 @@ declare global {
// ----------------------------------------------------------------------
export type VideoTranscodeStrategy = 'best_match' | 'all'
export type HardwareAcceleration = 'off' | 'auto'
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
// ----------------------------------------------------------------------
// Collection Filter
@@ -59,6 +60,7 @@ declare global {
export interface TranscodeSettings {
videoStrategy: VideoTranscodeStrategy
hardwareAcceleration?: HardwareAcceleration
threads?: number
}
export interface MediaProviderConfig {
@@ -103,6 +105,7 @@ declare global {
width: number
height: number
resolution?: string
hdr?: boolean
}
export interface ImageTranscode {
@@ -129,6 +132,7 @@ declare global {
export interface Metadata {
originalHeight: number
originalWidth: number
rotation?: number
hasAudio: boolean
duration: number
bitRate: number
@@ -141,6 +145,12 @@ declare global {
audioChannels?: number
audioSampleRate?: number
audioBitDepth?: number
colorTransfer?: string
colorPrimaries?: string
colorSpace?: string
isHdr?: boolean
hdrType?: HdrType
dvProfile?: number
format: unknown
}
@@ -314,6 +324,7 @@ declare global {
export interface TaskSpec {
videoStrategy?: VideoTranscodeStrategy
hardwareAcceleration?: HardwareAcceleration
threads?: number
thumbnail?: boolean
sprite?: boolean
poster?: boolean
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/dtos",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+10
View File
@@ -1,6 +1,12 @@
import { z } from 'zod'
import { paginationPageInfoSchema, paginationParamsSchema } from './pagination'
/**
* Number of days a soft-deleted asset is kept before it is permanently purged.
* Shared between the backend retention logic and the WebUI countdown labels.
*/
export const TRASH_RETENTION_DAYS = 30
export const assetInfoPaginatedListSchema = z.object({
data: z.array(z.lazy(() => assetInfoSchema)),
pageInfo: paginationPageInfoSchema,
@@ -12,6 +18,7 @@ export const previewInfoSchema = z.object({
thumbnailUrl: z.string().optional(),
originalHeight: z.number().optional(),
originalWidth: z.number().optional(),
rotation: z.number().optional(),
spriteUrl: z.string().optional(),
duration: z.number().optional(),
pageCount: z.number().optional(),
@@ -54,6 +61,7 @@ export const mediaMetadataSchema = z.object({
duration: z.number().optional(),
originalWidth: z.number().optional(),
originalHeight: z.number().optional(),
rotation: z.number().optional(),
frameRate: z.number().optional(),
totalFrames: z.number().optional(),
startTimecode: z.string().optional(),
@@ -97,6 +105,7 @@ export const assetInfoSchema = z.object({
width: z.number(),
height: z.number(),
size: z.number(),
hdr: z.boolean().optional(),
}),
)
.optional(),
@@ -329,6 +338,7 @@ export interface VideoTranscode {
width: number
height: number
size: number
hdr?: boolean
}
export const postAttachmentRequestSchema = z.object({
+5
View File
@@ -89,6 +89,10 @@ export const updateTeamSettingsRequestSchema = z.union([
key: z.literal('transcode.hardwareAcceleration'),
value: z.nativeEnum(HardwareAcceleration),
}),
z.object({
key: z.literal('transcode.threads'),
value: z.number().int().min(0).max(32),
}),
z.object({
key: z.literal('appearance.hideAgent'),
value: z.boolean(),
@@ -104,6 +108,7 @@ export interface TeamSettingsResponse {
transcode?: {
videoStrategy?: VideoTranscodeStrategy
hardwareAcceleration?: HardwareAcceleration
threads?: number
}
appearance?: TeamAppearanceSettings
semanticSearchEnabled?: boolean
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/e2e",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/tableprinter",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
@@ -75,6 +75,7 @@ vi.mock('@shumai/core/src/transcode/transcode', async (importOriginal) => {
takeScreenshots: vi.fn(),
overlayAnnotations: vi.fn(),
renderPdfPages: vi.fn(),
getAvailableFilters: vi.fn().mockResolvedValue(new Set(['zscale', 'tonemap'])),
},
}
})
@@ -184,6 +185,7 @@ describe('Transcode Activities', () => {
audioChannels: 2,
audioSampleRate: 48000,
audioBitDepth: 16,
rotation: -90,
mimeType: 'video/mp4',
})
@@ -197,6 +199,7 @@ describe('Transcode Activities', () => {
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/v.mp4')
expect(result.duration).toBe(10)
expect(result.metadata?.originalWidth).toBe(1920)
expect(result.metadata?.rotation).toBe(-90)
expect(result.metadata?.videoBitRate).toBe(850000)
expect(result.metadata?.videoCodec).toBe('Advanced Video Coding')
expect(result.metadata?.audioCodec).toBe('MPEG-4 Audio')
@@ -205,7 +208,10 @@ describe('Transcode Activities', () => {
expect(result.metadata?.audioBitDepth).toBe(16)
expect(metadataService.updateAssetMetadata).toHaveBeenCalledWith(
asset.id,
expect.arrayContaining([{ key: 'file_type', value: 'video' }]),
expect.arrayContaining([
{ key: 'file_type', value: 'video' },
{ key: 'rotation', value: -90 },
]),
true,
)
})
@@ -595,6 +601,83 @@ describe('Transcode Activities', () => {
expect(updated?.hasJpegPreview).toBe(false)
expect(s3Service.putObject).toHaveBeenCalled()
})
it('should throw non-retryable ApplicationFailure and not upload when asset is pending_purge in updateAssetMediaActivity', async () => {
const asset = await prisma.asset.create({
data: {
name: 'purging.mp4',
storageKey: { create: { key: 'purging.mp4' } },
status: 'pending_purge',
type: 'file',
},
})
const putObjectSpy = vi.mocked(s3Service.putObject)
putObjectSpy.mockClear()
await expect(
updateAssetMediaActivity({
assetId: asset.id,
mediaInfo: { duration: 100 } as unknown as PrismaJson.MediaInfo,
}),
).rejects.toThrow('Asset not found, has no key, or is being purged')
expect(putObjectSpy).not.toHaveBeenCalled()
})
it('should tolerate missing or deleted asset without throwing P2025 in updateAssetMediaActivity', async () => {
const asset = await prisma.asset.create({
data: {
name: 'deleted-during-update.mp4',
storageKey: { create: { key: 'deleted-during-update.mp4' } },
status: 'uploaded',
type: 'file',
},
})
const putObjectSpy = vi.mocked(s3Service.putObject)
putObjectSpy.mockClear()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
putObjectSpy.mockImplementationOnce(async (): Promise<any> => {
await prisma.asset.delete({ where: { id: asset.id } })
return {}
})
await expect(
updateAssetMediaActivity({
assetId: asset.id,
mediaInfo: { duration: 100 } as unknown as PrismaJson.MediaInfo,
}),
).resolves.toBeUndefined()
})
it('should throw non-retryable ApplicationFailure and not upload when asset is pending_purge in transcodeVideoActivity', async () => {
await prisma.asset.create({
data: {
name: 'purging-video.mp4',
storageKey: { create: { key: 'purging-video.mp4' } },
status: 'pending_purge',
type: 'file',
},
})
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
const putObjectSpy = vi.mocked(s3Service.putObject)
putObjectSpy.mockClear()
await expect(
transcodeVideoActivity({
assetKey: 'purging-video.mp4',
filePath: '/tmp/purging-video.mp4',
videoSpec: { resolution: '720p', width: 1280, height: 720 },
duration: 10,
originalFps: 30,
}),
).rejects.toThrow('Asset or storage key has been purged or is pending purge')
expect(putObjectSpy).not.toHaveBeenCalled()
})
it('should call transcodeService.transcodeVideo', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
@@ -606,6 +689,7 @@ describe('Transcode Activities', () => {
originalFps: 30,
hardwareAcceleration: 'auto',
sourceVideoBitrate: 600_000,
threads: 8,
})
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
@@ -613,6 +697,38 @@ describe('Transcode Activities', () => {
inputFile: '/tmp/v.mp4',
hardwareAcceleration: 'auto',
sourceVideoBitrate: 600_000,
threads: 8,
}),
)
})
it('transcodeVideoActivity appends -hdr.mp4 suffix and forwards HDR metadata', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
const result = await transcodeVideoActivity({
assetKey: 'files/asset-1/video.mp4',
filePath: '/tmp/video.mp4',
videoSpec: { resolution: '1080p', width: 1920, height: 1080, hdr: true },
duration: 10,
originalFps: 30,
sourceIsHdr: true,
sourceHdrType: 'pq',
sourceColorTransfer: 'smpte2084',
sourceColorPrimaries: 'bt2020',
sourceColorSpace: 'bt2020nc',
})
expect(result.key).toBe('files/asset-1/video-1080p-hdr.mp4')
expect(result.hdr).toBe(true)
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
expect.objectContaining({
inputFile: '/tmp/video.mp4',
hdr: true,
sourceIsHdr: true,
sourceHdrType: 'pq',
sourceColorTransfer: 'smpte2084',
sourceColorPrimaries: 'bt2020',
sourceColorSpace: 'bt2020nc',
}),
)
})
@@ -731,6 +847,26 @@ describe('Transcode Activities', () => {
).rejects.toThrowError(/Video transcoding failed/)
})
it('should throw non-retryable ApplicationFailure when transcodeVideoActivity is cancelled', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
const abortError = new Error('The operation was aborted')
abortError.name = 'AbortError'
vi.mocked(transcodeService.transcodeVideo).mockRejectedValue(abortError)
const promise = transcodeVideoActivity({
assetKey: 'v.mp4',
filePath: '/tmp/v.mp4',
videoSpec: { resolution: '720p', width: 1280, height: 720 },
duration: 10,
originalFps: 30,
})
await expect(promise).rejects.toThrowError(/Video transcoding cancelled/)
await expect(promise).rejects.toMatchObject({
nonRetryable: true,
})
})
it('should throw non-retryable ApplicationFailure when transcodeImageActivity fails with sharp error', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(transcodeService.transcodeImage).mockRejectedValue(new Error('sharp failed'))
@@ -774,6 +910,44 @@ describe('Transcode Activities', () => {
).rejects.toThrowError(/Sprite\/Poster generation failed/)
})
it('generateSpriteActivity forwards HDR options to transcodeService.generateSprite', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(transcodeService.generateSprite).mockImplementation(
async (_in, spriteOut, posterOut) => {
fs.writeFileSync(spriteOut, Buffer.from('fake-sprite'))
fs.writeFileSync(posterOut, Buffer.from('fake-poster'))
},
)
await generateSpriteActivity({
assetKey: 'files/asset-1/video.mp4',
filePath: '/tmp/video.mp4',
mediaInfo: {
duration: 10,
metadata: {
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
},
} as unknown as PrismaJson.MediaInfo,
spriteSpec: { key: 'files/asset-1/sprite.webp', frames: 100, tileX: 10, tileY: 10 },
posterSpec: { key: 'files/asset-1/poster.webp' },
})
expect(transcodeService.generateSprite).toHaveBeenCalledWith(
'/tmp/video.mp4',
expect.any(String),
expect.any(String),
10,
undefined,
{
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
},
)
})
it('should throw non-retryable ApplicationFailure when takeScreenshotsActivity fails with error', async () => {
vi.mocked(transcodeService.takeScreenshots).mockRejectedValue(new Error('FFmpeg failed'))
@@ -958,16 +1132,15 @@ describe('Transcode Activities', () => {
vi.mocked(s3Service.resolveInput).mockResolvedValue('https://mock-r2.com/video.mp4')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation(
(
file: string,
args: string[],
cb: (err: Error | null, result: { stdout: string; stderr: string }) => void,
) => {
(file: string, args: string[], optionsOrCb: unknown, maybeCb?: unknown) => {
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb
if (file === 'ffmpeg') {
const outPath = args[args.length - 1]
fs.writeFileSync(outPath, 'fake-poster-bytes')
}
cb(null, { stdout: '', stderr: '' })
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
},
)
@@ -990,6 +1163,7 @@ describe('Transcode Activities', () => {
'-c:v',
'libwebp',
]),
expect.objectContaining({ signal: undefined }),
expect.any(Function),
)
expect(s3Service.putObject).toHaveBeenCalledWith(
@@ -1001,6 +1175,131 @@ describe('Transcode Activities', () => {
)
})
it('extractPosterActivity applies tone mapping filter when isHdr is true', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(s3Service.resolveInput).mockResolvedValue('https://mock-r2.com/video.mp4')
let ffmpegArgs: string[] = []
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation(
(file: string, args: string[], optionsOrCb: unknown, maybeCb?: unknown) => {
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb
if (file === 'ffmpeg') {
ffmpegArgs = args
const outPath = args[args.length - 1]
fs.writeFileSync(outPath, 'fake-poster-bytes')
}
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
},
)
await extractPosterActivity({
assetKey: 'video.mp4',
posterSpec: { key: 'files/asset-1/poster.webp' },
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
})
const vfIndex = ffmpegArgs.indexOf('-vf')
expect(vfIndex).toBeGreaterThan(-1)
const vfArg = ffmpegArgs[vfIndex + 1]
expect(vfArg).toContain('zscale=tin=smpte2084')
expect(vfArg).toContain('tonemap=tonemap=hable')
expect(vfArg).toContain('scale=-2:300')
})
it('should throw non-retryable ApplicationFailure when poster extraction is cancelled with aborted signal', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
const controller = new AbortController()
controller.abort()
await expect(
extractPosterActivity({
assetKey: 'video.mp4',
posterSpec: { key: 'files/asset-1/poster.webp' },
signal: controller.signal,
}),
).rejects.toMatchObject({
message: 'Poster extraction cancelled',
nonRetryable: true,
})
})
it('should throw non-retryable ApplicationFailure when poster extraction ffmpeg execution is aborted', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(s3Service.resolveInput).mockResolvedValue('https://mock-r2.com/video.mp4')
const controller = new AbortController()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation(
(_file: string, _args: string[], optionsOrCb: unknown, maybeCb?: unknown) => {
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb
controller.abort()
const abortErr = new Error('The operation was aborted')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(abortErr as any).code = 'ABORT_ERR'
if (typeof cb === 'function') {
cb(abortErr, { stdout: '', stderr: '' })
}
},
)
await expect(
extractPosterActivity({
assetKey: 'video.mp4',
posterSpec: { key: 'files/asset-1/poster.webp' },
signal: controller.signal,
}),
).rejects.toMatchObject({
message: 'Poster extraction cancelled',
nonRetryable: true,
})
})
it('should throw non-retryable ApplicationFailure and not upload when asset is pending_purge before poster upload', async () => {
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
vi.mocked(s3Service.resolveInput).mockResolvedValue('https://mock-r2.com/video.mp4')
const putObjectSpy = vi.mocked(s3Service.putObject)
putObjectSpy.mockClear()
await prisma.asset.create({
data: {
name: 'purging-poster.mp4',
storageKey: { create: { key: 'purging-poster.mp4' } },
status: 'pending_purge',
type: 'file',
},
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(child_process.execFile as any).mockImplementation(
(file: string, args: string[], optionsOrCb: unknown, maybeCb?: unknown) => {
const cb = typeof optionsOrCb === 'function' ? optionsOrCb : maybeCb
if (file === 'ffmpeg') {
const outPath = args[args.length - 1]
fs.writeFileSync(outPath, 'fake-poster-bytes')
}
if (typeof cb === 'function') {
cb(null, { stdout: '', stderr: '' })
}
},
)
await expect(
extractPosterActivity({
assetKey: 'purging-poster.mp4',
posterSpec: { key: 'files/asset-1/poster.webp' },
}),
).rejects.toMatchObject({
message: 'Asset or storage key has been purged or is pending purge',
nonRetryable: true,
})
expect(putObjectSpy).not.toHaveBeenCalled()
})
it('should delete S3 object successfully', async () => {
await deleteS3ObjectActivity({ key: 'files/test-key.mp4' })
expect(s3Service.deleteObject).toHaveBeenCalledWith('shumai', 'files/test-key.mp4')
@@ -1013,12 +1312,14 @@ describe('Transcode Activities', () => {
const res = await transcodeAudioActivity({
assetKey: 'files/proj-123/a.wav',
filePath: '/tmp/a.wav',
threads: 4,
})
expect(transcodeService.transcodeAudio).toHaveBeenCalledWith({
inputFile: '/tmp/a.wav',
outputFile: expect.stringContaining('a-audio-proxy.mp4'),
bitrate: '128k',
threads: 4,
})
expect(s3Service.putObject).toHaveBeenCalledWith(
@@ -1247,5 +1548,56 @@ describe('Transcode Activities', () => {
})
expect(task).toBeNull()
})
it('should create ai_metadata_autofill task when asset is in trash (isDeleted: true)', async () => {
const user = await prisma.user.create({
data: { name: 'Test User Trashed Autofill', email: 'test-trashed-autofill@test.com' },
})
const team = await prisma.team.create({
data: { name: 'Test Team Trashed Autofill' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: user.id, role: 'owner' },
})
const project = await prisma.project.create({
data: { name: 'Test Project Trashed Autofill', teamId: team.id },
})
const autofillAgent = await prisma.agent.create({
data: {
id: user.id,
type: 'autofill',
enabled: true,
teamId: team.id,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
config: { provider: 'test', model: 'test' } as any,
},
})
const asset = await prisma.asset.create({
data: {
name: 'trashed-video.mp4',
mediaType: 'video/mp4',
type: 'file',
status: 'trashed',
isDeleted: true,
projectId: project.id,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
media: { proxyType: 'video' } as any,
},
})
await createAutofillTaskIfEnabledActivity({
assetId: asset.id,
teamId: team.id,
projectId: project.id,
})
const task = await prisma.workflowTask.findFirst({
where: { assetId: asset.id, type: 'ai_metadata_autofill' },
})
expect(task).toBeDefined()
expect(task?.status).toBe('pending')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((task?.payload as any)?.agent?.agentId).toBe(autofillAgent.id)
})
})
})
+258 -17
View File
@@ -1,6 +1,10 @@
import { prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
import { AssetStatus, prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
import { s3Service } from '@shumai/core/src/s3/s3'
import { transcodeService } from '@shumai/core/src/transcode/transcode'
import {
transcodeService,
buildSdrToneMapFilterChain,
type HdrType,
} from '@shumai/core/src/transcode/transcode'
import { metadataService } from '@shumai/core/src/metadata/metadata'
import { getDerivedArtifactDirectory, stemFromKey } from '@shumai/core/src/utils/filename'
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
@@ -12,7 +16,17 @@ import {
isMarkdownDocument,
isOfficeDocument,
} from '@shumai/core/src/utils/mime'
import { ApplicationFailure } from '@temporalio/activity'
import { logger } from '@shumai/core/src/logger'
import { ApplicationFailure, Context } from '@temporalio/activity'
import { getLocalTaskAbortSignal } from '@shumai/workflow-core'
function getActivityCancellationSignal(taskId?: string): AbortSignal | undefined {
try {
return Context.current().cancellationSignal
} catch {
return getLocalTaskAbortSignal(taskId)
}
}
import * as path from 'path'
import * as fs from 'fs'
import * as os from 'os'
@@ -47,6 +61,24 @@ function getErrorDetails(err: unknown): { code?: string; message: string; name?:
}
}
async function ensureAssetNotPurging(assetKey: string): Promise<void> {
const sk = await prisma.storageKey.findUnique({
where: { key: assetKey },
include: { assets: { select: { id: true, status: true } } },
})
if (
sk &&
(sk.status === 'purging' ||
sk.assets.length === 0 ||
sk.assets.every((a) => a.status === AssetStatus.pending_purge))
) {
throw ApplicationFailure.create({
message: 'Asset or storage key has been purged or is pending purge',
nonRetryable: true,
})
}
}
export async function getMediaInfoActivity(params: {
filePath: string
assetId: string
@@ -114,6 +146,13 @@ export async function getMediaInfoActivity(params: {
audioChannels: info.audioChannels,
audioSampleRate: info.audioSampleRate,
audioBitDepth: info.audioBitDepth,
colorTransfer: info.colorTransfer,
colorPrimaries: info.colorPrimaries,
colorSpace: info.colorSpace,
isHdr: info.isHdr,
hdrType: info.hdrType,
dvProfile: info.dvProfile,
rotation: info.rotation,
format: {},
}
metadataUpdates.push(
@@ -123,6 +162,12 @@ export async function getMediaInfoActivity(params: {
{ key: 'bitRate', value: info.bitRate / 1000 },
{ key: 'frame_rate', value: info.frameRate },
)
if (info.rotation !== undefined)
metadataUpdates.push({ key: 'rotation', value: info.rotation })
if (info.isHdr !== undefined)
metadataUpdates.push({ key: 'is_hdr', value: info.isHdr ? 1 : 0 })
if (info.colorTransfer)
metadataUpdates.push({ key: 'color_transfer', value: info.colorTransfer })
if (info.videoCodec) metadataUpdates.push({ key: 'video_codec', value: info.videoCodec })
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
if (info.audioChannels !== undefined)
@@ -216,6 +261,7 @@ export async function getMediaInfoActivity(params: {
}
export interface VideoActivityParams {
taskId?: string
assetKey: string
filePath: string
videoSpec: PrismaJson.VideoTranscode
@@ -223,6 +269,12 @@ export interface VideoActivityParams {
originalFps: number
hardwareAcceleration?: PrismaJson.HardwareAcceleration
sourceVideoBitrate?: number
threads?: number
sourceIsHdr?: boolean
sourceHdrType?: HdrType
sourceColorTransfer?: string
sourceColorPrimaries?: string
sourceColorSpace?: string
}
export async function transcodeVideoActivity(
@@ -231,7 +283,16 @@ export async function transcodeVideoActivity(
const bucket = process.env.S3_BUCKET || 'shumai'
const stem = stemFromKey(params.assetKey)
const res = params.videoSpec.resolution || `${params.videoSpec.height}p`
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${res}.mp4`)
const suffix = params.videoSpec.hdr ? `${res}-hdr` : res
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${suffix}.mp4`)
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'Video transcoding cancelled',
nonRetryable: true,
})
}
try {
await s3Service.headObject(bucket, key)
@@ -241,7 +302,7 @@ export async function transcodeVideoActivity(
}
const tmpDir = path.dirname(params.filePath)
const outputFile = path.join(tmpDir, `${stem}-${res}.mp4`)
const outputFile = path.join(tmpDir, `${stem}-${suffix}.mp4`)
try {
let targetFps: number | string = params.originalFps || 30
@@ -267,10 +328,19 @@ export async function transcodeVideoActivity(
disableAudio,
hardwareAcceleration: params.hardwareAcceleration,
sourceVideoBitrate: params.sourceVideoBitrate,
threads: params.threads,
signal,
hdr: params.videoSpec.hdr,
sourceIsHdr: params.sourceIsHdr,
sourceHdrType: params.sourceHdrType,
sourceColorTransfer: params.sourceColorTransfer,
sourceColorPrimaries: params.sourceColorPrimaries,
sourceColorSpace: params.sourceColorSpace,
})
const stat = fs.statSync(outputFile)
const stream = Bun.file(outputFile).stream()
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(bucket, key, stream, stat.size, 'video/mp4')
return { ...params.videoSpec, key }
@@ -278,6 +348,19 @@ export async function transcodeVideoActivity(
const { code, message } = getErrorDetails(err)
const lowerMsg = message.toLowerCase()
if (
signal?.aborted ||
code === 'ABORT_ERR' ||
message.includes('aborted') ||
lowerMsg.includes('abort')
) {
throw ApplicationFailure.create({
message: 'Video transcoding cancelled',
nonRetryable: true,
cause: err instanceof Error ? err : undefined,
})
}
if (
code === 'ENOENT' ||
lowerMsg.includes('enoent') ||
@@ -285,7 +368,9 @@ export async function transcodeVideoActivity(
lowerMsg.includes('ffprobe') ||
lowerMsg.includes('spawn') ||
lowerMsg.includes('format') ||
lowerMsg.includes('no video stream found')
lowerMsg.includes('no video stream found') ||
lowerMsg.includes('zscale') ||
lowerMsg.includes('tonemap')
) {
throw ApplicationFailure.create({
message: `Video transcoding failed: ${message}`,
@@ -300,8 +385,10 @@ export async function transcodeVideoActivity(
}
export interface AudioActivityParams {
taskId?: string
assetKey: string
filePath: string
threads?: number
}
export async function transcodeAudioActivity(
@@ -311,6 +398,14 @@ export async function transcodeAudioActivity(
const stem = stemFromKey(params.assetKey)
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-audio-proxy.mp4`)
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'Audio transcoding cancelled',
nonRetryable: true,
})
}
try {
await s3Service.headObject(bucket, key)
return { width: 0, height: 0, key }
@@ -326,10 +421,13 @@ export async function transcodeAudioActivity(
inputFile: params.filePath,
outputFile,
bitrate: '128k',
threads: params.threads,
signal,
})
const stat = fs.statSync(outputFile)
const stream = Bun.file(outputFile).stream()
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(bucket, key, stream, stat.size, 'video/mp4')
return { width: 0, height: 0, key }
@@ -337,6 +435,19 @@ export async function transcodeAudioActivity(
const { code, message } = getErrorDetails(err)
const lowerMsg = message.toLowerCase()
if (
signal?.aborted ||
code === 'ABORT_ERR' ||
message.includes('aborted') ||
lowerMsg.includes('abort')
) {
throw ApplicationFailure.create({
message: 'Audio transcoding cancelled',
nonRetryable: true,
cause: err instanceof Error ? err : undefined,
})
}
if (
code === 'ENOENT' ||
lowerMsg.includes('enoent') ||
@@ -396,6 +507,7 @@ export async function transcodeImageActivity(
},
)
const buffer = fs.readFileSync(outputFile)
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(bucket, key, buffer, buffer.length, 'image/webp')
return { ...params.imageSpec, key }
@@ -426,6 +538,7 @@ export async function transcodeImageActivity(
}
export interface GenerateSpriteActivityParams {
taskId?: string
assetKey: string
filePath: string
mediaInfo: PrismaJson.MediaInfo
@@ -435,6 +548,14 @@ export interface GenerateSpriteActivityParams {
export async function generateSpriteActivity(params: GenerateSpriteActivityParams) {
const bucket = process.env.S3_BUCKET || 'shumai'
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'Sprite/Poster generation cancelled',
nonRetryable: true,
})
}
try {
await s3Service.headObject(bucket, params.spriteSpec.key)
await s3Service.headObject(bucket, params.posterSpec.key)
@@ -453,6 +574,7 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
params.filePath,
spriteFile,
posterFile,
signal,
)
if (params.mediaInfo && params.mediaInfo.metadata) {
params.mediaInfo.metadata.totalFrames = pdfRes.pageCount
@@ -466,10 +588,17 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
spriteFile,
posterFile,
params.mediaInfo.duration,
signal,
{
isHdr: params.mediaInfo.metadata?.isHdr,
hdrType: params.mediaInfo.metadata?.hdrType,
colorTransfer: params.mediaInfo.metadata?.colorTransfer,
},
)
}
const spriteBuffer = fs.readFileSync(spriteFile)
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(
bucket,
params.spriteSpec.key,
@@ -492,13 +621,28 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
const { code, message } = getErrorDetails(err)
const lowerMsg = message.toLowerCase()
if (
signal?.aborted ||
code === 'ABORT_ERR' ||
message.includes('aborted') ||
lowerMsg.includes('abort')
) {
throw ApplicationFailure.create({
message: 'Sprite/Poster generation cancelled',
nonRetryable: true,
cause: err instanceof Error ? err : undefined,
})
}
if (
code === 'ENOENT' ||
lowerMsg.includes('enoent') ||
lowerMsg.includes('ffmpeg') ||
lowerMsg.includes('ffprobe') ||
lowerMsg.includes('spawn') ||
lowerMsg.includes('format')
lowerMsg.includes('format') ||
lowerMsg.includes('zscale') ||
lowerMsg.includes('tonemap')
) {
throw ApplicationFailure.create({
message: `Sprite/Poster generation failed: ${message}`,
@@ -606,6 +750,7 @@ export async function generatePdfProxyActivity(
const stat = fs.statSync(pdfFilePath)
const stream = Bun.file(pdfFilePath).stream()
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(bucket, pdfProxyKey, stream, stat.size, 'application/pdf')
return { pdfProxyKey, pdfFilePath }
@@ -664,9 +809,9 @@ export async function updateAssetMediaActivity(params: UpdateAssetMediaActivityP
include: { storageKey: true },
})
const key = asset?.storageKey?.key
if (!asset || !key) {
if (!asset || !key || asset.status === AssetStatus.pending_purge) {
throw ApplicationFailure.create({
message: 'Asset not found or has no key',
message: 'Asset not found, has no key, or is being purged',
nonRetryable: true,
})
}
@@ -675,14 +820,24 @@ export async function updateAssetMediaActivity(params: UpdateAssetMediaActivityP
const buffer = Buffer.from(JSON.stringify(params.mediaInfo))
await s3Service.putObject(bucket, infoKey, buffer, buffer.length, 'application/json')
await prisma.asset.update({
where: { id: params.assetId },
const { count } = await prisma.asset.updateMany({
where: {
id: params.assetId,
status: { not: AssetStatus.pending_purge },
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data: { media: params.mediaInfo as any, hasJpegPreview: false },
})
if (count === 0) {
logger.info(
{ assetId: params.assetId },
'[updateAssetMediaActivity] Asset was deleted or pending purge before media update completed',
)
}
}
export async function takeScreenshotsActivity(params: {
taskId?: string
assetKey: string
assetId: string
start: number
@@ -691,11 +846,33 @@ export async function takeScreenshotsActivity(params: {
commentTimestamp?: number | null
annotations?: PrismaJson.AnnotationList | null
}): Promise<Array<{ key: string; timestamp: number }>> {
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'Screenshot extraction cancelled',
nonRetryable: true,
})
}
try {
return await transcodeService.takeScreenshots(params)
return await transcodeService.takeScreenshots({ ...params, signal })
} catch (err) {
const { code, message } = getErrorDetails(err)
const lowerMsg = message.toLowerCase()
if (
signal?.aborted ||
code === 'ABORT_ERR' ||
message.includes('aborted') ||
lowerMsg.includes('abort')
) {
throw ApplicationFailure.create({
message: 'Screenshot extraction cancelled',
nonRetryable: true,
cause: err instanceof Error ? err : undefined,
})
}
if (
code === 'ENOENT' ||
lowerMsg.includes('enoent') ||
@@ -716,11 +893,24 @@ export async function takeScreenshotsActivity(params: {
export interface ExtractPosterActivityParams {
assetKey: string
posterSpec: PrismaJson.PosterInfo
taskId?: string
signal?: AbortSignal
isHdr?: boolean
hdrType?: HdrType
colorTransfer?: string
}
export async function extractPosterActivity(
params: ExtractPosterActivityParams,
): Promise<{ poster: PrismaJson.PosterInfo }> {
const signal = params.signal || getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'Poster extraction cancelled',
nonRetryable: true,
})
}
const bucket = process.env.S3_BUCKET || 'shumai'
try {
await s3Service.headObject(bucket, params.posterSpec.key)
@@ -736,6 +926,17 @@ export async function extractPosterActivity(
const inputSource = await s3Service.resolveInput(bucket, params.assetKey)
const isRemote = inputSource.startsWith('http://') || inputSource.startsWith('https://')
let vf = 'scale=-2:300:force_original_aspect_ratio=decrease'
if (params.isHdr) {
const availableFilters = await transcodeService.getAvailableFilters()
const tonemap = buildSdrToneMapFilterChain({
hdrType: params.hdrType,
colorTransfer: params.colorTransfer,
availableFilters,
})
vf = `${tonemap},scale=-2:300:force_original_aspect_ratio=decrease`
}
const args = [
...(isRemote
? ['-reconnect', '1', '-reconnect_streamed', '1', '-reconnect_delay_max', '5']
@@ -747,16 +948,17 @@ export async function extractPosterActivity(
'-vframes',
'1',
'-vf',
'scale=-2:300:force_original_aspect_ratio=decrease',
vf,
'-c:v',
'libwebp',
'-q:v',
'75',
posterFile,
]
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args])
await execFileAsync('ffmpeg', ['-y', '-loglevel', 'warning', ...args], { signal })
const posterBuffer = fs.readFileSync(posterFile)
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(
bucket,
params.posterSpec.key,
@@ -769,12 +971,28 @@ export async function extractPosterActivity(
} catch (err) {
const { code, message } = getErrorDetails(err)
const lowerMsg = message.toLowerCase()
if (
signal?.aborted ||
code === 'ABORT_ERR' ||
message.includes('aborted') ||
lowerMsg.includes('abort')
) {
throw ApplicationFailure.create({
message: 'Poster extraction cancelled',
nonRetryable: true,
cause: err instanceof Error ? err : undefined,
})
}
if (
code === 'ENOENT' ||
lowerMsg.includes('enoent') ||
lowerMsg.includes('nosuchkey') ||
lowerMsg.includes('ffmpeg') ||
lowerMsg.includes('sharp')
lowerMsg.includes('sharp') ||
lowerMsg.includes('zscale') ||
lowerMsg.includes('tonemap')
) {
throw ApplicationFailure.create({
message: `Poster extraction failed: ${message}`,
@@ -816,6 +1034,7 @@ export async function overlayAnnotationsActivity(params: {
}
export async function renderPdfPagesActivity(params: {
taskId?: string
assetKey: string
assetId: string
start: number
@@ -823,11 +1042,33 @@ export async function renderPdfPagesActivity(params: {
commentTimestamp?: number | null
annotations?: PrismaJson.AnnotationList | null
}): Promise<Array<{ key: string; page: number }>> {
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'PDF page rendering cancelled',
nonRetryable: true,
})
}
try {
return await transcodeService.renderPdfPages(params)
return await transcodeService.renderPdfPages({ ...params, signal })
} catch (err) {
const { code, message } = getErrorDetails(err)
const lowerMsg = message.toLowerCase()
if (
signal?.aborted ||
code === 'ABORT_ERR' ||
message.includes('aborted') ||
lowerMsg.includes('abort')
) {
throw ApplicationFailure.create({
message: 'PDF page rendering cancelled',
nonRetryable: true,
cause: err instanceof Error ? err : undefined,
})
}
if (
code === 'ENOENT' ||
lowerMsg.includes('enoent') ||
@@ -933,7 +1174,7 @@ export async function createAutofillTaskIfEnabledActivity(
project: true,
},
})
if (!asset || (asset.type !== 'file' && asset.type !== 'version_stack') || asset.isDeleted) {
if (!asset || (asset.type !== 'file' && asset.type !== 'version_stack')) {
return
}
@@ -352,6 +352,7 @@ describe('Watermark Activities', () => {
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'auto',
threads: 6,
},
},
},
@@ -398,11 +399,131 @@ describe('Watermark Activities', () => {
hardwareAcceleration: 'auto',
sourceVideoBitrate: 1800000,
disableAudio: true,
threads: 6,
}),
)
fs.rmSync(outFilePath, { force: true })
})
it('mirrors both SDR and HDR videoTranscodes preserving HDR flags and -hdr suffix', async () => {
const assetKey = 'files/hdr-wm/video.mp4'
const storageKey = await prisma.storageKey.create({ data: { key: assetKey } })
const asset = await prisma.asset.create({
data: {
name: 'video.mp4',
type: 'file',
status: 'processed',
storageKeyId: storageKey.id,
mediaType: 'video/mp4',
media: {
duration: 10,
filesize: 0,
frames: 300,
proxyType: 'video',
imageTranscodes: [],
videoPreview: { width: 1920, height: 1080 },
finishedAt: new Date().toISOString(),
original: {
key: assetKey,
filesizeInBytes: 0,
codec: '',
},
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
bitRate: 1000,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
hasAudio: true,
format: {},
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
},
videoTranscodes: [
{
key: 'files/hdr-wm/video-1080p.mp4',
resolution: '1080p',
width: 1920,
height: 1080,
hdr: false,
},
{
key: 'files/hdr-wm/video-1080p-hdr.mp4',
resolution: '1080p',
width: 1920,
height: 1080,
hdr: true,
},
],
} as PrismaJson.MediaInfo,
},
})
const config = await seedConfig()
vi.mocked(transcodeService.getVideoInfo).mockResolvedValue({
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
bitRate: 1000,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
hasAudio: true,
mimeType: 'video/mp4',
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
})
vi.mocked(s3Service.putObject).mockResolvedValue(undefined as never)
const sdrOut = path.join('/tmp', `video-watermark-${config.id}-1080p.mp4`)
const hdrOut = path.join('/tmp', `video-watermark-${config.id}-1080p-hdr.mp4`)
fs.writeFileSync(sdrOut, Buffer.from('fake sdr'))
fs.writeFileSync(hdrOut, Buffer.from('fake hdr'))
const media = await transcodeWatermarkMediaActivity({
assetId: asset.id,
watermarkConfigId: config.id,
})
expect(media.videoTranscodes).toHaveLength(2)
expect(media.videoTranscodes?.[0]).toEqual(
expect.objectContaining({
resolution: '1080p',
hdr: false,
key: expect.stringContaining(`video-watermark-${config.id}-1080p.mp4`),
}),
)
expect(media.videoTranscodes?.[1]).toEqual(
expect.objectContaining({
resolution: '1080p',
hdr: true,
key: expect.stringContaining(`video-watermark-${config.id}-1080p-hdr.mp4`),
}),
)
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
expect.objectContaining({
outputFile: sdrOut,
hdr: false,
sourceIsHdr: true,
}),
)
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
expect.objectContaining({
outputFile: hdrOut,
hdr: true,
sourceIsHdr: true,
}),
)
fs.rmSync(sdrOut, { force: true })
fs.rmSync(hdrOut, { force: true })
})
})
describe('completeWatermarkFileActivity', () => {
+30 -1
View File
@@ -150,6 +150,7 @@ export async function transcodeWatermarkMediaActivity(
const teamSettings = asset.project?.team?.settings as PrismaJson.Settings | null
const hardwareAcceleration = teamSettings?.transcode?.hardwareAcceleration ?? 'off'
const threads = teamSettings?.transcode?.threads ?? 0
// The config column is declared as PrismaJson.WatermarkConfigSpec, which is
// structurally identical to the DTO type, so no cast is required.
@@ -180,6 +181,12 @@ export async function transcodeWatermarkMediaActivity(
let startTimecode = '00:00:00:00'
let hasAudio = false
let sourceVideoBitrate: number | undefined
let colorTransfer: string | undefined
let colorPrimaries: string | undefined
let colorSpace: string | undefined
let isHdr: boolean | undefined
let hdrType: PrismaJson.HdrType | undefined
let dvProfile: number | undefined
if (isVideo) {
const info = await transcodeService.getVideoInfo(rawFilePath)
@@ -193,6 +200,12 @@ export async function transcodeWatermarkMediaActivity(
startTimecode = info.startTimecode || '00:00:00:00'
hasAudio = info.hasAudio
sourceVideoBitrate = info.videoBitRate || info.bitRate
colorTransfer = info.colorTransfer
colorPrimaries = info.colorPrimaries
colorSpace = info.colorSpace
isHdr = info.isHdr
hdrType = info.hdrType
dvProfile = info.dvProfile
} else if (isImage) {
const info = await transcodeService.getImageInfo(rawFilePath)
originalWidth = info.originalWidth
@@ -257,6 +270,12 @@ export async function transcodeWatermarkMediaActivity(
totalFrames,
startTimecode,
hasAudio,
colorTransfer: colorTransfer ?? originalMedia?.metadata?.colorTransfer,
colorPrimaries: colorPrimaries ?? originalMedia?.metadata?.colorPrimaries,
colorSpace: colorSpace ?? originalMedia?.metadata?.colorSpace,
isHdr: isHdr ?? originalMedia?.metadata?.isHdr,
hdrType: hdrType ?? originalMedia?.metadata?.hdrType,
dvProfile: dvProfile ?? originalMedia?.metadata?.dvProfile,
format: {},
},
original: {
@@ -319,6 +338,8 @@ export async function transcodeWatermarkMediaActivity(
const targetWidth = vt.width || originalWidth
const targetHeight = vt.height || originalHeight
const resolution = vt.resolution || `${targetHeight}p`
const isVtHdr = Boolean(vt.hdr)
const suffix = isVtHdr ? `${resolution}-hdr` : resolution
const svgString = generateWatermarkSvg(config, targetWidth, targetHeight, blockImagesMap)
const overlayPngBuffer = await transcodeService.renderSvgToPng(svgString)
@@ -326,7 +347,7 @@ export async function transcodeWatermarkMediaActivity(
const overlayPngPath = path.join(tmpDir, `watermarkOverlay-${i}.png`)
fs.writeFileSync(overlayPngPath, overlayPngBuffer)
const outFileName = `${stem}-watermark-${params.watermarkConfigId}-${resolution}.mp4`
const outFileName = `${stem}-watermark-${params.watermarkConfigId}-${suffix}.mp4`
const outFilePath = path.join(tmpDir, outFileName)
await transcodeService.transcodeVideo({
@@ -338,6 +359,13 @@ export async function transcodeWatermarkMediaActivity(
overlayFile: overlayPngPath,
hardwareAcceleration,
sourceVideoBitrate,
threads,
hdr: isVtHdr,
sourceIsHdr: isHdr ?? originalMedia?.metadata?.isHdr,
sourceHdrType: hdrType ?? originalMedia?.metadata?.hdrType,
sourceColorTransfer: colorTransfer ?? originalMedia?.metadata?.colorTransfer,
sourceColorPrimaries: colorPrimaries ?? originalMedia?.metadata?.colorPrimaries,
sourceColorSpace: colorSpace ?? originalMedia?.metadata?.colorSpace,
})
const stat = fs.statSync(outFilePath)
@@ -357,6 +385,7 @@ export async function transcodeWatermarkMediaActivity(
width: targetWidth,
height: targetHeight,
resolution,
hdr: isVtHdr,
})
}
mediaInfo.filesize = totalSize
+7
View File
@@ -29,6 +29,13 @@ export class VideoTranscoder {
return this
}
setThreads(threads?: number): this {
if (threads !== undefined) {
this.spec.threads = threads
}
return this
}
withSprite(): this {
this.spec.sprite = true
return this
+2 -2
View File
@@ -16,9 +16,9 @@ export async function fetchAssetWithKey(workerQueue: string, assetId: string) {
const { getAssetActivity } = getActivities()
const asset = await executeActivity(workerQueue, getAssetActivity, assetId)
const key = asset?.storageKey?.key
if (!asset || !key) {
if (!asset || !key || asset.status === 'pending_purge') {
throw ApplicationFailure.create({
message: 'Asset not found or has no key',
message: 'Asset not found, has no key, or is being purged',
nonRetryable: true,
})
}
@@ -88,6 +88,7 @@ describe('renderPdfPagesWorkflow', () => {
await renderPdfPagesWorkflow(task)
expect(mockActivities.renderPdfPagesActivity).toHaveBeenCalledWith({
taskId: 'task-pdf-pages',
assetKey: 'doc.pdf',
assetId: 'asset-pdf',
start: 1,
@@ -21,6 +21,7 @@ export async function renderPdfPagesWorkflow(task: WorkflowTask): Promise<void>
const pdfKey = (asset.media as PrismaJson.MediaInfo | null)?.pdfTranscode?.key || key
const pages = await executeActivity(workerQueue, renderPdfPagesActivity, {
taskId: task.id,
assetKey: pdfKey,
assetId: asset.id,
start: payload.pdfPages.start,
@@ -87,6 +87,7 @@ describe('takeVideoScreenshotsWorkflow', () => {
await takeVideoScreenshotsWorkflow(task)
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith({
taskId: 'task-screenshot',
assetKey: 'video.mp4',
assetId: 'asset-video',
start: 0,
@@ -157,6 +158,7 @@ describe('takeVideoScreenshotsWorkflow', () => {
await takeVideoScreenshotsWorkflow(task)
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith({
taskId: 'task-screenshot-proxy',
assetKey: 'proxy-1080p.mp4',
assetId: 'asset-video-proxy',
start: 1.2345,
@@ -166,4 +168,58 @@ describe('takeVideoScreenshotsWorkflow', () => {
annotations: [],
})
})
it('should prioritize SDR proxy over higher-resolution HDR proxy to avoid washed-out annotations', async () => {
const task: WorkflowTask = {
id: 'task-screenshot-sdr-prioritized',
assetId: 'asset-video-hdr',
type: WorkflowTaskType.transcode_screenshot,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
screenshot: {
start: 2.0,
end: 2.0,
count: 1,
commentTimestamp: 2.0,
annotations: [],
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-video-hdr',
storageKey: { key: 'raw-hdr.mp4' },
mediaType: 'video/mp4',
media: {
videoTranscodes: [
{ key: 'proxy-1080p-hdr.mp4', height: 1080, width: 1920, hdr: true },
{ key: 'proxy-720p.mp4', height: 720, width: 1280, hdr: false },
],
},
})
mockActivities.takeScreenshotsActivity.mockResolvedValue([
{ key: 'files/asset-video-hdr/screenshots/shot1.webp', timestamp: 2.0 },
])
await takeVideoScreenshotsWorkflow(task)
expect(mockActivities.takeScreenshotsActivity).toHaveBeenCalledWith(
expect.objectContaining({
assetKey: 'proxy-720p.mp4',
}),
)
})
})
@@ -23,7 +23,12 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
if (mediaInfo.videoTranscodes && mediaInfo.videoTranscodes.length > 0) {
const sorted = [...mediaInfo.videoTranscodes]
.filter((t) => t.key)
.sort((a, b) => (b.height || 0) - (a.height || 0))
.sort((a, b) => {
// Prioritize SDR over HDR to avoid washed out screenshots
if (!a.hdr && b.hdr) return -1
if (a.hdr && !b.hdr) return 1
return (b.height || 0) - (a.height || 0)
})
if (sorted.length > 0 && sorted[0].key) {
targetKey = sorted[0].key
}
@@ -33,6 +38,7 @@ export async function takeVideoScreenshotsWorkflow(task: WorkflowTask): Promise<
const { takeScreenshotsActivity } = getActivities()
const screenshots = await executeActivity(workerQueue, takeScreenshotsActivity, {
taskId: task.id,
assetKey: targetKey,
assetId: asset.id,
start: payload.screenshot.start,
@@ -187,6 +187,7 @@ describe('transcodeVideoWorkflow', () => {
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'auto',
threads: 8,
},
},
createdAt: new Date(),
@@ -238,6 +239,7 @@ describe('transcodeVideoWorkflow', () => {
filePath: '/tmp/video.mp4',
hardwareAcceleration: 'auto',
sourceVideoBitrate: 850000,
threads: 8,
}),
)
})
@@ -252,7 +254,9 @@ describe('transcodeVideoWorkflow', () => {
output: null,
payload: {
projectId: 'proj-1',
transcode: {},
transcode: {
threads: 4,
},
},
createdAt: new Date(),
updatedAt: new Date(),
@@ -300,10 +304,13 @@ describe('transcodeVideoWorkflow', () => {
await transcodeVideoWorkflow(task)
expect(mockActivities.transcodeAudioActivity).toHaveBeenCalledWith({
assetKey: 'audio.wav',
filePath: '/tmp/video.mp4',
})
expect(mockActivities.transcodeAudioActivity).toHaveBeenCalledWith(
expect.objectContaining({
assetKey: 'audio.wav',
filePath: '/tmp/video.mp4',
threads: 4,
}),
)
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
assetId: 'asset-audio',
@@ -385,6 +392,7 @@ describe('transcodeVideoWorkflow', () => {
posterSpec: {
key: 'files/asset-poster/poster.webp',
},
taskId: 'task-poster',
})
expect(mockActivities.updateAssetMediaActivity).toHaveBeenCalledWith({
@@ -394,4 +402,304 @@ describe('transcodeVideoWorkflow', () => {
}),
})
})
it('should persist poster/sprite before transcoding proxies so previews are available early', async () => {
const task: WorkflowTask = {
id: 'task-sprite',
assetId: 'asset-sprite',
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
transcode: {
poster: true,
sprite: true,
videoStrategy: 'best_match',
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid-sprite',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-sprite',
storageKey: { key: 'files/asset-sprite/video.mp4' },
mediaType: 'video/mp4',
})
mockActivities.getMediaInfoActivity.mockResolvedValue({
proxyType: 'video',
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
bitRate: 1000,
hasAudio: false,
format: {},
},
videoTranscodes: [],
imageTranscodes: [],
})
mockActivities.extractPosterActivity.mockResolvedValue({
poster: { key: 'files/asset-sprite/poster.webp' },
})
mockActivities.generateSpriteActivity.mockResolvedValue({
sprite: { key: 'files/asset-sprite/sprite.webp', frames: 100, tileX: 10, tileY: 10 },
poster: { key: 'files/asset-sprite/poster.webp' },
})
mockActivities.transcodeVideoActivity.mockResolvedValue({
key: 'files/asset-sprite/video-180p.mp4',
width: 320,
height: 180,
})
// Capture a snapshot of the media payload at each commit: the workflow mutates the same
// `mediaInfo` object in place, so the recorded mock call args would reflect the final state.
const commitSnapshots: Array<{ sprite?: unknown; videoTranscodes: unknown[] }> = []
mockActivities.updateAssetMediaActivity.mockImplementation(
(params: { mediaInfo: { sprite?: unknown; videoTranscodes?: unknown[] } }) => {
commitSnapshots.push({
sprite: params.mediaInfo.sprite,
videoTranscodes: [...(params.mediaInfo.videoTranscodes ?? [])],
})
return Promise.resolve()
},
)
await transcodeVideoWorkflow(task)
const spriteOrder = mockActivities.generateSpriteActivity.mock.invocationCallOrder[0]
const firstProxyOrder = mockActivities.transcodeVideoActivity.mock.invocationCallOrder[0]
// Sprite generation must run before any proxy transcode.
expect(spriteOrder).toBeLessThan(firstProxyOrder)
// The media commit that carries the sprite must land before the first proxy transcode too,
// and must not yet contain any proxy transcodes.
const spriteCommitIndex = commitSnapshots.findIndex((snapshot) => snapshot.sprite !== undefined)
expect(spriteCommitIndex).toBeGreaterThanOrEqual(0)
expect(commitSnapshots[spriteCommitIndex].videoTranscodes).toEqual([])
expect(
mockActivities.updateAssetMediaActivity.mock.invocationCallOrder[spriteCommitIndex],
).toBeLessThan(firstProxyOrder)
})
it('should transcode only HDR proxies and HDR 180p preview when source is HDR', async () => {
const task: WorkflowTask = {
id: 'task-hdr',
assetId: 'asset-hdr',
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
transcode: {
videoStrategy: 'best_match',
poster: true,
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid-hdr',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-hdr',
storageKey: { key: 'hdr-video.mp4' },
mediaType: 'video/mp4',
})
mockActivities.getMediaInfoActivity.mockResolvedValue({
proxyType: 'video',
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
bitRate: 1000,
videoBitRate: 850000,
hasAudio: false,
format: {},
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
colorPrimaries: 'bt2020',
colorSpace: 'bt2020nc',
},
videoTranscodes: [],
imageTranscodes: [],
})
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
return {
key: `files/asset-hdr/video-${params.videoSpec.resolution}${params.videoSpec.hdr ? '-hdr' : ''}.mp4`,
width: params.videoSpec.width,
height: params.videoSpec.height,
resolution: params.videoSpec.resolution,
hdr: params.videoSpec.hdr,
}
})
await transcodeVideoWorkflow(task)
// Poster extraction must use SDR tone mapping
expect(mockActivities.extractPosterActivity).toHaveBeenCalledWith(
expect.objectContaining({
isHdr: true,
hdrType: 'pq',
colorTransfer: 'smpte2084',
}),
)
// 180p preview must be generated as HDR (hdr: true)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '180p',
hdr: true,
}),
}),
)
// Main resolution (1080p) must be called as HDR (hdr: true)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '1080p',
hdr: true,
}),
}),
)
// No calls should have been made with hdr: false for HDR source
const calls = mockActivities.transcodeVideoActivity.mock.calls
const sdrCalls = calls.filter(
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === false,
)
expect(sdrCalls).toHaveLength(0)
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
taskId: 'task-hdr',
status: WorkflowTaskStatus.completed,
})
})
it('should transcode only SDR proxy and SDR 180p preview when source is SDR', async () => {
const task: WorkflowTask = {
id: 'task-sdr-source',
assetId: 'asset-sdr-source',
type: WorkflowTaskType.transcode_video,
status: WorkflowTaskStatus.pending,
sessionId: null,
output: null,
payload: {
projectId: 'proj-1',
transcode: {
videoStrategy: 'best_match',
poster: true,
},
},
createdAt: new Date(),
updatedAt: new Date(),
heartbeat: null,
teamId: 'team-1',
projectId: 'proj-1',
uid: 'task-uid-sdr-source',
model: null,
inputTokens: 0,
outputTokens: 0,
}
mockActivities.getAssetActivity.mockResolvedValue({
id: 'asset-sdr-source',
storageKey: { key: 'sdr-video.mp4' },
mediaType: 'video/mp4',
})
mockActivities.getMediaInfoActivity.mockResolvedValue({
proxyType: 'video',
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
startTimecode: '00:00:00:00',
bitRate: 1000,
videoBitRate: 850000,
hasAudio: false,
format: {},
isHdr: false,
},
videoTranscodes: [],
imageTranscodes: [],
})
mockActivities.transcodeVideoActivity.mockImplementation(async (params) => {
return {
key: `files/asset-sdr-source/video-${params.videoSpec.resolution}.mp4`,
width: params.videoSpec.width,
height: params.videoSpec.height,
resolution: params.videoSpec.resolution,
hdr: params.videoSpec.hdr,
}
})
await transcodeVideoWorkflow(task)
// 180p preview must be generated as SDR (hdr: false)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '180p',
hdr: false,
}),
}),
)
// Main resolution (1080p) must be generated as SDR (hdr: false)
expect(mockActivities.transcodeVideoActivity).toHaveBeenCalledWith(
expect.objectContaining({
videoSpec: expect.objectContaining({
resolution: '1080p',
hdr: false,
}),
}),
)
// No calls should have been made with hdr: true for SDR source
const calls = mockActivities.transcodeVideoActivity.mock.calls
const hdrCalls = calls.filter(
(c: unknown[]) => (c[0] as { videoSpec: { hdr?: boolean } }).videoSpec.hdr === true,
)
expect(hdrCalls).toHaveLength(0)
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
taskId: 'task-sdr-source',
status: WorkflowTaskStatus.completed,
})
})
})
@@ -68,6 +68,10 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
const posterResult = await executeActivity(workerQueue, extractPosterActivity, {
assetKey: key,
posterSpec,
taskId: task.id,
isHdr: mediaInfo.metadata?.isHdr,
hdrType: mediaInfo.metadata?.hdrType,
colorTransfer: mediaInfo.metadata?.colorTransfer,
})
mediaInfo.poster = posterResult.poster
await executeActivity(workerQueue, updateAssetMediaActivity, {
@@ -76,6 +80,43 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
})
}
// Generate the sprite (and its poster fallback) before the expensive proxy transcodes so the
// file list can show a poster/sprite preview while the asset is still processing.
if (spec.sprite || (spec.poster && !mediaInfo.poster)) {
const lastSlashIndex = key.lastIndexOf('/')
const assetDir = lastSlashIndex === -1 ? '' : key.substring(0, lastSlashIndex)
const spriteSpec: PrismaJson.SpriteInfo = {
key: assetDir ? `${assetDir}/sprite.webp` : 'sprite.webp',
frames: 100,
tileX: 10,
tileY: 10,
}
const posterSpec: PrismaJson.PosterInfo = mediaInfo.poster || {
key: assetDir ? `${assetDir}/poster.webp` : 'poster.webp',
}
const spriteResult = await executeActivity(workerQueue, generateSpriteActivity, {
taskId: task.id,
assetKey: key,
filePath,
spriteSpec,
posterSpec,
mediaInfo,
})
if (spec.sprite) {
mediaInfo.sprite = spriteResult.sprite
}
if (!mediaInfo.poster) {
mediaInfo.poster = spriteResult.poster
}
await executeActivity(workerQueue, updateAssetMediaActivity, {
assetId: asset.id,
mediaInfo,
})
}
const metadata = mediaInfo.metadata
if (mediaInfo.proxyType === 'video' && metadata) {
@@ -91,13 +132,46 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
metadata.originalHeight,
)
const isHdr = Boolean(metadata.isHdr)
if (res === '180p') {
const videoSpec: PrismaJson.VideoTranscode = {
resolution: res,
width,
height,
hdr: isHdr,
}
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
taskId: task.id,
assetKey: key,
filePath,
videoSpec,
duration: metadata.duration,
originalFps: metadata.frameRate,
hardwareAcceleration: spec.hardwareAcceleration,
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
threads: spec.threads,
sourceIsHdr: metadata.isHdr,
sourceHdrType: metadata.hdrType,
sourceColorTransfer: metadata.colorTransfer,
sourceColorPrimaries: metadata.colorPrimaries,
sourceColorSpace: metadata.colorSpace,
})
mediaInfo.videoPreview = videoTranscode
continue
}
const videoSpec: PrismaJson.VideoTranscode = {
resolution: res,
width,
height,
hdr: isHdr,
}
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
taskId: task.id,
assetKey: key,
filePath,
videoSpec,
@@ -105,21 +179,25 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
originalFps: metadata.frameRate,
hardwareAcceleration: spec.hardwareAcceleration,
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
threads: spec.threads,
sourceIsHdr: metadata.isHdr,
sourceHdrType: metadata.hdrType,
sourceColorTransfer: metadata.colorTransfer,
sourceColorPrimaries: metadata.colorPrimaries,
sourceColorSpace: metadata.colorSpace,
})
if (res === '180p') {
mediaInfo.videoPreview = videoTranscode
} else {
mediaInfo.videoTranscodes.push(videoTranscode)
}
mediaInfo.videoTranscodes.push(videoTranscode)
}
}
const isAudio = mediaInfo.proxyType === 'audio'
if (isAudio && metadata) {
const audioTranscode = await executeActivity(workerQueue, transcodeAudioActivity, {
taskId: task.id,
assetKey: key,
filePath,
threads: spec.threads,
})
mediaInfo.videoTranscodes.push(audioTranscode)
}
@@ -133,35 +211,6 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
mediaInfo.thumbnail = thumbTranscode
}
if (spec.sprite || (spec.poster && !mediaInfo.poster)) {
const lastSlashIndex = key.lastIndexOf('/')
const assetDir = lastSlashIndex === -1 ? '' : key.substring(0, lastSlashIndex)
const spriteSpec: PrismaJson.SpriteInfo = {
key: assetDir ? `${assetDir}/sprite.webp` : 'sprite.webp',
frames: 100,
tileX: 10,
tileY: 10,
}
const posterSpec: PrismaJson.PosterInfo = mediaInfo.poster || {
key: assetDir ? `${assetDir}/poster.webp` : 'poster.webp',
}
const spriteResult = await executeActivity(workerQueue, generateSpriteActivity, {
assetKey: key,
filePath,
spriteSpec,
posterSpec,
mediaInfo,
})
if (spec.sprite) {
mediaInfo.sprite = spriteResult.sprite
}
if (!mediaInfo.poster) {
mediaInfo.poster = spriteResult.poster
}
}
await executeActivity(workerQueue, updateAssetMediaActivity, {
assetId: asset.id,
mediaInfo,
@@ -144,4 +144,20 @@ describe('BreadcrumbNav component', () => {
expect(container.querySelector('.lucide-bot')).toBeNull()
})
it('renders file actions dropdown trigger button and opens on click', () => {
render(
<QueryClientProvider client={queryClient}>
<BreadcrumbNav
{...baseProps}
fileId="file-1"
currentAsset={{ id: 'file-1', name: 'sample.mov', type: 'file', version: 1 }}
allowDownload={true}
/>
</QueryClientProvider>,
)
const triggerButton = screen.getByRole('button', { name: 'sample.mov' })
expect(triggerButton).toBeDefined()
})
})
+25 -7
View File
@@ -84,6 +84,7 @@ interface BreadcrumbNavProps {
key: string
width: number
height: number
hdr?: boolean
}>
}
versions?: Array<{
@@ -133,6 +134,7 @@ export function BreadcrumbNav({
const { openMobileMenu } = useDualSidebarStore()
const [isManageVersionsOpen, setIsManageVersionsOpen] = useState(false)
const [isLinkedTasksOpen, setIsLinkedTasksOpen] = useState(false)
const [isFileMenuOpen, setIsFileMenuOpen] = useState(false)
const targetAssetId = fileId || currentAsset.id
const isRecentlyDeleted = currentAsset.name === 'Recently Deleted'
@@ -249,17 +251,32 @@ export function BreadcrumbNav({
}
return (
<DropdownMenu modal={false}>
<DropdownMenuTrigger className="flex items-center gap-1 truncate rounded px-2 py-1 text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground">
<DropdownMenu modal={false} open={isFileMenuOpen} onOpenChange={setIsFileMenuOpen}>
<div
className="flex items-center gap-1 truncate rounded px-2 py-1 text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground cursor-pointer select-none"
onClick={() => setIsFileMenuOpen((prev) => !prev)}
>
<span className="truncate">{currentAsset.name}</span>
{currentAsset.version !== undefined && (
<Badge variant="outline" className="px-1 py-0 text-xs shrink-0">
v{currentAsset.version}
</Badge>
)}
<ChevronDown className="h-4 w-4 shrink-0" />
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56" align="start">
<DropdownMenuTrigger
asChild
onClick={(e) => e.stopPropagation()}
onPointerDown={(e) => e.stopPropagation()}
>
<button
type="button"
aria-label={currentAsset.name}
className="flex items-center justify-center p-0.5 rounded shrink-0 focus:outline-none"
>
<ChevronDown className="h-4 w-4 shrink-0" />
</button>
</DropdownMenuTrigger>
</div>
<DropdownMenuContent className="w-56" align="center">
{allowDownload &&
(hasVideoTranscodes ? (
<DropdownMenuSub>
@@ -278,13 +295,14 @@ export function BreadcrumbNav({
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
const label = t.hdr ? `${resolution} (HDR)` : resolution
return (
<DropdownMenuItem
key={resolution}
key={t.key || `${resolution}-${t.hdr ? 'hdr' : 'sdr'}`}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between"
>
<span>{resolution}</span>
<span>{label}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
@@ -19,7 +19,7 @@ interface CompareControlBarProps {
onVolumeChange: (volume: number) => void
onToggleMute: () => void
onChangePlaybackRate: (rate: number) => void
onChangeResolution: (resolution: string) => void
onChangeResolution: (resolution: string, hdr?: boolean) => void
onZoomIn: () => void
onZoomOut: () => void
onFit: () => void
@@ -65,6 +65,7 @@ export function CompareControlBar({
isFullScreen,
showFrames: false,
currentResolution: v.currentResolution,
isCurrentHdr: v.isCurrentHdr,
}
// The active-side asset carries the metadata used for timecode display and
@@ -88,7 +89,7 @@ export function CompareControlBar({
toggleMute={onToggleMute}
handleVolumeChange={onVolumeChange}
changePlaybackRate={onChangePlaybackRate}
changeResolution={(res: DisplayTranscode) => onChangeResolution(res.resolution)}
changeResolution={(res: DisplayTranscode) => onChangeResolution(res.resolution, res.hdr)}
handleDownload={(key?: string) => onDownload(key)}
toggleFullScreen={onToggleFullScreen}
onZoomChange={(nz: number) => (nz >= activeState.zoom ? onZoomIn() : onZoomOut())}
@@ -213,7 +213,7 @@ export function CompareViewer({
)
const handleChangeResolution = useCallback(
(resolution: string) => getActive()?.changeResolution(resolution),
(resolution: string, hdr?: boolean) => getActive()?.changeResolution(resolution, hdr),
[getActive],
)
+2 -1
View File
@@ -23,6 +23,7 @@ export interface PaneReportedState {
playbackRate: number
isLooping: boolean
currentResolution: string
isCurrentHdr?: boolean
resolutions: DisplayTranscode[]
buffered: number
}
@@ -45,7 +46,7 @@ export interface ComparePaneHandle {
setVolume: (volume: number) => void
setPlaybackRate: (rate: number) => void
toggleLoop: () => void
changeResolution: (resolution: string) => void
changeResolution: (resolution: string, hdr?: boolean) => void
// Zoom / pan (image + video)
zoomBy: (factor: number) => void
fit: () => void
+37 -52
View File
@@ -19,7 +19,6 @@ interface DrawingCanvasProps {
imageUrl?: string
/** A live canvas to draw instead of an image URL (e.g. a PDF.js page render). */
canvasElement?: HTMLCanvasElement | null
videoElement?: HTMLVideoElement
annotations: Annotation[]
scale: number
offset: { x: number; y: number }
@@ -40,7 +39,6 @@ const DrawingCanvas = ({
mediaDimensions,
imageUrl,
canvasElement,
videoElement,
annotations,
scale,
offset,
@@ -53,7 +51,7 @@ const DrawingCanvas = ({
onAddAnnotation,
}: DrawingCanvasProps) => {
const [loadedImage] = useImage(imageUrl || '', 'anonymous')
const imageRef = useRef<Konva.Image>(null)
const mediaGroupRef = useRef<Konva.Group>(null)
const isDragging = useRef(false)
const lastPos = useRef({ x: 0, y: 0 })
const startPointRef = useRef<{ x: number; y: number } | null>(null)
@@ -66,27 +64,11 @@ const DrawingCanvas = ({
// Force a redraw whenever the live canvas source is swapped, so the layer
// picks up the new page raster (Konva redraws the source each batchDraw).
useEffect(() => {
if (canvasElement && imageRef.current) {
imageRef.current.getLayer()?.batchDraw()
if (canvasElement && mediaGroupRef.current) {
mediaGroupRef.current.getLayer()?.batchDraw()
}
}, [canvasElement])
// Handle Video Redraw
useEffect(() => {
if (videoElement && imageRef.current) {
const layer = imageRef.current.getLayer()
if (!layer) return
const anim = new Konva.Animation(() => {
// Force redraw to update video frame
}, layer)
anim.start()
return () => {
anim.stop()
}
}
}, [videoElement])
// -- Helpers --
const getRelativePointerPosition = (
node: Konva.Node,
@@ -217,7 +199,7 @@ const DrawingCanvas = ({
const handleGlobalMove = (e: MouseEvent | TouchEvent) => {
if (!isDragging.current) return
const stage = imageRef.current?.getStage()
const stage = mediaGroupRef.current?.getStage()
if (!stage) return
const container = stage.container()
const rect = container.getBoundingClientRect()
@@ -255,11 +237,11 @@ const DrawingCanvas = ({
if (activeDrawing) {
if (tool === 'select') return
const pos = getRelativePointerPosition(imageRef.current!, true, stagePos)
const pos = getRelativePointerPosition(mediaGroupRef.current!, true, stagePos)
if (!pos || !startPointRef.current) return
const start = startPointRef.current
const layer = imageRef.current?.getLayer()
const layer = mediaGroupRef.current?.getLayer()
if (tool === 'freehand' && currentLineRef.current) {
const newPoints = currentLineRef.current.points().concat([pos.x, pos.y])
@@ -317,8 +299,8 @@ const DrawingCanvas = ({
const stage = e.target.getStage()
if (!stage) return
// Use imageRef to get coordinates relative to the image (handling zoom/pan)
const pos = getRelativePointerPosition(imageRef.current!)
// Use mediaGroupRef to get coordinates relative to the media (handling zoom/pan)
const pos = getRelativePointerPosition(mediaGroupRef.current!)
if (!pos) return
// Only start drawing if within media bounds
@@ -334,7 +316,7 @@ const DrawingCanvas = ({
isDragging.current = true
startPointRef.current = pos
const layer = imageRef.current?.getLayer()
const layer = mediaGroupRef.current?.getLayer()
if (!layer) return
if (currentTool === 'freehand' && currentLineRef.current) {
@@ -474,32 +456,35 @@ const DrawingCanvas = ({
onTouchStart={handleMouseDown}
>
<Layer>
<KonvaImage
ref={imageRef}
image={videoElement || canvasElement || loadedImage}
width={mediaDimensions.width}
height={mediaDimensions.height}
/>
{annotations.map(renderAnnotation)}
<Group ref={mediaGroupRef} width={mediaDimensions.width} height={mediaDimensions.height}>
{(canvasElement || loadedImage) && (
<KonvaImage
image={canvasElement || loadedImage}
width={mediaDimensions.width}
height={mediaDimensions.height}
/>
)}
{annotations.map(renderAnnotation)}
{/* Draft Shapes */}
<Group listening={false}>
<Line
ref={currentLineRef}
strokeWidth={2.6 / scale}
lineCap="round"
lineJoin="round"
visible={false}
/>
<Rect ref={currentRectRef} strokeWidth={2.6 / scale} visible={false} />
<Arrow
ref={currentArrowRef}
points={[]}
strokeWidth={2.6 / scale}
pointerLength={10 / scale}
pointerWidth={10 / scale}
visible={false}
/>
{/* Draft Shapes */}
<Group listening={false}>
<Line
ref={currentLineRef}
strokeWidth={2.6 / scale}
lineCap="round"
lineJoin="round"
visible={false}
/>
<Rect ref={currentRectRef} strokeWidth={2.6 / scale} visible={false} />
<Arrow
ref={currentArrowRef}
points={[]}
strokeWidth={2.6 / scale}
pointerLength={10 / scale}
pointerWidth={10 / scale}
visible={false}
/>
</Group>
</Group>
</Layer>
</Stage>
@@ -1,8 +1,9 @@
// @vitest-environment happy-dom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { FileBrowser } from './file-browser'
import { client } from '@/ui/api/client'
import type { AssetInfo } from '@shumai/dtos'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
@@ -126,6 +127,7 @@ describe('FileBrowser', () => {
let queryClient: QueryClient
beforeEach(() => {
vi.clearAllMocks()
queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
})
@@ -312,4 +314,56 @@ describe('FileBrowser', () => {
expect(screen.getByTestId('folder-preview-icon')).toBeDefined()
expect(screen.getAllByText('Linked Folder').length).toBeGreaterThan(0)
})
const mockVersionStack: AssetInfo = {
id: 'stack-1',
name: 'stacked_clip.mp4',
type: 'version_stack',
sizeByte: 0,
fileCount: 2,
createdAt: '2026-01-01T00:00:00Z',
updatedAt: '2026-01-01T00:00:00Z',
status: 'processed',
} as AssetInfo
it('deletes a version stack through the delete dialog', async () => {
renderComponent({ folders: [], files: [mockVersionStack] })
const card = screen.getByTestId('file-card')
fireEvent.keyDown(within(card).getByRole('button', { name: '' }), {
key: 'ArrowDown',
code: 'ArrowDown',
})
fireEvent.click(await screen.findByRole('menuitem', { name: /^Delete$|^删除$/ }))
const dialog = await screen.findByRole('alertdialog')
fireEvent.click(within(dialog).getByRole('button', { name: /^Delete$|^删除$/ }))
await waitFor(() => {
expect(vi.mocked(client.api.files.$delete)).toHaveBeenCalledWith({
json: { ids: ['stack-1'] },
})
})
})
it('restores a version stack through the context action in recently deleted', async () => {
renderComponent({
folders: [],
files: [mockVersionStack],
isRecentlyDeleted: true,
})
const card = screen.getByTestId('file-card')
fireEvent.keyDown(within(card).getByRole('button', { name: '' }), {
key: 'ArrowDown',
code: 'ArrowDown',
})
fireEvent.click(await screen.findByRole('menuitem', { name: /^Restore$|^恢复$/ }))
await waitFor(() => {
expect(vi.mocked(client.api.files.restore.$post)).toHaveBeenCalledWith({
json: { ids: ['stack-1'] },
})
})
})
})
@@ -223,15 +223,16 @@ describe('FileCard', () => {
renderComponent({ item: itemWithComments })
const wrapper = screen.getByTestId('file-card-preview-badges')
expect(wrapper.className).toContain('absolute')
expect(wrapper.className).toContain('bottom-1')
expect(wrapper.className).toContain('left-1')
expect(wrapper.className).toContain('pointer-events-none')
const commentsBadge = screen.getByTestId('file-card-comments-count')
expect(commentsBadge).toBeTruthy()
expect(commentsBadge.textContent).toContain('5')
expect(commentsBadge.className).toContain('absolute')
expect(commentsBadge.className).toContain('bottom-1')
expect(commentsBadge.className).toContain('left-1')
expect(commentsBadge.className).toContain('bg-black/60')
expect(commentsBadge.className).toContain('text-white')
expect(commentsBadge.className).toContain('pointer-events-none')
expect(commentsBadge.className).toContain('tabular-nums')
})
@@ -253,4 +254,132 @@ describe('FileCard', () => {
renderComponent({ item: itemNoComments })
expect(screen.queryByTestId('file-card-comments-count')).toBeNull()
})
it('renders the days-left badge in preview area for recently deleted items', () => {
const deletedItem: AssetInfo = {
...fileItem,
deletedAt: new Date().toISOString(),
} as AssetInfo
renderComponent({ item: deletedItem, isRecentlyDeleted: true })
const badge = screen.getByTestId('file-card-days-left')
expect(badge.textContent).toMatch(/30\s*(d|天)/)
})
it('places the comments badge to the right of the days-left badge', () => {
const deletedItem: AssetInfo = {
...fileItem,
deletedAt: new Date().toISOString(),
commentsCount: 3,
} as AssetInfo
renderComponent({ item: deletedItem, isRecentlyDeleted: true })
const wrapper = screen.getByTestId('file-card-preview-badges')
const order = Array.from(wrapper.children).map((child) => child.getAttribute('data-testid'))
expect(order).toEqual(['file-card-days-left', 'file-card-comments-count'])
})
it('does not render the days-left badge outside of recently deleted', () => {
const deletedItem: AssetInfo = {
...fileItem,
deletedAt: new Date().toISOString(),
} as AssetInfo
renderComponent({ item: deletedItem, isRecentlyDeleted: false })
expect(screen.queryByTestId('file-card-days-left')).toBeNull()
})
it('does not render the days-left badge when deletedAt is missing', () => {
renderComponent({ item: fileItem, isRecentlyDeleted: true })
expect(screen.queryByTestId('file-card-days-left')).toBeNull()
})
it('breathes the preview and shows "Preparing..." in place of the creator while processing', () => {
const processingItem: AssetInfo = {
...fileItem,
status: 'processing',
creator: { id: 'u1', name: 'Alice' },
preview: {
proxyType: 'video',
thumbnailUrl: 'https://example.com/poster.webp',
spriteUrl: 'https://example.com/sprite.webp',
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
},
} as AssetInfo
renderComponent({ item: processingItem })
// The preview (sprite scrubber base thumbnail) is rendered and breathes instead of an overlay.
const media = screen.getByTestId('file-card-preview-media')
expect(media.className).toContain('animate-pulse')
expect(screen.getByAltText('Thumbnail').getAttribute('src')).toBe(
'https://example.com/poster.webp',
)
// The creator row is replaced by the status label while processing.
expect(screen.getByText(/Preparing|准备中/i)).toBeTruthy()
expect(screen.queryByText(/Alice/i)).toBeNull()
// The duration badge is hidden until the asset is ready.
expect(screen.queryByText('00:10')).toBeNull()
})
it('shows "Uploading..." in place of the creator while uploading', () => {
const uploadingItem: AssetInfo = {
...fileItem,
status: 'uploading',
creator: { id: 'u1', name: 'Alice' },
} as AssetInfo
renderComponent({ item: uploadingItem })
expect(screen.getByText(/Uploading|上传中/i)).toBeTruthy()
expect(screen.queryByText(/Alice/i)).toBeNull()
})
it('shows a preparing circle and "Preparing..." when processing without a preview yet', () => {
const processingItem: AssetInfo = {
...fileItem,
status: 'processing',
creator: { id: 'u1', name: 'Alice' },
} as AssetInfo
renderComponent({ item: processingItem })
expect(screen.queryByTestId('file-card-preview-media')).toBeNull()
const circle = screen.getByTestId('file-card-preparing-circle')
expect(circle.tagName.toLowerCase()).toBe('svg')
expect(circle.querySelector('circle')?.getAttribute('fill')).toBe('transparent')
expect(screen.getByText(/Preparing|准备中/i)).toBeTruthy()
expect(screen.queryByText(/Alice/i)).toBeNull()
})
it('stops breathing the preview and shows the creator once processed', () => {
const processedItem: AssetInfo = {
...fileItem,
status: 'processed',
creator: { id: 'u1', name: 'Alice' },
preview: {
proxyType: 'video',
thumbnailUrl: 'https://example.com/poster.webp',
duration: 10,
},
} as AssetInfo
renderComponent({ item: processedItem })
const media = screen.getByTestId('file-card-preview-media')
expect(media.className).not.toContain('animate-pulse')
expect(screen.getByAltText('Preview').getAttribute('src')).toBe(
'https://example.com/poster.webp',
)
expect(screen.getByText(/Alice/i)).toBeTruthy()
// The duration badge appears once processing is done.
expect(screen.getByText('00:10')).toBeTruthy()
})
})
@@ -21,13 +21,13 @@ import {
TooltipTrigger,
} from '@/ui/components/ui/tooltip'
import { ProgressCircle } from '@/ui/components/ui/progress-circle'
import { Skeleton } from '@/ui/components/ui/skeleton'
import { formatTimeAgo } from '@/ui/lib/time'
import { formatTimeAgo, getTrashDaysLeft } from '@/ui/lib/time'
import { selectFileNameWithoutExtension } from '@/ui/lib/rename-utils'
import { cn } from '@/ui/lib/utils'
import { useUploadStore } from '@/ui/stores/upload'
import { useDraggable, useDroppable } from '@dnd-kit/react'
import {
Clock,
Download,
Edit,
History,
@@ -252,6 +252,57 @@ export function FileCard({
})
}, [displayItem.createdAt, displayItem.agent, displayItem.creator?.name])
const daysLeft = isRecentlyDeleted ? getTrashDaysLeft(displayItem.deletedAt) : null
const daysLeftTooltip =
daysLeft === null
? ''
: daysLeft === 1
? m.n_days_left_singular({ count: daysLeft })
: m.n_days_left_plural({ count: daysLeft })
// A preview (poster thumbnail and/or sprite) can be available before transcoding finishes,
// since the poster/sprite are generated and persisted ahead of the proxy transcodes.
const hasPreview = Boolean(displayItem.preview?.thumbnailUrl || displayItem.preview?.spriteUrl)
const isProcessing = displayItem.status === 'processing' || displayItem.status === 'uploaded'
// While uploading/transcoding, the creator row is replaced by a short status label so the real
// date/author only appears once the asset is ready.
const statusText =
displayItem.status === 'uploading'
? m.uploading()
: displayItem.status === 'uploaded' || displayItem.status === 'processing'
? m.preparing()
: null
const previewBadges =
daysLeft !== null ||
(typeof displayItem.commentsCount === 'number' && displayItem.commentsCount > 0) ? (
<div
data-testid="file-card-preview-badges"
className="pointer-events-none absolute bottom-1 left-1 z-10 flex items-center gap-1"
>
{daysLeft !== null && (
<span
data-testid="file-card-days-left"
title={daysLeftTooltip}
className="flex items-center gap-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white"
>
<Clock className="h-3.5 w-3.5" />
<span>{m.days_left_short({ count: daysLeft })}</span>
</span>
)}
{typeof displayItem.commentsCount === 'number' && displayItem.commentsCount > 0 && (
<span
data-testid="file-card-comments-count"
className="flex items-center gap-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white"
>
<MessageCircleMore className="h-3.5 w-3.5" />
<span>{displayItem.commentsCount}</span>
</span>
)}
</div>
) : null
return (
<div
ref={setNodeRef}
@@ -303,45 +354,48 @@ export function FileCard({
</div>
<div className="relative aspect-square overflow-hidden bg-muted/30">
{displayItem.status === 'uploading' ||
displayItem.status === 'processing' ||
displayItem.status === 'uploaded' ||
displayItem.status === 'error' ? (
{displayItem.status === 'uploading' ? (
<div className="flex h-full w-full items-center justify-center bg-background/50">
{displayItem.status !== 'error' && (
<Skeleton className="absolute inset-0 h-full w-full" />
)}
{displayItem.status === 'uploading' ? (
<ProgressCircle progress={uploadPercent} className="w-16 h-16 z-10" />
) : (
<span
className={cn(
'z-10 font-medium px-2 text-center text-sm',
displayItem.status === 'error'
? 'text-destructive font-semibold'
: 'text-muted-foreground capitalize',
)}
>
{displayItem.status === 'uploaded'
? 'Processing'
: displayItem.status === 'error'
? 'Failed to upload'
: displayItem.status}
</span>
)}
<ProgressCircle progress={uploadPercent} className="w-16 h-16 z-10" />
</div>
) : hasPreview ? (
<>
<div
data-testid="file-card-preview-media"
className={cn('h-full w-full', isProcessing && 'animate-pulse')}
>
<FilePreview item={displayItem} showDuration={!isProcessing} />
</div>
{previewBadges}
</>
) : displayItem.status === 'error' ? (
<div className="flex h-full w-full items-center justify-center bg-background/50">
<span className="z-10 font-medium px-2 text-center text-sm text-destructive font-semibold">
{m.failed_to_upload()}
</span>
</div>
) : displayItem.status === 'processing' || displayItem.status === 'uploaded' ? (
<div className="flex h-full w-full items-center justify-center">
{/* Same geometry as the upload progress ring, but empty inside and no percentage. */}
<svg
viewBox="0 0 50 50"
data-testid="file-card-preparing-circle"
className="h-16 w-16 opacity-60 animate-preparing-breathe"
>
<circle
cx="25"
cy="25"
r="20"
className="stroke-muted-foreground"
strokeWidth="4"
fill="transparent"
/>
</svg>
</div>
) : (
<>
<FilePreview item={displayItem} showDuration />
{typeof displayItem.commentsCount === 'number' && displayItem.commentsCount > 0 && (
<span
data-testid="file-card-comments-count"
className="pointer-events-none absolute bottom-1 left-1 z-10 flex items-center gap-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white"
>
<MessageCircleMore className="h-3.5 w-3.5" />
<span>{displayItem.commentsCount}</span>
</span>
)}
{previewBadges}
</>
)}
</div>
@@ -378,7 +432,7 @@ export function FileCard({
>
<TooltipTrigger asChild>
<p ref={creatorRef} className="text-sm text-muted-foreground line-clamp-2 h-[2lh]">
{creatorText}
{statusText ?? creatorText}
</p>
</TooltipTrigger>
{isCreatorTooltipOpen && (
@@ -0,0 +1,99 @@
// @vitest-environment happy-dom
import { cleanup, render, screen } from '@testing-library/react'
import React from 'react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import type { AssetInfo } from '@shumai/dtos'
import { FolderCard } from './folder-card'
vi.mock('@dnd-kit/react', () => ({
useDraggable: () => ({
ref: vi.fn(),
isDragging: false,
}),
useDroppable: () => ({
ref: vi.fn(),
isDropTarget: false,
}),
}))
describe('FolderCard', () => {
afterEach(() => {
cleanup()
})
const folderItem: AssetInfo = {
id: 'folder-123',
name: 'regular_folder',
type: 'folder',
status: 'processed',
fileCount: 2,
createdAt: '2026-01-01T00:00:00Z',
updatedAt: '2026-01-01T00:00:00Z',
} as AssetInfo
const renderComponent = (props: Partial<React.ComponentProps<typeof FolderCard>> = {}) => {
return render(
<FolderCard
item={folderItem}
isSelected={false}
isChecked={false}
isEditing={false}
onSelect={vi.fn()}
onDoubleClick={vi.fn()}
onContextMenu={vi.fn()}
onDragStart={vi.fn()}
onDrop={vi.fn()}
onRename={vi.fn()}
onFinishEditing={vi.fn()}
{...props}
/>,
)
}
it('renders previews for the children of a folder', () => {
const itemWithChildren: AssetInfo = {
...folderItem,
latestChildren: [
{ type: 'image', preview: { proxyType: 'image', thumbnailUrl: 'http://x/thumb-1.png' } },
{ type: 'image', preview: { proxyType: 'image', thumbnailUrl: 'http://x/thumb-2.png' } },
],
} as AssetInfo
renderComponent({ item: itemWithChildren })
const previews = screen.getAllByAltText('Preview')
expect(previews).toHaveLength(2)
})
it('renders the days-left badge in the preview area for recently deleted folders', () => {
const deletedItem: AssetInfo = {
...folderItem,
deletedAt: new Date().toISOString(),
latestChildren: [
{ type: 'image', preview: { proxyType: 'image', thumbnailUrl: 'http://x/thumb-1.png' } },
],
} as AssetInfo
renderComponent({ item: deletedItem, isRecentlyDeleted: true })
const badge = screen.getByTestId('folder-card-days-left')
expect(badge.textContent).toMatch(/30\s*(d|天)/)
// The badge must not hide the preview of the deleted folder's content
expect(screen.getAllByAltText('Preview')).toHaveLength(1)
})
it('does not render the days-left badge outside of recently deleted', () => {
const deletedItem: AssetInfo = {
...folderItem,
deletedAt: new Date().toISOString(),
} as AssetInfo
renderComponent({ item: deletedItem, isRecentlyDeleted: false })
expect(screen.queryByTestId('folder-card-days-left')).toBeNull()
})
it('does not render the days-left badge when deletedAt is missing', () => {
renderComponent({ item: folderItem, isRecentlyDeleted: true })
expect(screen.queryByTestId('folder-card-days-left')).toBeNull()
})
})
@@ -11,7 +11,8 @@ import { cn } from '@/ui/lib/utils'
import { useDraggable, useDroppable } from '@dnd-kit/react'
import type { AssetInfo, ChildPreview } from '@shumai/dtos'
import { m } from '@/ui/paraglide/messages.js'
import { Download, Edit, History, MoreHorizontal, Trash2 } from 'lucide-react'
import { getTrashDaysLeft } from '@/ui/lib/time'
import { Clock, Download, Edit, History, MoreHorizontal, Trash2 } from 'lucide-react'
import React, { useEffect, useMemo, useRef, useState } from 'react'
import type { DragState } from '../dnd-types'
import { FilePreview } from './file-preview'
@@ -230,6 +231,14 @@ export function FolderCard({
.trim()
}, [])
const daysLeft = isRecentlyDeleted ? getTrashDaysLeft(item.deletedAt) : null
const daysLeftTooltip =
daysLeft === null
? ''
: daysLeft === 1
? m.n_days_left_singular({ count: daysLeft })
: m.n_days_left_plural({ count: daysLeft })
return (
<div
ref={setNodeRef}
@@ -333,7 +342,20 @@ export function FolderCard({
</div>
{item.latestChildren && item.latestChildren.length > 0 && (
<FolderPreviewGrid items={item.latestChildren} />
<div data-testid="folder-preview-grid" className="h-full w-full">
<FolderPreviewGrid items={item.latestChildren} />
</div>
)}
{daysLeft !== null && (
<span
data-testid="folder-card-days-left"
title={daysLeftTooltip}
className="pointer-events-none absolute bottom-1 left-1 z-10 flex items-center gap-1 rounded bg-black/60 px-1 py-0.5 text-xs font-medium tabular-nums text-white"
>
<Clock className="h-3.5 w-3.5" />
<span>{m.days_left_short({ count: daysLeft })}</span>
</span>
)}
</div>
@@ -141,7 +141,9 @@ export function useFileActions({
}
const confirmDelete = () => {
const fileIds = itemsToDelete.filter((i) => i.type === 'file').map((i) => i.id!)
const fileIds = itemsToDelete
.filter((i) => i.type === 'file' || i.type === 'version_stack')
.map((i) => i.id!)
const folderIds = itemsToDelete.filter((i) => i.type === 'folder').map((i) => i.id!)
if (fileIds.length > 0) {
@@ -183,7 +185,9 @@ export function useFileActions({
}
const handleRestore = (items: AssetInfo[]) => {
const fileIds = items.filter((i) => i.type === 'file').map((i) => i.id!)
const fileIds = items
.filter((i) => i.type === 'file' || i.type === 'version_stack')
.map((i) => i.id!)
const folderIds = items.filter((i) => i.type === 'folder').map((i) => i.id!)
if (fileIds.length > 0) {
@@ -145,6 +145,7 @@ export function MobileFileDetail({
key: t.key,
width: t.width,
height: t.height,
hdr: t.hdr,
})),
}
}, [file.media])
@@ -46,6 +46,7 @@ export interface MobileFileHeaderProps {
key: string
width: number
height: number
hdr?: boolean
}>
}
canEdit?: boolean
@@ -245,13 +246,14 @@ export function MobileFileHeader({
else if (longSide >= 960) resolution = '540p'
else if (longSide >= 640) resolution = '360p'
else if (longSide >= 320) resolution = '180p'
const label = t.hdr ? `${resolution} (HDR)` : resolution
return (
<DropdownMenuItem
key={resolution}
key={t.key || `${resolution}-${t.hdr ? 'hdr' : 'sdr'}`}
onClick={() => handleDownload(t.key)}
className="flex items-center justify-between text-xs cursor-pointer"
>
<span>{resolution}</span>
<span>{label}</span>
<span className="text-[10px] text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
@@ -440,6 +440,7 @@ export function PublicShareManager({
key: t.key,
width: t.width,
height: t.height,
hdr: t.hdr,
})),
}
: undefined,
@@ -45,6 +45,28 @@ function computeResolutions(file: AssetInfo): DisplayTranscode[] {
})
}
function getInitialResolution(resolutions: DisplayTranscode[]): DisplayTranscode | null {
if (resolutions.length === 0) return null
if (typeof window === 'undefined') return resolutions[0]
const prefersHdr =
typeof window.matchMedia === 'function' && window.matchMedia('(dynamic-range: high)').matches
const hasHdr = resolutions.some((r) => r.hdr)
const hasSdr = resolutions.some((r) => !r.hdr)
let candidates = resolutions
if (prefersHdr && hasHdr) {
candidates = resolutions.filter((r) => r.hdr)
} else if (!prefersHdr && hasSdr) {
candidates = resolutions.filter((r) => !r.hdr)
}
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
const sorted = [...candidates].sort((a, b) => (a.width ?? 0) - (b.width ?? 0))
const bestFit = sorted.find((r) => (r.width ?? 0) >= screenWidth)
return bestFit || sorted[sorted.length - 1]
}
export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPaneProps>(
function CompareVideoPane(
{
@@ -66,7 +88,6 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const videoContainerRef = useRef<HTMLDivElement>(null)
const containerRef = useRef<HTMLDivElement>(null)
const videoRef = useRef<HTMLVideoElement | null>(null)
const [videoHtmlEl, setVideoHtmlEl] = useState<HTMLVideoElement | undefined>(undefined)
const {
isDrawing,
@@ -82,6 +103,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const [pan, setPan] = useState<{ x: number; y: number } | null>(null)
const [isPlaying, setIsPlaying] = useState(false)
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
const [isLooping, setIsLooping] = useState(false)
const [playbackRate, setPlaybackRate] = useState(1)
const [buffered, setBuffered] = useState(0)
@@ -96,8 +118,9 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
const resolutions = computeResolutions(file)
const initialRes = resolutions[0]
const initialRes = getInitialResolution(resolutions)
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? '')
const [isCurrentHdr, setIsCurrentHdr] = useState(initialRes?.hdr)
const currentSrcRef = useRef(initialRes?.url)
const isAudio = file.proxyType === 'audio'
@@ -137,8 +160,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
// if the parent renders this pane without a per-asset `key`. Runs before the
// video.js init effect below (declaration order) so the ref is fresh.
useEffect(() => {
setCurrentResolution(initialRes?.resolution ?? '')
currentSrcRef.current = initialRes?.url
const res = getInitialResolution(resolutions)
setCurrentResolution(res?.resolution ?? '')
setIsCurrentHdr(res?.hdr)
currentSrcRef.current = res?.url
setHasStartedPlaying(false)
}, [file.id])
// Initialize video.js
@@ -146,7 +172,6 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
if (!videoContainerRef.current) return
const videoElement = document.createElement('video-js')
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
videoElement.style.opacity = '0'
videoElement.style.pointerEvents = 'none'
videoContainerRef.current.appendChild(videoElement)
@@ -160,13 +185,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
const htmlVid = videoElement.querySelector('video')
if (htmlVid) {
setVideoHtmlEl(htmlVid)
videoRef.current = htmlVid
} else {
player.ready(() => {
const techEl = player.tech({ iWillNotUseThisInPlugins: true })?.el() as HTMLVideoElement
if (techEl) {
setVideoHtmlEl(techEl)
videoRef.current = techEl
}
})
@@ -174,17 +197,20 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
player.on('play', () => {
setIsPlaying(true)
setHasStartedPlaying(true)
onPlay?.()
})
player.on('pause', () => setIsPlaying(false))
player.on('ended', () => setIsPlaying(false))
player.on('loadedmetadata', () => setIsPlayerReady(true))
player.on('loadstart', () => setIsPlayerReady(false))
player.on('timeupdate', () => {
const playerDuration = player.duration() || containerDuration || 0
const bufferedEnd = player.bufferedEnd()
if (playerDuration > 0) setBuffered((bufferedEnd / playerDuration) * 100)
setBuffered(player.bufferedPercent())
})
player.on('loadedmetadata', () => {
setIsPlayerReady(true)
})
player.on('loadstart', () => setIsPlayerReady(false))
player.on('volumechange', () => {
setPlayerVolume(player.volume() || 0)
setPlayerMuted(player.muted() || false)
@@ -223,6 +249,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
playbackRate,
isLooping,
currentResolution,
isCurrentHdr,
resolutions,
buffered,
},
@@ -239,6 +266,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
playbackRate,
isLooping,
currentResolution,
isCurrentHdr,
buffered,
])
@@ -294,14 +322,20 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
)
const changeResolution = useCallback(
(resolution: string) => {
(resolution: string, hdr?: boolean) => {
const player = playerRef.current
if (!player) return
const target = resolutions.find((r) => r.resolution === resolution)
const target =
hdr !== undefined
? resolutions.find(
(r) => r.resolution === resolution && Boolean(r.hdr) === Boolean(hdr),
)
: resolutions.find((r) => r.resolution === resolution)
if (!target) return
const wasPlaying = !player.paused()
const currentT = player.currentTime()
setCurrentResolution(resolution)
setIsCurrentHdr(target.hdr)
currentSrcRef.current = target.url
player.src({ type: 'video/mp4', src: target.url })
player.one('loadedmetadata', () => {
@@ -334,12 +368,19 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
player.pause()
}
},
seekToFrame: (frame) => seekToFrame(clampFrame(frame)),
seekToFrame: (frame) => {
setHasStartedPlaying(true)
return seekToFrame(clampFrame(frame))
},
seekToSecond: (second) => {
setHasStartedPlaying(true)
const frame = Math.floor(second * frameRate + 0.45)
seekToFrame(clampFrame(frame))
},
stepFrame: (delta) => seekToFrame(clampFrame(currentFrameRef.current + delta)),
stepFrame: (delta) => {
setHasStartedPlaying(true)
return seekToFrame(clampFrame(currentFrameRef.current + delta))
},
setMuted: (m) => playerRef.current?.muted(m),
setVolume: (v) => {
const player = playerRef.current
@@ -420,7 +461,28 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
onClick={handleAreaClick}
data-testid="compare-video-area"
>
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
{!isAudio && (
<div
className="absolute pointer-events-none"
style={{
left: 0,
top: 0,
width: vidW,
height: vidH,
transform: `translate(${panX}px, ${panY}px) scale(${scale})`,
transformOrigin: '0 0',
}}
>
<div
ref={videoContainerRef}
className="w-full h-full [&_.video-js]:!w-full [&_.video-js]:!h-full [&_video]:!w-full [&_video]:!h-full [&_video]:!block [&_video]:!object-contain"
/>
</div>
)}
{isAudio && (
<div ref={videoContainerRef} className="absolute inset-0 pointer-events-none opacity-0" />
)}
{isAudio ? (
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
@@ -432,13 +494,11 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
/>
</div>
) : (
videoHtmlEl &&
containerSize.width > 0 && (
<DrawingCanvas
width={containerSize.width}
height={containerSize.height}
mediaDimensions={{ width: vidW, height: vidH }}
videoElement={videoHtmlEl}
annotations={displayAnnotations}
scale={scale}
offset={{ x: panX, y: panY }}
@@ -452,8 +512,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
)
)}
{!isPlaying && !isDrawing && (
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20">
{!hasStartedPlaying && !isDrawing && (
<div className="pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-black/20 transition-opacity duration-200">
<div className="flex h-16 w-16 items-center justify-center rounded-full border-2 border-white/30 bg-white/10 backdrop-blur-sm">
<Play className="ml-1 h-8 w-8 fill-white text-white" />
</div>
@@ -93,4 +93,92 @@ describe('MobileVideoControlBar', () => {
fireEvent.click(fsBtn)
expect(toggleFullScreen).toHaveBeenCalledTimes(1)
})
it('renders HDR label on settings button when playing HDR video', () => {
render(
<MobileVideoControlBar
state={{
...defaultState,
currentResolution: '1080p',
isCurrentHdr: true,
}}
zoom={1}
isControlsVisible={true}
buffered={50}
data={mockData}
resolutions={[
{
key: '1080-hdr.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: true,
} as unknown as DisplayTranscode,
]}
togglePlay={vi.fn()}
toggleLoop={vi.fn()}
toggleMute={vi.fn()}
handleVolumeChange={vi.fn()}
changePlaybackRate={vi.fn()}
changeResolution={vi.fn()}
handleDownload={vi.fn()}
toggleFullScreen={vi.fn()}
onZoomChange={vi.fn()}
onZoomReset={vi.fn()}
frameRate={25}
totalFrames={2500}
currentFrame={250}
seekToFrame={vi.fn()}
/>,
)
const settingsBtn = screen.getByLabelText(/Settings/i)
expect(settingsBtn).toBeDefined()
expect(settingsBtn.textContent).toContain('1080p')
expect(settingsBtn.textContent).toContain('HDR')
})
it('does not render HDR label on settings button when playing SDR video', () => {
render(
<MobileVideoControlBar
state={{
...defaultState,
currentResolution: '1080p',
isCurrentHdr: false,
}}
zoom={1}
isControlsVisible={true}
buffered={50}
data={mockData}
resolutions={[
{
key: '1080.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: false,
} as unknown as DisplayTranscode,
]}
togglePlay={vi.fn()}
toggleLoop={vi.fn()}
toggleMute={vi.fn()}
handleVolumeChange={vi.fn()}
changePlaybackRate={vi.fn()}
changeResolution={vi.fn()}
handleDownload={vi.fn()}
toggleFullScreen={vi.fn()}
onZoomChange={vi.fn()}
onZoomReset={vi.fn()}
frameRate={25}
totalFrames={2500}
currentFrame={250}
seekToFrame={vi.fn()}
/>,
)
const settingsBtn = screen.getByLabelText(/Settings/i)
expect(settingsBtn).toBeDefined()
expect(settingsBtn.textContent).toContain('1080p')
expect(settingsBtn.textContent).not.toContain('HDR')
})
})
@@ -186,10 +186,19 @@ export const MobileVideoControlBar: React.FC<ControlBarProps> = ({
aria-label={m.settings()}
>
<Settings className="h-3.5 w-3.5" />
<span className="text-[11px]">
{!isAudio && state.currentResolution
? state.currentResolution
: `${state.playbackRate}x`}
<span className="flex items-center gap-1 text-[11px]">
<span>
{!isAudio && state.currentResolution
? state.currentResolution === 'Original'
? m.original()
: state.currentResolution
: `${state.playbackRate}x`}
</span>
{!isAudio && state.isCurrentHdr && (
<span className="px-1 py-0.2 rounded text-[9px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</span>
</button>
</DropdownMenuTrigger>
@@ -199,23 +208,36 @@ export const MobileVideoControlBar: React.FC<ControlBarProps> = ({
<DropdownMenuLabel className="text-[10px] font-bold text-muted-foreground uppercase tracking-wider">
{m.quality()}
</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between text-xs cursor-pointer',
state.currentResolution === res.resolution
? 'text-primary font-medium'
: 'text-foreground',
)}
>
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
<span className="text-[10px] text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
))}
{resolutions.map((res) => {
const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
const isSelected =
state.currentResolution === res.resolution &&
Boolean(state.isCurrentHdr) === Boolean(res.hdr)
return (
<DropdownMenuItem
key={itemKey}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between text-xs cursor-pointer',
isSelected ? 'text-primary font-medium' : 'text-foreground',
)}
>
<div className="flex items-center gap-1.5">
<span>
{res.resolution === 'Original' ? m.original() : res.resolution}
</span>
{res.hdr && (
<span className="px-1 py-0.2 rounded text-[9px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</div>
<span className="text-[10px] text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
)
})}
<DropdownMenuSeparator />
</>
)}
@@ -0,0 +1,110 @@
// @vitest-environment happy-dom
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import React from 'react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { VideoControlBar } from './video-control-bar'
import type { AssetInfo } from '@shumai/dtos'
import type { DisplayTranscode, PlayerState } from './video-control-bar'
describe('VideoControlBar', () => {
afterEach(() => {
cleanup()
})
const mockData: AssetInfo = {
id: 'video-1',
name: 'sample.mp4',
proxyType: 'video',
media: {
original: { key: 'files/sample.mp4' },
metadata: {
duration: 100,
frameRate: 25,
},
},
} as AssetInfo
const defaultState: PlayerState = {
isPlaying: false,
progress: 10,
currentTime: 10,
duration: 100,
volume: 1,
isMuted: false,
isLooping: false,
playbackRate: 1,
isFullScreen: false,
showFrames: false,
currentResolution: '1080p',
isCurrentHdr: false,
}
const resolutions: DisplayTranscode[] = [
{
key: '1080.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: false,
} as unknown as DisplayTranscode,
{
key: '1080-hdr.mp4',
width: 1920,
height: 1080,
resolution: '1080p',
hdr: true,
} as unknown as DisplayTranscode,
]
it('renders download menu with HDR badge on HDR download items', async () => {
const handleDownload = vi.fn()
render(
<VideoControlBar
state={defaultState}
zoom={1}
isControlsVisible={true}
buffered={50}
data={mockData}
resolutions={resolutions}
togglePlay={vi.fn()}
toggleLoop={vi.fn()}
toggleMute={vi.fn()}
handleVolumeChange={vi.fn()}
changePlaybackRate={vi.fn()}
changeResolution={vi.fn()}
handleDownload={handleDownload}
toggleFullScreen={vi.fn()}
onZoomChange={vi.fn()}
onZoomReset={vi.fn()}
frameRate={25}
totalFrames={2500}
currentFrame={250}
seekToFrame={vi.fn()}
allowDownload={true}
/>,
)
const downloadTrigger = screen.getByTitle(/Download/i)
expect(downloadTrigger).toBeDefined()
fireEvent.pointerDown(downloadTrigger, { button: 0, ctrlKey: false })
const menuItems = await screen.findAllByRole('menuitem')
// We expect: 1080p SDR, 1080p HDR, and Original
expect(menuItems.length).toBe(3)
const sdrItem = menuItems.find(
(item) => item.textContent?.includes('1080p') && !item.textContent?.includes('HDR'),
)
const hdrItem = menuItems.find(
(item) => item.textContent?.includes('1080p') && item.textContent?.includes('HDR'),
)
expect(sdrItem).toBeDefined()
expect(hdrItem).toBeDefined()
// Clicking HDR item triggers download with HDR key
fireEvent.click(hdrItem!)
expect(handleDownload).toHaveBeenCalledWith('1080-hdr.mp4')
})
})
@@ -43,6 +43,7 @@ export interface PlayerState {
showFrames: boolean // Toggle between time (02:30) and frames (1234)
currentResolution: string // 'Original' or '720p', '480p' etc.
currentSrc?: string
isCurrentHdr?: boolean
}
export type DisplayTranscode = VideoTranscode & { resolution: string }
@@ -317,35 +318,53 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
{!isAudio && resolutions.length > 0 && (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
<button className="flex items-center gap-1.5 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
<Settings className="h-3.5 w-3.5" />
<span>
{state.currentResolution === 'Original'
? m.original()
: state.currentResolution}
<span className="flex items-center gap-1">
<span>
{state.currentResolution === 'Original'
? m.original()
: state.currentResolution}
</span>
{state.isCurrentHdr && (
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.quality()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between',
state.currentResolution === res.resolution
? 'text-primary font-medium'
: 'text-foreground',
)}
>
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
<span className="pl-5 text-xs text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
))}
{resolutions.map((res) => {
const itemKey = `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
const isSelected =
state.currentResolution === res.resolution &&
Boolean(state.isCurrentHdr) === Boolean(res.hdr)
return (
<DropdownMenuItem
key={itemKey}
onClick={() => changeResolution(res)}
className={cn(
'flex w-full items-center justify-between',
isSelected ? 'text-primary font-medium' : 'text-foreground',
)}
>
<div className="flex items-center gap-1.5">
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
{res.hdr && (
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</div>
<span className="pl-5 text-xs text-muted-foreground">
{res.width}x{res.height}
</span>
</DropdownMenuItem>
)
})}
</DropdownMenuContent>
</DropdownMenu>
)}
@@ -370,16 +389,26 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
</DropdownMenuTrigger>
<DropdownMenuContent>
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
{resolutions.map((res) => (
<DropdownMenuItem
key={res.resolution}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
>
<span>{res.resolution}</span>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
))}
{resolutions.map((res) => {
const itemKey = res.key || `${res.resolution}-${res.hdr ? 'hdr' : 'sdr'}`
return (
<DropdownMenuItem
key={itemKey}
onClick={() => handleDownload(res.key ?? '')}
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground cursor-pointer"
>
<div className="flex items-center gap-1.5">
<span>{res.resolution}</span>
{res.hdr && (
<span className="px-1 py-0.2 rounded text-[10px] font-bold bg-amber-500/20 text-amber-500 border border-amber-500/30">
{m.hdr()}
</span>
)}
</div>
<span className="text-xs text-muted-foreground">MP4</span>
</DropdownMenuItem>
)
})}
{data.media?.original?.key && (
<>
<DropdownMenuSeparator />
@@ -1,5 +1,5 @@
// @vitest-environment happy-dom
import { cleanup, render } from '@testing-library/react'
import { act, cleanup, render } from '@testing-library/react'
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import VideoViewer from './video-viewer'
@@ -182,4 +182,191 @@ describe('VideoViewer', () => {
}),
)
})
it('auto-selects HDR proxy when display supports HDR (dynamic-range: high)', () => {
const originalMatchMedia = window.matchMedia
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
matches: query === '(dynamic-range: high)',
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}))
const hdrVideo: AssetInfo = {
id: 'video-hdr',
name: 'video-hdr.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p.mp4',
width: 1920,
height: 1080,
hdr: false,
},
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p-hdr.mp4',
width: 1920,
height: 1080,
hdr: true,
},
],
},
} as unknown as AssetInfo
render(<VideoViewer file={hdrVideo} />)
expect(videojsMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
sources: [
{
src: 'https://cdn.example.com/video-1080p-hdr.mp4',
type: 'video/mp4',
},
],
}),
)
window.matchMedia = originalMatchMedia
})
it('auto-selects SDR proxy when display does not support HDR', () => {
const originalMatchMedia = window.matchMedia
window.matchMedia = vi.fn().mockImplementation((query: string) => ({
matches: false,
media: query,
onchange: null,
addListener: vi.fn(),
removeListener: vi.fn(),
addEventListener: vi.fn(),
removeEventListener: vi.fn(),
dispatchEvent: vi.fn(),
}))
const hdrVideo: AssetInfo = {
id: 'video-sdr-fallback',
name: 'video-sdr-fallback.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p.mp4',
width: 1920,
height: 1080,
hdr: false,
},
{
resolution: '1080p',
url: 'https://cdn.example.com/video-1080p-hdr.mp4',
width: 1920,
height: 1080,
hdr: true,
},
],
},
} as unknown as AssetInfo
render(<VideoViewer file={hdrVideo} />)
expect(videojsMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
sources: [
{
src: 'https://cdn.example.com/video-1080p.mp4',
type: 'video/mp4',
},
],
}),
)
window.matchMedia = originalMatchMedia
})
it('shows play button and darkened overlay initially, but never again after playing (even when paused or scrubbed back to start)', () => {
const listeners: Record<string, () => void> = {}
videojsMock.mockImplementation(() => ({
on: vi.fn((event: string, cb: () => void) => {
listeners[event] = cb
}),
volume: vi.fn(),
duration: vi.fn(() => 10),
currentTime: vi.fn(() => 0),
bufferedEnd: vi.fn(() => 0),
playbackRate: vi.fn(() => 1),
ready: vi.fn(),
dispose: vi.fn(),
isDisposed: vi.fn(() => false),
}))
const testVideo: AssetInfo = {
id: 'test-video-lifecycle',
name: 'test.mp4',
proxyType: 'video',
media: {
metadata: {
originalWidth: 1920,
originalHeight: 1080,
duration: 10,
frameRate: 30,
totalFrames: 300,
},
videoTranscodes: [
{
resolution: '1080p',
url: 'https://cdn.example.com/test-1080p.mp4',
width: 1920,
height: 1080,
},
],
},
} as unknown as AssetInfo
const { container } = render(<VideoViewer file={testVideo} />)
const videoArea = container.querySelector('[data-testid="video-area"]')
expect(videoArea).toBeTruthy()
// 1. Initially (before playing): play button & 20% black tint are present
expect(videoArea?.querySelector('.bg-black\\/20')).not.toBeNull()
// 2. Start playback
act(() => {
listeners['play']?.()
})
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
// 3. Pause video: overlay must NOT show again
act(() => {
listeners['pause']?.()
})
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
// 4. Drag seekbar / time back to 0: overlay must STILL NOT show
act(() => {
listeners['timeupdate']?.()
})
expect(videoArea?.querySelector('.bg-black\\/20')).toBeNull()
})
})
@@ -54,17 +54,30 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
// We use a container ref to manually append the video element
const videoContainerRef = useRef<HTMLDivElement>(null)
// Logic to select best resolution based on screen size
// Logic to select best resolution based on screen size and dynamic range
const getInitialResolution = (): DisplayTranscode | null => {
if (resolutions.length === 0) return null
if (typeof window === 'undefined') return resolutions[0]
const prefersHdr =
typeof window.matchMedia === 'function' &&
window.matchMedia('(dynamic-range: high)').matches
const hasHdr = resolutions.some((r) => r.hdr)
const hasSdr = resolutions.some((r) => !r.hdr)
let candidateResolutions = resolutions
if (prefersHdr && hasHdr) {
candidateResolutions = resolutions.filter((r) => r.hdr)
} else if (!prefersHdr && hasSdr) {
candidateResolutions = resolutions.filter((r) => !r.hdr)
}
// Use device pixel ratio for high DPI screens
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
// 1. Sort by width ascending
const sortedResolutions = [...resolutions].sort((a, b) => {
const sortedResolutions = [...candidateResolutions].sort((a, b) => {
const wA = a.width ?? 0
const wB = b.width ?? 0
return wA - wB
@@ -93,7 +106,9 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
showFrames: false,
currentResolution: initialRes?.resolution ?? '',
currentSrc: initialRes?.url ?? '',
isCurrentHdr: initialRes?.hdr ?? false,
})
const [hasStartedPlaying, setHasStartedPlaying] = useState(false)
const containerRef = useRef<HTMLDivElement>(null)
const rootRef = useRef<HTMLDivElement>(null)
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
@@ -110,6 +125,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
}
},
seekTo: (second: number) => {
setHasStartedPlaying(true)
if (localPlayerRef.current) {
localPlayerRef.current.currentTime(second)
}
@@ -140,11 +156,13 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
duration: data.media?.metadata?.duration || 0,
currentResolution: res?.resolution ?? '',
currentSrc: res?.url ?? '',
isCurrentHdr: res?.hdr ?? false,
}))
setHasManuallyZoomed(false)
setIsPlayerReady(false)
setBuffered(0)
lastProcessedStartTimeRef.current = null
setHasStartedPlaying(false)
}, [data.id, Boolean(initialRes?.url)])
const vidW = data.media?.metadata?.originalWidth || 1920
@@ -246,6 +264,14 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
const { currentFrame, seekToFrame } = useFramePlayer(videoRef, frameRate, totalFrames, isAudio)
const handleSeekToFrame = useCallback(
(frame: number) => {
setHasStartedPlaying(true)
return seekToFrame(frame)
},
[seekToFrame],
)
const currentTime = currentFrame / frameRate
const duration = totalFrames / frameRate
const progress = duration > 0 ? (currentTime / duration) * 100 : 0
@@ -284,8 +310,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
const videoElement = document.createElement('video-js')
videoElement.classList.add('vjs-big-play-centered', '!h-full', '!w-full')
// Hide it, but keep it in DOM
videoElement.style.opacity = '0'
// Keep it in DOM, enable visible rendering
videoElement.style.pointerEvents = 'none'
// Append to our container
@@ -348,6 +373,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
player.on('play', () => {
setState((p) => ({ ...p, isPlaying: true }))
setHasStartedPlaying(true)
onPlay?.()
})
player.on('pause', () => {
@@ -413,6 +439,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
if (startTime !== lastProcessedStartTimeRef.current) {
lastProcessedStartTimeRef.current = startTime
const targetFrame = Math.floor(startTime * frameRate + 0.45)
setHasStartedPlaying(true)
seekToFrame(targetFrame)
}
}
@@ -600,6 +627,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
...prev,
currentResolution: res.resolution,
currentSrc: res.url,
isCurrentHdr: res.hdr ?? false,
}))
player.src({ type: 'video/mp4', src: res.url })
@@ -758,8 +786,31 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
data-vjs-player
data-testid="video-area"
>
{/* Hidden VideoJS container */}
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
{/* Native Video Layer (Hardware-accelerated, full HDR EDR) */}
{!isAudio && (
<div
className="absolute pointer-events-none"
style={{
left: 0,
top: 0,
width: vidW,
height: vidH,
transform: `translate(${pan.x}px, ${pan.y}px) scale(${scale})`,
transformOrigin: '0 0',
}}
>
<div
ref={videoContainerRef}
className="w-full h-full [&_.video-js]:!w-full [&_.video-js]:!h-full [&_video]:!w-full [&_video]:!h-full [&_video]:!block [&_video]:!object-contain"
/>
</div>
)}
{isAudio && (
<div
ref={videoContainerRef}
className="absolute inset-0 pointer-events-none opacity-0"
/>
)}
{isAudio ? (
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
@@ -771,8 +822,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
/>
</div>
) : (
/* Drawing Canvas (Visible) */
videoHtmlEl &&
/* Drawing Canvas (Transparent Overlay for annotations) */
containerSize.width > 0 && (
<DrawingCanvas
width={containerSize.width}
@@ -781,7 +831,6 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
width: vidW,
height: vidH,
}}
videoElement={videoHtmlEl}
annotations={displayAnnotations}
scale={scale}
offset={pan}
@@ -798,10 +847,10 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
)
)}
{/* Big Play Button Overlay (when paused) */}
{!state.isPlaying && !isDrawing && (
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10">
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30 animate-pulse">
{/* Initial Big Play Button Overlay (shown only before playback starts) */}
{!hasStartedPlaying && !isDrawing && (
<div className="absolute inset-0 flex items-center justify-center bg-black/20 pointer-events-none z-10 transition-opacity duration-200">
<div className="w-20 h-20 bg-white/10 backdrop-blur-sm rounded-full flex items-center justify-center border-2 border-white/30">
<Play className="w-10 h-10 text-white ml-1 fill-white" />
</div>
</div>
@@ -830,7 +879,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
frameRate={frameRate}
totalFrames={totalFrames}
currentFrame={currentFrame}
seekToFrame={seekToFrame}
seekToFrame={handleSeekToFrame}
onMouseEnter={handleControlsMouseEnter}
onMouseLeave={handleControlsMouseLeave}
allowDownload={allowDownload}
@@ -856,7 +905,7 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
frameRate={frameRate}
totalFrames={totalFrames}
currentFrame={currentFrame}
seekToFrame={seekToFrame}
seekToFrame={handleSeekToFrame}
onMouseEnter={handleControlsMouseEnter}
onMouseLeave={handleControlsMouseLeave}
allowDownload={allowDownload}
+11
View File
@@ -114,9 +114,20 @@
--color-sidebar-ring: var(--sidebar-ring);
--animate-upload-breathing: upload-breathing 2s cubic-bezier(0.4, 0, 0.6, 1) infinite alternate;
--animate-preparing-breathe: preparing-breathe 1.6s ease-in-out infinite;
--animate-drift-slow: drift-slow 15s ease-in-out infinite alternate;
--animate-drift-medium: drift-medium 12s ease-in-out infinite alternate;
@keyframes preparing-breathe {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(0.8);
}
}
@keyframes upload-breathing {
0% {
filter: drop-shadow(0 0 1px rgb(var(--primary)));
+30 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { formatRemainingTime } from './time'
import { formatRemainingTime, getTrashDaysLeft } from './time'
describe('formatRemainingTime', () => {
const baseNow = new Date('2026-08-17T12:00:00Z')
@@ -44,3 +44,32 @@ describe('formatRemainingTime', () => {
expect(formatRemainingTime('2026-08-17T15:18:00Z', baseNow)).toBe('3h 18m')
})
})
describe('getTrashDaysLeft', () => {
const now = new Date('2026-08-17T12:00:00Z')
it('returns the full retention window for a freshly deleted asset', () => {
expect(getTrashDaysLeft('2026-08-17T12:00:00Z', now)).toBe(30)
})
it('counts down as days pass', () => {
expect(getTrashDaysLeft('2026-08-16T12:00:00Z', now)).toBe(29)
expect(getTrashDaysLeft('2026-08-06T12:00:00Z', now)).toBe(19)
})
it('rounds partial days up', () => {
// Deleted 23h ago: 29d 1h remain, which rounds up to 30
expect(getTrashDaysLeft('2026-08-16T13:00:00Z', now)).toBe(30)
})
it('never returns less than zero once the retention window has elapsed', () => {
expect(getTrashDaysLeft('2026-07-01T12:00:00Z', now)).toBe(0)
})
it('returns null when there is no valid deletedAt', () => {
expect(getTrashDaysLeft(null, now)).toBeNull()
expect(getTrashDaysLeft(undefined, now)).toBeNull()
expect(getTrashDaysLeft('', now)).toBeNull()
expect(getTrashDaysLeft('not-a-date', now)).toBeNull()
})
})
+20
View File
@@ -1,6 +1,9 @@
import { differenceInDays, format, isToday, isYesterday, parseISO } from 'date-fns'
import { TRASH_RETENTION_DAYS } from '@shumai/dtos'
import { m } from '@/ui/paraglide/messages.js'
const MS_PER_DAY = 24 * 60 * 60 * 1000
export const formatTimeAgo = (dateString: string) => {
const date = parseISO(dateString)
const now = new Date()
@@ -71,3 +74,20 @@ export const formatRemainingTime = (targetDate: string | Date, now: Date = new D
}
return minutes > 0 ? `${minutes}m` : '< 1m'
}
/**
* Whole days remaining before a soft-deleted asset is permanently purged.
* Returns `null` when there is no valid `deletedAt` timestamp, and `0` once the
* retention window has elapsed.
*/
export const getTrashDaysLeft = (
deletedAt: string | null | undefined,
now: Date = new Date(),
): number | null => {
if (!deletedAt) return null
const deleted = parseISO(deletedAt)
if (isNaN(deleted.getTime())) return null
const expiresAtMs = deleted.getTime() + TRASH_RETENTION_DAYS * MS_PER_DAY
return Math.max(0, Math.ceil((expiresAtMs - now.getTime()) / MS_PER_DAY))
}
+10
View File
@@ -132,6 +132,7 @@
"activity_notifications": "Activity Notifications",
"activity_notifications_description": "Receive in-app updates for comments, uploads, and automated background analysis tasks inside this project.",
"processing": "Processing...",
"preparing": "Preparing...",
"project_updated": "Project updated",
"failed_update_project": "Failed to update project",
"project_notification_updated": "Project notification settings updated",
@@ -260,6 +261,12 @@
"hardware_acceleration_off_description": "Uses software libx264 encoder with constant rate factor (CRF).",
"hardware_acceleration_auto": "Auto Detect",
"hardware_acceleration_auto_description": "Automatically probes and uses GPU/Hardware acceleration (NVENC, QSV, AMF, VideoToolbox). If hardware acceleration is unsupported on the host, video transcoding may fail.",
"ffmpeg_threads": "FFmpeg Threads",
"ffmpeg_threads_description": "Maximum number of CPU threads used by FFmpeg during transcoding. Set to 0 for Auto.",
"threads_auto": "Auto",
"threads_count": "{count} threads",
"hdr": "HDR",
"sdr": "SDR",
"notification_settings": "Notification Settings",
"notifications_description": "Configure your personal notification preferences for this team.",
@@ -1018,6 +1025,9 @@
"n_tasks_plural": "{count} tasks",
"n_days_ago_singular": "{count} day ago",
"n_days_ago_plural": "{count} days ago",
"days_left_short": "{count}d",
"n_days_left_singular": "{count} day left before permanent deletion",
"n_days_left_plural": "{count} days left before permanent deletion",
"today_with_time": "Today {time}",
"yesterday_with_time": "Yesterday {time}",
"n_items_singular": "{count} Item",
+10
View File
@@ -132,6 +132,7 @@
"activity_notifications": "活动通知",
"activity_notifications_description": "接收此项目中评论、上传及自动后台分析任务的应用内通知。",
"processing": "处理中...",
"preparing": "准备中...",
"project_updated": "项目已更新",
"failed_update_project": "更新项目失败",
"project_notification_updated": "项目通知设置已更新",
@@ -260,6 +261,12 @@
"hardware_acceleration_off_description": "使用 CPU 的 libx264 软件编码器及 CRF 恒定画质模式。",
"hardware_acceleration_auto": "自动检测",
"hardware_acceleration_auto_description": "自动检测并使用 GPU/硬件加速(NVENC、QSV、AMF、VideoToolbox)。若宿主硬件不支持加速,视频转码可能会失败。",
"ffmpeg_threads": "FFmpeg 线程数",
"ffmpeg_threads_description": "FFmpeg 转码时使用的最大 CPU 线程数。设置为 0 表示自动。",
"threads_auto": "自动",
"threads_count": "{count} 线程",
"hdr": "HDR",
"sdr": "SDR",
"notification_settings": "通知设置",
"notifications_description": "配置您在此团队的个人通知偏好。",
@@ -1018,6 +1025,9 @@
"n_tasks_plural": "{count} 个任务",
"n_days_ago_singular": "{count} 天前",
"n_days_ago_plural": "{count} 天前",
"days_left_short": "{count}天",
"n_days_left_singular": "永久删除前还剩 {count} 天",
"n_days_left_plural": "永久删除前还剩 {count} 天",
"today_with_time": "今天 {time}",
"yesterday_with_time": "昨天 {time}",
"n_items_singular": "{count} 个项目",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/webui",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./index.html",
@@ -300,6 +300,7 @@ function FileViewPage() {
key: t.key,
width: t.width,
height: t.height,
hdr: t.hdr,
})),
},
versions: versionsDataList,
@@ -3,6 +3,7 @@ import {
VideoTranscodeStrategy,
HardwareAcceleration,
UpdateTeamSettingsRequest,
TeamSettingsResponse,
} from '@shumai/dtos'
import { client } from '@/ui/api/client'
import { AgentsSettings } from '@/ui/components/settings/AgentsSettings'
@@ -16,6 +17,7 @@ import { QuotasSettings } from '@/ui/components/settings/QuotasSettings'
import { AppearanceSettings } from '@/ui/components/settings/AppearanceSettings'
import { ImageVideoGenerationSettings } from '@/ui/components/settings/ImageVideoGenerationSettings'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/ui/components/ui/card'
import { Slider } from '@/ui/components/ui/slider'
import { cn } from '@/ui/lib/utils'
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import {
@@ -309,6 +311,23 @@ function TeamSettingsPage() {
})
}
const [localThreads, setLocalThreads] = useState<number | null>(null)
const serverThreads = (settings as TeamSettingsResponse | undefined)?.transcode?.threads ?? 0
useEffect(() => {
setLocalThreads(null)
}, [serverThreads])
const handleThreadsChange = (value: number) => {
updateSettings({
teamId,
data: {
key: 'transcode.threads',
value,
},
})
}
if (isSettingsLoading || isMeLoading) {
return (
<div className="flex h-screen items-center justify-center">
@@ -334,6 +353,8 @@ function TeamSettingsPage() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(settings as any)?.transcode?.hardwareAcceleration || HardwareAcceleration.off
const currentThreads = localThreads ?? serverThreads
return (
<div className="h-full bg-background font-sans selection:bg-primary/20 transition-colors duration-300">
<div className="flex flex-col md:flex-row h-full">
@@ -725,7 +746,7 @@ function TeamSettingsPage() {
)}
{activeTab === 'transcode' && (
<div className="h-full overflow-y-auto pr-1">
<div className="h-full overflow-y-auto pr-1 pb-8">
<Card>
<CardHeader>
<CardTitle>{m.transcode_settings()}</CardTitle>
@@ -812,6 +833,41 @@ function TeamSettingsPage() {
</div>
</div>
</div>
{/* FFmpeg Threads */}
<div className="space-y-4 pt-6 border-t border-border">
<div className="flex items-center justify-between">
<div>
<h3 className="text-lg font-medium">{m.ffmpeg_threads()}</h3>
<p className="text-sm text-muted-foreground">
{m.ffmpeg_threads_description()}
</p>
</div>
<span className="font-mono text-sm font-semibold px-2.5 py-1 rounded bg-muted text-foreground border border-border">
{currentThreads === 0
? m.threads_auto()
: m.threads_count({ count: currentThreads })}
</span>
</div>
<div className="pt-2 px-1">
<Slider
value={[currentThreads]}
min={0}
max={32}
step={1}
onValueChange={([val]) => setLocalThreads(val)}
onValueCommit={([val]) => {
setLocalThreads(val)
handleThreadsChange(val)
}}
/>
<div className="flex justify-between text-xs text-muted-foreground mt-2">
<span>{m.threads_auto()} (0)</span>
<span>16</span>
<span>32</span>
</div>
</div>
</div>
</CardContent>
</Card>
</div>
+1
View File
@@ -23,6 +23,7 @@ export interface TopNavProjectState {
key: string
width: number
height: number
hdr?: boolean
}>
}
versions?: Array<{
+1 -1
View File
@@ -1 +1 @@
export const APP_VERSION = '0.4.6'
export const APP_VERSION = '0.4.8'
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/workflow-core",
"version": "0.4.6",
"version": "0.4.8",
"private": true,
"type": "module",
"main": "./src/index.ts",
@@ -48,6 +48,27 @@ describe('Task Activities', () => {
expect(updated?.status).toBe(AssetStatus.processing)
})
it('should NOT overwrite trashed status when asset is soft-deleted (isDeleted: true)', async () => {
const asset = await prisma.asset.create({
data: {
name: 'trashed-video.mp4',
storageKey: { create: { key: 'trashed-video.mp4' } },
status: AssetStatus.trashed,
isDeleted: true,
type: 'file',
},
})
await updateAssetStatusActivity({
assetId: asset.id,
status: AssetStatus.processed,
})
const updated = await prisma.asset.findUnique({ where: { id: asset.id } })
expect(updated?.status).toBe(AssetStatus.trashed)
expect(updated?.isDeleted).toBe(true)
})
it('should update task usage', async () => {
const task = await prisma.workflowTask.create({
data: {
@@ -69,4 +90,13 @@ describe('Task Activities', () => {
expect(updated?.outputTokens).toBe(200)
expect(updated?.model).toBe('gpt-4o')
})
it('should not throw error when updating status of a non-existent or purged task', async () => {
await expect(
updateTaskStatusActivity({
taskId: 'non-existent-task-id',
status: WorkflowTaskStatus.failed,
}),
).resolves.not.toThrow()
})
})
@@ -70,7 +70,7 @@ export interface UpdateTaskStatusParams {
}
export async function updateTaskStatusActivity(params: UpdateTaskStatusParams): Promise<void> {
await prisma.workflowTask.update({
await prisma.workflowTask.updateMany({
where: { id: params.taskId },
data: {
status: params.status,
@@ -85,8 +85,8 @@ export interface UpdateAssetStatusParams {
}
export async function updateAssetStatusActivity(params: UpdateAssetStatusParams): Promise<void> {
await prisma.asset.update({
where: { id: params.assetId },
await prisma.asset.updateMany({
where: { id: params.assetId, isDeleted: false },
data: { status: params.status },
})
}
@@ -99,7 +99,7 @@ export interface UpdateTaskUsageParams {
}
export async function updateTaskUsageActivity(params: UpdateTaskUsageParams): Promise<void> {
await prisma.workflowTask.update({
await prisma.workflowTask.updateMany({
where: { id: params.taskId },
data: {
inputTokens: params.inputTokens,
@@ -120,7 +120,7 @@ export interface UpdateWorkflowTaskParams {
}
export async function updateWorkflowTaskActivity(params: UpdateWorkflowTaskParams): Promise<void> {
await prisma.workflowTask.update({
await prisma.workflowTask.updateMany({
where: { id: params.taskId },
data: {
...(params.status !== undefined ? { status: params.status } : {}),
+1
View File
@@ -4,3 +4,4 @@ export * from './temporal-executor'
export * from './workflow-utils'
export * from './workflow'
export * from './activities/task'
export * from './local-task-storage'
@@ -413,5 +413,153 @@ describe('LocalExecutor Integration Tests', () => {
unregisterLocalCancelHandler(taskId)
})
it('clears active heartbeat timer when cancelling a task', async () => {
let resolveChat: (value: unknown) => void = () => {}
const chatPromise = new Promise((resolve) => {
resolveChat = resolve
})
mocks.agentChat.mockImplementationOnce(() => chatPromise)
const task = await prisma.workflowTask.create({
data: {
assetId: 'test-asset-cancel',
type: WorkflowTaskType.chat,
status: WorkflowTaskStatus.pending,
},
})
// Wait briefly for submit to start and establish heartbeat
await new Promise((resolve) => setTimeout(resolve, 50))
// Heartbeat timer should be tracked
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const heartbeats = (executor as any).heartbeatIntervals as Map<string, Timer>
expect(heartbeats.has(task.id)).toBe(true)
await executor.cancel(task.id)
// Timer should be cleared and removed
expect(heartbeats.has(task.id)).toBe(false)
resolveChat(undefined)
await new Promise((resolve) => setTimeout(resolve, 50))
})
it('handles heartbeat updateMany returning 0 when task is deleted from database', async () => {
let resolveChat: (value: unknown) => void = () => {}
const chatPromise = new Promise((resolve) => {
resolveChat = resolve
})
mocks.agentChat.mockImplementationOnce(() => chatPromise)
const task = await prisma.workflowTask.create({
data: {
assetId: 'test-asset-deleted',
type: WorkflowTaskType.chat,
status: WorkflowTaskStatus.pending,
},
})
await new Promise((resolve) => setTimeout(resolve, 50))
// Delete the task from DB while task is running
await prisma.workflowTask.delete({ where: { id: task.id } })
// UpdateMany should safely return count 0 without throwing P2025
const { count } = await prisma.workflowTask.updateMany({
where: { id: task.id },
data: { heartbeat: new Date() },
})
expect(count).toBe(0)
resolveChat(undefined)
await new Promise((resolve) => setTimeout(resolve, 50))
})
it('aborts local task abort signal when task is cancelled', async () => {
const { getLocalTaskAbortSignal } = await import('./workflow-utils')
let resolveChat: (value: unknown) => void = () => {}
const chatPromise = new Promise((resolve) => {
resolveChat = resolve
})
mocks.agentChat.mockImplementationOnce(() => chatPromise)
const task = await prisma.workflowTask.create({
data: {
assetId: 'test-asset-abort-signal',
type: WorkflowTaskType.chat,
status: WorkflowTaskStatus.pending,
},
})
await new Promise((resolve) => setTimeout(resolve, 50))
const signal = getLocalTaskAbortSignal(task.id)
expect(signal).toBeDefined()
expect(signal?.aborted).toBe(false)
await executor.cancel(task.id)
expect(signal?.aborted).toBe(true)
resolveChat(undefined)
await new Promise((resolve) => setTimeout(resolve, 50))
})
it('cancels queued local tasks before execution when limiter is saturated', async () => {
let resolveFirstTranscode: (value: unknown) => void = () => {}
const firstTranscodePromise = new Promise((resolve) => {
resolveFirstTranscode = resolve
})
mocks.transcodeMedia.mockImplementationOnce(() => firstTranscodePromise)
mocks.transcodeMedia.mockImplementationOnce(() => Promise.resolve())
// 1. Task 1 starts and occupies the single transcode slot
const task1 = await prisma.workflowTask.create({
data: {
assetId: 'asset-queued-cancel-1',
type: WorkflowTaskType.transcode,
status: WorkflowTaskStatus.pending,
},
})
// 2. Task 2 is submitted and queued because concurrency limit is 1
const task2 = await prisma.workflowTask.create({
data: {
assetId: 'asset-queued-cancel-2',
type: WorkflowTaskType.transcode,
status: WorkflowTaskStatus.pending,
},
})
await new Promise((resolve) => setTimeout(resolve, 50))
// Task 1 should be running
expect(mocks.transcodeMedia).toHaveBeenCalledWith(expect.objectContaining({ id: task1.id }))
// Task 2 should not have started yet
expect(mocks.transcodeMedia).not.toHaveBeenCalledWith(
expect.objectContaining({ id: task2.id }),
)
// 3. Cancel task 2 while it is still waiting in the queue
await executor.cancel(task2.id)
// 4. Release task 1 so the concurrency slot becomes available
resolveFirstTranscode(undefined)
await new Promise((resolve) => setTimeout(resolve, 50))
// 5. Verify task 2's workflow was NEVER executed
expect(mocks.transcodeMedia).not.toHaveBeenCalledWith(
expect.objectContaining({ id: task2.id }),
)
// 6. Verify task 2 was marked failed / cancelled
const dbTask2 = await prisma.workflowTask.findUnique({
where: { id: task2.id },
})
expect(dbTask2?.status).toBe(WorkflowTaskStatus.failed)
expect((dbTask2?.output as { error?: string })?.error).toContain('cancelled')
})
})
})
+108 -11
View File
@@ -2,8 +2,15 @@ import { prisma } from '@shumai/db'
import { WorkflowTask, WorkflowTaskStatus } from '@shumai/db'
import { Executor } from './executor'
import * as taskActivities from './activities/task'
import {
getConcurrencyLimit,
registerLocalTaskAbortController,
runInLocalTaskContext,
triggerLocalCancel,
unregisterLocalTaskAbortController,
} from './workflow-utils'
import { logger } from '@shumai/core/src/logger'
import { getConcurrencyLimit, triggerLocalCancel } from './workflow-utils'
import './local-task-storage'
type WorkflowFn = (task: WorkflowTask) => Promise<void>
@@ -30,6 +37,7 @@ export function registerActivities(acts: Record<string, unknown>) {
globalObj.__localActivities = activityRegistry
globalObj.__localLogger = logger
// ConcurrencyLimiter manages concurrent execution of promises with a FIFO queue.
export class ConcurrencyLimiter {
private activeCount = 0
private queue: (() => void)[] = []
@@ -72,6 +80,7 @@ export class ConcurrencyLimiter {
export class LocalExecutor implements Executor {
private interval: Timer | null = null
private processingTasks = new Set<string>()
private heartbeatIntervals = new Map<string, Timer>()
private transcodeLimiter: ConcurrencyLimiter
private generalLimiter: ConcurrencyLimiter
@@ -94,7 +103,7 @@ export class LocalExecutor implements Executor {
async submit(task: WorkflowTask): Promise<string> {
if (task.status !== WorkflowTaskStatus.pending) {
await prisma.workflowTask.update({
await prisma.workflowTask.updateMany({
where: { id: task.id },
data: { status: WorkflowTaskStatus.pending },
})
@@ -135,14 +144,26 @@ export class LocalExecutor implements Executor {
// 2. Start heartbeat updater immediately
const heartbeatInterval = setInterval(async () => {
try {
await prisma.workflowTask.update({
const { count } = await prisma.workflowTask.updateMany({
where: { id: task.id },
data: { heartbeat: new Date() },
})
if (count === 0) {
clearInterval(heartbeatInterval)
this.heartbeatIntervals.delete(task.id)
logger.debug(
{ taskId: task.id },
'[LocalExecutor] Stopped heartbeat for deleted or cancelled task',
)
}
} catch (err) {
console.error(`[LocalExecutor] Failed to update heartbeat for task ${task.id}:`, err)
}
}, 5000)
this.heartbeatIntervals.set(task.id, heartbeatInterval)
const abortController = new AbortController()
registerLocalTaskAbortController(task.id, abortController)
const limiter =
task.type && task.type.startsWith('transcode')
@@ -152,10 +173,32 @@ export class LocalExecutor implements Executor {
limiter
.run(async () => {
try {
await this.processTaskWrapper(task)
if (abortController.signal.aborted) {
logger.info(
{ taskId: task.id },
'[LocalExecutor] Queued task was aborted before execution',
)
try {
await prisma.workflowTask.updateMany({
where: { id: task.id, status: WorkflowTaskStatus.processing },
data: {
status: WorkflowTaskStatus.failed,
output: { error: 'Workflow task was cancelled before execution' },
},
})
} catch {
// Ignore if task was already deleted
}
return
}
await runInLocalTaskContext({ taskId: task.id, abortController }, async () => {
await this.processTaskWrapper(task)
})
} finally {
// 3. Clean up the heartbeat updater and processing set when the task finishes
clearInterval(heartbeatInterval)
this.heartbeatIntervals.delete(task.id)
unregisterLocalTaskAbortController(task.id)
this.processingTasks.delete(task.id)
}
})
@@ -168,7 +211,13 @@ export class LocalExecutor implements Executor {
}
async cancel(taskId: string): Promise<void> {
const timer = this.heartbeatIntervals.get(taskId)
if (timer) {
clearInterval(timer)
this.heartbeatIntervals.delete(taskId)
}
triggerLocalCancel(taskId)
logger.info({ taskId }, '[LocalExecutor] Cancelled workflow task')
}
start(): void {
@@ -181,6 +230,13 @@ export class LocalExecutor implements Executor {
clearInterval(this.interval)
this.interval = null
}
for (const timer of this.heartbeatIntervals.values()) {
clearInterval(timer)
}
this.heartbeatIntervals.clear()
for (const taskId of this.processingTasks) {
triggerLocalCancel(taskId)
}
}
// Returns the array of task promises so tests can await them to avoid early rollback.
@@ -188,6 +244,10 @@ export class LocalExecutor implements Executor {
const promises: Promise<void>[] = []
try {
const staleTime = new Date(Date.now() - 30 * 1000)
// Find tasks that are:
// 1. Pending (new tasks)
// 2. Processing but stale (worker crashed, heartbeat > 30s ago)
const tasks = await prisma.workflowTask.findMany({
where: {
OR: [
@@ -198,6 +258,7 @@ export class LocalExecutor implements Executor {
},
],
},
orderBy: { id: 'asc' },
take: 50,
})
@@ -206,8 +267,7 @@ export class LocalExecutor implements Executor {
this.processingTasks.add(task.id)
// 1. Immediately mark task as processing and set initial heartbeat in DB
// to guarantee no other ticks/replicas can double-query it.
// We use updateMany to atomically claim it only if it is still pending or stale.
// atomically, ensuring no two workers pick up the same task.
try {
const affected = await prisma.workflowTask.updateMany({
where: {
@@ -230,23 +290,38 @@ export class LocalExecutor implements Executor {
continue
}
} catch (err) {
console.error(`[LocalExecutor] Failed to mark task ${task.id} as processing:`, err)
console.error(
`[LocalExecutor] Failed to mark task ${task.id} as processing in tick:`,
err,
)
this.processingTasks.delete(task.id)
continue
}
// 2. Start heartbeat updater immediately so it updates heartbeat
// 2. Start heartbeat updater immediately to prevent other workers from considering it stale
// even while the task is queued waiting for limiter capacity.
const heartbeatInterval = setInterval(async () => {
try {
await prisma.workflowTask.update({
const { count } = await prisma.workflowTask.updateMany({
where: { id: task.id },
data: { heartbeat: new Date() },
})
if (count === 0) {
clearInterval(heartbeatInterval)
this.heartbeatIntervals.delete(task.id)
logger.debug(
{ taskId: task.id },
'[LocalExecutor] Stopped heartbeat for deleted or cancelled task',
)
}
} catch (err) {
console.error(`[LocalExecutor] Failed to update heartbeat for task ${task.id}:`, err)
}
}, 5000)
this.heartbeatIntervals.set(task.id, heartbeatInterval)
const abortController = new AbortController()
registerLocalTaskAbortController(task.id, abortController)
const limiter =
task.type && task.type.startsWith('transcode')
@@ -256,10 +331,32 @@ export class LocalExecutor implements Executor {
const promise = limiter
.run(async () => {
try {
await this.processTaskWrapper(task)
if (abortController.signal.aborted) {
logger.info(
{ taskId: task.id },
'[LocalExecutor] Queued task was aborted before execution',
)
try {
await prisma.workflowTask.updateMany({
where: { id: task.id, status: WorkflowTaskStatus.processing },
data: {
status: WorkflowTaskStatus.failed,
output: { error: 'Workflow task was cancelled before execution' },
},
})
} catch {
// Ignore if task was already deleted
}
return
}
await runInLocalTaskContext({ taskId: task.id, abortController }, async () => {
await this.processTaskWrapper(task)
})
} finally {
// 3. Clean up the heartbeat updater and processing set when the task finishes
clearInterval(heartbeatInterval)
this.heartbeatIntervals.delete(task.id)
unregisterLocalTaskAbortController(task.id)
this.processingTasks.delete(task.id)
}
})
@@ -285,7 +382,7 @@ export class LocalExecutor implements Executor {
} catch (err) {
console.error(`Error in workflow ${task.type} for task ${task.id}:`, err)
try {
await prisma.workflowTask.update({
await prisma.workflowTask.updateMany({
where: { id: task.id },
data: {
status: WorkflowTaskStatus.failed,
@@ -0,0 +1,12 @@
import { AsyncLocalStorage } from 'node:async_hooks'
import type { LocalTaskContext } from './workflow-utils'
// Store AsyncLocalStorage on globalThis to share with workflow-utils without
// requiring workflow-utils to import node:async_hooks (which would break Temporal's Webpack workflow bundler).
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalObj = globalThis as any
if (!globalObj.__localTaskStorage) {
globalObj.__localTaskStorage = new AsyncLocalStorage<LocalTaskContext>()
}
export const localTaskStorage: AsyncLocalStorage<LocalTaskContext> = globalObj.__localTaskStorage
@@ -1,5 +1,6 @@
import { Connection, Client } from '@temporalio/client'
import { WorkflowTask, WorkflowTaskType } from '@shumai/db'
import { prisma, WorkflowTask, WorkflowTaskType } from '@shumai/db'
import { logger } from '@shumai/core/src/logger'
import { Executor } from './executor'
import { TaskQueueAgent, TaskQueueTranscode } from './workflow-utils'
@@ -80,9 +81,18 @@ export class TemporalExecutor implements Executor {
async cancel(taskId: string): Promise<void> {
const client = await this.getClient()
const workflowId = `chat-${taskId}`
const handle = client.workflow.getHandle(workflowId)
await handle.cancel()
const task = await prisma.workflowTask.findUnique({
where: { id: taskId },
select: { type: true },
})
const workflowId = task?.type ? `${task.type}-${taskId}` : `chat-${taskId}`
try {
const handle = client.workflow.getHandle(workflowId)
await handle.cancel()
logger.info({ taskId, workflowId }, '[TemporalExecutor] Cancelled workflow task')
} catch (err) {
logger.warn({ taskId, workflowId, err }, '[TemporalExecutor] Failed to cancel workflow task')
}
}
start(): void {
+60 -2
View File
@@ -204,6 +204,11 @@ export function getConcurrencyLimit(envVar: string | undefined, defaultValue: nu
return parsed
}
export interface LocalTaskContext {
taskId: string
abortController: AbortController
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalObjWithCancel = globalThis as any
if (!globalObjWithCancel.__localCancelHandlers) {
@@ -211,6 +216,52 @@ if (!globalObjWithCancel.__localCancelHandlers) {
}
const localCancelHandlers: Map<string, () => void> = globalObjWithCancel.__localCancelHandlers
if (!globalObjWithCancel.__localTaskAbortControllers) {
globalObjWithCancel.__localTaskAbortControllers = new Map<string, AbortController>()
}
const localTaskAbortControllers: Map<string, AbortController> =
globalObjWithCancel.__localTaskAbortControllers
interface LocalTaskStorageHolder {
getStore: () => LocalTaskContext | undefined
run: <T>(store: LocalTaskContext, fn: () => T) => T
}
function getLocalTaskStorage(): LocalTaskStorageHolder | undefined {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (globalThis as any).__localTaskStorage
}
export function registerLocalTaskAbortController(
taskId: string,
controller: AbortController,
): void {
localTaskAbortControllers.set(taskId, controller)
}
export function unregisterLocalTaskAbortController(taskId: string): void {
localTaskAbortControllers.delete(taskId)
}
export function runInLocalTaskContext<T>(context: LocalTaskContext, fn: () => T): T {
registerLocalTaskAbortController(context.taskId, context.abortController)
const storage = getLocalTaskStorage()
if (storage) {
return storage.run(context, fn)
}
return fn()
}
export function getLocalTaskAbortSignal(taskId?: string): AbortSignal | undefined {
if (taskId) {
const controller = localTaskAbortControllers.get(taskId)
if (controller) {
return controller.signal
}
}
return getLocalTaskStorage()?.getStore()?.abortController?.signal
}
export function registerLocalCancelHandler(taskId: string, cancelFn: () => void) {
localCancelHandlers.set(taskId, cancelFn)
}
@@ -220,10 +271,17 @@ export function unregisterLocalCancelHandler(taskId: string) {
}
export function triggerLocalCancel(taskId: string): boolean {
let cancelled = false
const controller = localTaskAbortControllers.get(taskId)
if (controller) {
controller.abort()
localTaskAbortControllers.delete(taskId)
cancelled = true
}
const handler = localCancelHandlers.get(taskId)
if (handler) {
handler()
return true
cancelled = true
}
return false
return cancelled
}
+4 -1
View File
@@ -1,4 +1,4 @@
import { prisma, registerWorkflowTrigger, WorkflowTask } from '@shumai/db'
import { prisma, registerWorkflowCancel, registerWorkflowTrigger, WorkflowTask } from '@shumai/db'
import path from 'path'
import { ulid } from 'ulid'
import * as taskActivities from './activities/task'
@@ -187,3 +187,6 @@ export const workflowService = new WorkflowService()
registerWorkflowTrigger(async (task) => {
await workflowService.submit(task)
})
registerWorkflowCancel(async (taskId) => {
await workflowService.cancel(taskId)
})
+100
View File
@@ -0,0 +1,100 @@
import { describe, expect, it } from 'vitest'
import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { extractChangelog } from './extract-changelog'
describe('extractChangelog', () => {
const sampleChangelog = `# Changelog
All notable changes to this project will be documented in this file.
## [Unreleased]
### Added
- Some unreleased feature
## [1.2.0] - 2026-09-18
### Added
- New feature A
- New feature B
### Fixed
- Fixed bug 1
## [1.1.0] - 2026-09-01
### Fixed
- Fixed bug 2
## [1.0.0]
### Added
- Initial release
`
it('extracts notes for version with date header', () => {
const notes = extractChangelog(sampleChangelog, '1.2.0')
expect(notes).toBe(`### Added\n- New feature A\n- New feature B\n\n### Fixed\n- Fixed bug 1`)
})
it('extracts notes when version is prefixed with "v"', () => {
const notes = extractChangelog(sampleChangelog, 'v1.2.0')
expect(notes).toBe(`### Added\n- New feature A\n- New feature B\n\n### Fixed\n- Fixed bug 1`)
})
it('extracts notes when version header has no date', () => {
const notes = extractChangelog(sampleChangelog, '1.0.0')
expect(notes).toBe(`### Added\n- Initial release`)
})
it('extracts notes for the last release at the end of the file', () => {
const notes = extractChangelog(sampleChangelog, 'v1.0.0')
expect(notes).toBe(`### Added\n- Initial release`)
})
it('extracts notes for middle versions correctly', () => {
const notes = extractChangelog(sampleChangelog, '1.1.0')
expect(notes).toBe(`### Fixed\n- Fixed bug 2`)
})
it('extracts notes for Unreleased', () => {
const notes = extractChangelog(sampleChangelog, 'Unreleased')
expect(notes).toBe(`### Added\n- Some unreleased feature`)
})
it('returns null if the version is not found', () => {
const notes = extractChangelog(sampleChangelog, '9.9.9')
expect(notes).toBeNull()
})
it('returns null for empty or whitespace version', () => {
expect(extractChangelog(sampleChangelog, '')).toBeNull()
expect(extractChangelog(sampleChangelog, ' ')).toBeNull()
expect(extractChangelog(sampleChangelog, 'v')).toBeNull()
})
it('returns null for empty content', () => {
expect(extractChangelog('', '1.0.0')).toBeNull()
})
it('handles regex special characters safely in version', () => {
const weirdChangelog = `## [1.0.0-beta.1] - 2026-01-01\n\n- Beta note\n\n## [1.0.0]`
const notes = extractChangelog(weirdChangelog, '1.0.0-beta.1')
expect(notes).toBe('- Beta note')
})
it('successfully extracts real releases from repository CHANGELOG.md', () => {
const realChangelog = readFileSync(resolve(__dirname, '../CHANGELOG.md'), 'utf-8')
const v046 = extractChangelog(realChangelog, 'v0.4.6')
expect(v046).not.toBeNull()
expect(v046).toContain('### Added')
expect(v046).toContain('Introduce Adobe Premiere Pro UXP plugin for Shumai')
expect(v046).toContain('https://github.com/shumaiOne/shumai/pull/407')
const v001 = extractChangelog(realChangelog, '0.0.1')
expect(v001).not.toBeNull()
expect(v001).toBe('### Added\n\n- Initial release of Shumai')
})
})
+115
View File
@@ -0,0 +1,115 @@
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
/**
* Extracts the release notes for a given version from the markdown content of a changelog.
*
* @param content The full text content of CHANGELOG.md
* @param version The version string to search for (e.g. "0.4.6" or "v0.4.6")
* @returns The extracted markdown text, or null if the version is not found.
*/
export function extractChangelog(content: string, version: string): string | null {
if (!content || !version) {
return null
}
const cleanVersion = version.trim().replace(/^v/i, '')
if (!cleanVersion) {
return null
}
const escapedVersion = cleanVersion.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
const headerRegex = new RegExp(`^## \\[(?:v)?${escapedVersion}\\](?:\\s*-\\s*.*)?$`, 'm')
const match = headerRegex.exec(content)
if (!match || match.index === undefined) {
return null
}
const startIndex = match.index + match[0].length
const remainingContent = content.slice(startIndex)
// Look for the next release header starting with "## ["
const nextHeaderRegex = /^## \[/m
const nextMatch = nextHeaderRegex.exec(remainingContent)
const sectionContent =
nextMatch && nextMatch.index !== undefined
? remainingContent.slice(0, nextMatch.index)
: remainingContent
return sectionContent.trim()
}
interface CliOptions {
version: string
output?: string
changelogPath: string
}
function parseCliArgs(args: string[]): CliOptions {
let version = ''
let output: string | undefined
let changelogPath = 'CHANGELOG.md'
for (let i = 0; i < args.length; i++) {
const arg = args[i]
if (arg === '--output' || arg === '-o') {
output = args[++i]
} else if (arg === '--changelog' || arg === '-c') {
changelogPath = args[++i]
} else if (!arg.startsWith('-') && !version) {
version = arg
}
}
return { version, output, changelogPath }
}
export function runCli(argv: string[]): void {
const { version, output, changelogPath } = parseCliArgs(argv)
if (!version) {
console.error(
'Usage: bun run scripts/extract-changelog.ts <version> [--output <path>] [--changelog <path>]',
)
process.exit(1)
}
const resolvedChangelog = resolve(changelogPath)
if (!existsSync(resolvedChangelog)) {
console.error(`Changelog file not found at: ${resolvedChangelog}`)
process.exit(1)
}
const content = readFileSync(resolvedChangelog, 'utf-8')
const notes = extractChangelog(content, version)
if (output) {
const resolvedOutput = resolve(output)
mkdirSync(dirname(resolvedOutput), { recursive: true })
writeFileSync(resolvedOutput, notes ?? '', 'utf-8')
if (notes) {
console.log(`Extracted release notes for ${version} to ${resolvedOutput}`)
} else {
console.warn(
`No changelog entry found for version ${version}; wrote empty file to ${resolvedOutput}`,
)
}
} else {
if (notes) {
process.stdout.write(notes + '\n')
} else {
console.warn(`No changelog entry found for version ${version}`)
}
}
}
// Run CLI when invoked directly
const isDirectlyExecuted =
Boolean(import.meta.main) ||
(process.argv[1] ? resolve(process.argv[1]) === resolve(import.meta.filename ?? '') : false)
if (isDirectlyExecuted) {
runCli(process.argv.slice(2))
}

Some files were not shown because too many files have changed in this diff Show More