Compare commits

...
7 Commits
Author SHA1 Message Date
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
75 changed files with 3752 additions and 214 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
+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
+715
View File
@@ -0,0 +1,715 @@
# 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.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.7",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/cli",
"version": "0.4.6",
"version": "0.4.7",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/premiere-uxp",
"version": "0.4.6",
"version": "0.4.7",
"private": true,
"type": "commonjs",
"scripts": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode-app",
"version": "0.4.6",
"version": "0.4.7",
"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.7",
"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.7",
"bin": {
"shumai-agent": "./src/index.ts",
},
@@ -45,7 +45,7 @@
},
"apps/cli": {
"name": "@shumai/cli",
"version": "0.4.6",
"version": "0.4.7",
"bin": {
"shumai-cli": "./src/index.ts",
},
@@ -60,7 +60,7 @@
},
"apps/premiere-uxp": {
"name": "@shumai/premiere-uxp",
"version": "0.4.6",
"version": "0.4.7",
"dependencies": {
"@shumai/api": "workspace:*",
"@shumai/dtos": "workspace:*",
@@ -114,7 +114,7 @@
},
"apps/transcode": {
"name": "@shumai/transcode-app",
"version": "0.4.6",
"version": "0.4.7",
"bin": {
"shumai-transcode": "./src/index.ts",
},
@@ -126,7 +126,7 @@
},
"apps/web": {
"name": "@shumai/web-app",
"version": "0.4.6",
"version": "0.4.7",
"dependencies": {
"@shumai/agent": "workspace:*",
"@shumai/api": "workspace:*",
@@ -146,7 +146,7 @@
},
"packages/agent": {
"name": "@shumai/agent",
"version": "0.4.6",
"version": "0.4.7",
"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.7",
"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.7",
"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.7",
"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.7",
"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.7",
"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.7",
},
"packages/transcode": {
"name": "@shumai/transcode",
"version": "0.4.6",
"version": "0.4.7",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -299,7 +299,7 @@
},
"packages/webui": {
"name": "@shumai/webui",
"version": "0.4.6",
"version": "0.4.7",
"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.7",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
+3 -2
View File
@@ -1,6 +1,6 @@
{
"name": "shumai",
"version": "0.4.6",
"version": "0.4.7",
"private": true,
"type": "module",
"repository": {
@@ -38,7 +38,8 @@
"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"
},
"devDependencies": {
"@eslint/js": "10.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent",
"version": "0.4.6",
"version": "0.4.7",
"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.7",
"private": true,
"type": "module",
"main": "./src/index.ts",
+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.7",
"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(
+4 -1
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 () => {
@@ -376,12 +378,13 @@ describe('TeamService', () => {
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,
})
+7 -1
View File
@@ -33,7 +33,7 @@ export class TeamService {
data: {
name: 'Default Team',
settings: {
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off' },
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', threads: 0 },
},
sandbox: { create: {} },
},
@@ -332,6 +332,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 = {}
@@ -614,6 +614,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(
@@ -1638,5 +1708,109 @@ 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),
)
})
})
})
+62 -20
View File
@@ -116,6 +116,8 @@ export interface TranscodeVideoParams {
hardwareAcceleration?: 'off' | 'auto'
videoBitrate?: string
sourceVideoBitrate?: number
threads?: number
signal?: AbortSignal
}
export interface EncoderConfig {
@@ -627,9 +629,19 @@ export class TranscodeService {
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,6 +748,7 @@ export class TranscodeService {
outputSprite: string,
outputPoster: string,
duration: number,
signal?: AbortSignal,
): 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]`
@@ -766,19 +779,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 +859,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 +1112,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 +1228,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 +1290,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 +1332,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 +1345,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 +1353,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()
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/db",
"version": "0.4.6",
"version": "0.4.7",
"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 {
+2
View File
@@ -59,6 +59,7 @@ declare global {
export interface TranscodeSettings {
videoStrategy: VideoTranscodeStrategy
hardwareAcceleration?: HardwareAcceleration
threads?: number
}
export interface MediaProviderConfig {
@@ -314,6 +315,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.7",
"private": true,
"type": "module",
"main": "./src/index.ts",
+6
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,
+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.7",
"private": true,
"type": "module",
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/tableprinter",
"version": "0.4.6",
"version": "0.4.7",
"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.7",
"private": true,
"type": "module",
"main": "./src/index.ts",
@@ -595,6 +595,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 +683,7 @@ describe('Transcode Activities', () => {
originalFps: 30,
hardwareAcceleration: 'auto',
sourceVideoBitrate: 600_000,
threads: 8,
})
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
@@ -613,6 +691,7 @@ describe('Transcode Activities', () => {
inputFile: '/tmp/v.mp4',
hardwareAcceleration: 'auto',
sourceVideoBitrate: 600_000,
threads: 8,
}),
)
})
@@ -731,6 +810,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'))
@@ -958,16 +1057,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 +1088,7 @@ describe('Transcode Activities', () => {
'-c:v',
'libwebp',
]),
expect.objectContaining({ signal: undefined }),
expect.any(Function),
)
expect(s3Service.putObject).toHaveBeenCalledWith(
@@ -1001,6 +1100,96 @@ describe('Transcode Activities', () => {
)
})
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 +1202,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 +1438,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)
})
})
})
+197 -10
View File
@@ -1,4 +1,4 @@
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 { metadataService } from '@shumai/core/src/metadata/metadata'
@@ -12,7 +12,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 +57,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
@@ -216,6 +244,7 @@ export async function getMediaInfoActivity(params: {
}
export interface VideoActivityParams {
taskId?: string
assetKey: string
filePath: string
videoSpec: PrismaJson.VideoTranscode
@@ -223,6 +252,7 @@ export interface VideoActivityParams {
originalFps: number
hardwareAcceleration?: PrismaJson.HardwareAcceleration
sourceVideoBitrate?: number
threads?: number
}
export async function transcodeVideoActivity(
@@ -233,6 +263,14 @@ export async function transcodeVideoActivity(
const res = params.videoSpec.resolution || `${params.videoSpec.height}p`
const key = path.posix.join(path.posix.dirname(params.assetKey), `${stem}-${res}.mp4`)
const signal = getActivityCancellationSignal(params.taskId)
if (signal?.aborted) {
throw ApplicationFailure.create({
message: 'Video transcoding cancelled',
nonRetryable: true,
})
}
try {
await s3Service.headObject(bucket, key)
return { ...params.videoSpec, key }
@@ -267,10 +305,13 @@ export async function transcodeVideoActivity(
disableAudio,
hardwareAcceleration: params.hardwareAcceleration,
sourceVideoBitrate: params.sourceVideoBitrate,
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 { ...params.videoSpec, key }
@@ -278,6 +319,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') ||
@@ -300,8 +354,10 @@ export async function transcodeVideoActivity(
}
export interface AudioActivityParams {
taskId?: string
assetKey: string
filePath: string
threads?: number
}
export async function transcodeAudioActivity(
@@ -311,6 +367,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 +390,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 +404,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 +476,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 +507,7 @@ export async function transcodeImageActivity(
}
export interface GenerateSpriteActivityParams {
taskId?: string
assetKey: string
filePath: string
mediaInfo: PrismaJson.MediaInfo
@@ -435,6 +517,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 +543,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 +557,12 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
spriteFile,
posterFile,
params.mediaInfo.duration,
signal,
)
}
const spriteBuffer = fs.readFileSync(spriteFile)
await ensureAssetNotPurging(params.assetKey)
await s3Service.putObject(
bucket,
params.spriteSpec.key,
@@ -492,6 +585,19 @@ 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') ||
@@ -606,6 +712,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 +771,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 +782,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 +808,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 +855,21 @@ export async function takeScreenshotsActivity(params: {
export interface ExtractPosterActivityParams {
assetKey: string
posterSpec: PrismaJson.PosterInfo
taskId?: string
signal?: AbortSignal
}
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)
@@ -754,9 +903,10 @@ export async function extractPosterActivity(
'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,6 +919,20 @@ 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') ||
@@ -816,6 +980,7 @@ export async function overlayAnnotationsActivity(params: {
}
export async function renderPdfPagesActivity(params: {
taskId?: string
assetKey: string
assetId: string
start: number
@@ -823,11 +988,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 +1120,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,6 +399,7 @@ describe('Watermark Activities', () => {
hardwareAcceleration: 'auto',
sourceVideoBitrate: 1800000,
disableAudio: true,
threads: 6,
}),
)
@@ -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.
@@ -338,6 +339,7 @@ export async function transcodeWatermarkMediaActivity(
overlayFile: overlayPngPath,
hardwareAcceleration,
sourceVideoBitrate,
threads,
})
const stat = fs.statSync(outFilePath)
+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,
@@ -33,6 +33,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,99 @@ 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)
})
})
@@ -68,6 +68,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
const posterResult = await executeActivity(workerQueue, extractPosterActivity, {
assetKey: key,
posterSpec,
taskId: task.id,
})
mediaInfo.poster = posterResult.poster
await executeActivity(workerQueue, updateAssetMediaActivity, {
@@ -76,6 +77,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) {
@@ -98,6 +136,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
}
const videoTranscode = await executeActivity(workerQueue, transcodeVideoActivity, {
taskId: task.id,
assetKey: key,
filePath,
videoSpec,
@@ -105,6 +144,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
originalFps: metadata.frameRate,
hardwareAcceleration: spec.hardwareAcceleration,
sourceVideoBitrate: metadata.videoBitRate || metadata.bitRate,
threads: spec.threads,
})
if (res === '180p') {
@@ -118,8 +158,10 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
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 +175,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()
})
})
+21 -5
View File
@@ -133,6 +133,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 +250,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>
@@ -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) {
+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))
}
+8
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,10 @@
"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",
"notification_settings": "Notification Settings",
"notifications_description": "Configure your personal notification preferences for this team.",
@@ -1018,6 +1023,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",
+8
View File
@@ -132,6 +132,7 @@
"activity_notifications": "活动通知",
"activity_notifications_description": "接收此项目中评论、上传及自动后台分析任务的应用内通知。",
"processing": "处理中...",
"preparing": "准备中...",
"project_updated": "项目已更新",
"failed_update_project": "更新项目失败",
"project_notification_updated": "项目通知设置已更新",
@@ -260,6 +261,10 @@
"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} 线程",
"notification_settings": "通知设置",
"notifications_description": "配置您在此团队的个人通知偏好。",
@@ -1018,6 +1023,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.7",
"private": true,
"type": "module",
"main": "./index.html",
@@ -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 -1
View File
@@ -1 +1 @@
export const APP_VERSION = '0.4.6'
export const APP_VERSION = '0.4.7'
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/workflow-core",
"version": "0.4.6",
"version": "0.4.7",
"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))
}
+40
View File
@@ -99,6 +99,45 @@ function updateVersions(newVersion: string) {
}
}
function updateChangelog(newVersion: string) {
const changelogFile = 'CHANGELOG.md'
if (!existsSync(changelogFile)) {
return
}
const content = readFileSync(changelogFile, 'utf-8')
if (content.includes(`## [${newVersion}]`) || content.includes(`## [v${newVersion}]`)) {
console.log(` Changelog already contains ## [${newVersion}], skipping update`)
return
}
const unreleasedRegex = /^## \[Unreleased\]/m
if (!unreleasedRegex.test(content)) {
console.warn(' Warning: No ## [Unreleased] header found in CHANGELOG.md')
return
}
const now = new Date()
const year = now.getFullYear()
const month = String(now.getMonth() + 1).padStart(2, '0')
const day = String(now.getDate()).padStart(2, '0')
const dateStr = `${year}-${month}-${day}`
const replacement = `## [Unreleased]
### Added
### Fixed
### Changed
## [${newVersion}] - ${dateStr}`
const updatedContent = content.replace(unreleasedRegex, replacement)
writeFileSync(changelogFile, updatedContent, 'utf-8')
console.log(` Updated ${changelogFile} for v${newVersion} (${dateStr})`)
}
function shellQuote(value: string) {
return `'${value.replace(/'/g, `'\\''`)}'`
}
@@ -151,6 +190,7 @@ if (bumpTypes.has(releaseTarget)) {
console.log(`Bumping version from ${currentVersion} to ${newVersion}...`)
updateVersions(newVersion)
updateChangelog(newVersion)
console.log()
// 3. Update bun.lock