Compare commits

...
50 Commits
Author SHA1 Message Date
yiling c302c162a0 Release v0.5.2 2026-10-13 21:03:51 +08:00
Yiling-J 432be04a96 Update CHANGELOG to remove fixed and changed entries
Removed fixed and changed entries related to 3D visual markup and settings adjustments.
2026-10-13 20:18:03 +08:00
yiling 6c95d14fb3 fix(webui): reverse 3D sprite scrubbing and remove container volumes from turntable doc 2026-10-13 16:49:42 +08:00
Yiling-J 3263580e89 fix(webui): clear markup annotations when rotating 3d model (#474) 2026-10-13 15:21:12 +08:00
yiling f3da916905 fix(asset): remove unbundled GLTF format from supported 3D models 2026-10-13 11:38:25 +08:00
Yiling-J fe8d404a44 feat(agent): support 3D degree comments, markup annotations, and config3d in read_asset (#473)
* feat(agent): support AI embedding, autofill, and read_asset for 3D assets

* feat(agent): support 3D degree comments, markup annotations, and config3d in read_asset

* fix(agent): resolve 3D session annotations to turntable degree frame time
2026-10-13 00:03:21 +08:00
Yiling-J 0f9d213b1d docs: update 3D asset and Gotenberg integration guides (#472) 2026-10-12 16:55:20 +08:00
Yiling-J f952318b34 feat(team): add integrations settings with turntable and gotenberg (#471)
* feat(team): add integrations settings with turntable and gotenberg

* fix(upload): pass teamId to gotenberg availability check during upload preflight
2026-10-12 15:38:15 +08:00
Yiling-J 43a2eced75 feat(transcode): add 3D asset support and turntable viewer (#454)
* feat(transcode): add 3D asset support and turntable viewer

* perf(turntable): stream file via Bun.file and increase upload timeout

* feat(turntable): increase upload timeout to 15m to support 5GB uploads

* fix(webui): align 3D model viewer layout and full-width control bar with video viewer

* feat(webui): unify 3D viewer bottom bar and redesign cyclic ruler slider

- Place RulerSlider in single row with playback and zoom controls, centered with max 320px width
- Flank RulerSlider with minus and plus buttons to step angle by 15°
- Redesign RulerSlider with fixed center indicator and moving cyclic track with continuous 360° wrapping
- Render major ticks longer at 60° intervals without numeric text labels on track
- Display floating degree tooltip above center indicator only during dragging

* fix(webui): prevent RulerSlider from collapsing to 0px width in control bar

- Use flex layout with flex-1 on left and right clusters to preserve center cluster width
- Enforce min-w-[140px] and w-full on RulerSlider
- Fix tooltip positioning and remove outer overflow-hidden

* feat(webui): snap RulerSlider track directly to discrete 15° ticks during drag

* fix(webui): prevent ruler snap-back caused by floating point second truncation

- Use Math.round instead of Math.floor in secondToDegree to avoid 0.999996 dropping to previous frame
- Ensure final dragDegree is committed on pointer up

* fix(webui): fix arrow key frame rounding and duplicate event bubbling

- Use Math.round instead of Math.floor for keyboard arrow frame navigation in ModelViewer
- Add e.stopPropagation() to RulerSlider keyboard events to prevent duplicate bubbling to window listener

* feat(webui): redesign RulerSlider with encapsulated step buttons and capsule pill track

* feat(webui): make RulerSlider responsive on mobile and remove bottom bar reset button

* fix(webui): load 3d video directly without poster and invert drag rotation to counterclockwise

* fix(webui): fix 3d asset viewer frame seeking and drag jitter

* feat(transcode): show 3D asset poster preview immediately after render start

* fix(viewer): synchronize 3D turntable playback via frame callback to prevent skipped degrees

* fix(viewer): handle touchpad zoom gestures and prevent page zoom in 3D viewer

* fix(viewer): eliminate 3D model rotation jitter at 345 degrees

* fix(share): watermark 3D asset turntable video on share links

* fix(share): preserve video transcode resolution on watermarked share links

* fix(viewer): download original 3D model file instead of rendered turntable MP4
2026-10-11 21:32:28 +08:00
Christopher BuzickyandBristopher e894457275 fix(transcode): apply EXIF orientation to non-RAW image transcodes and reported size (#461)
* fix(transcode): apply EXIF orientation to image transcodes and reported size

Cameras and phones store portrait shots as landscape pixels plus an EXIF
orientation tag. sharp ignores the tag and the webp output drops it, so
thumbnails, previews, watermarked share-link images and annotated snapshots
came out sideways, and getImageInfo reported width and height swapped
(a 5152x7728 portrait recorded as 7728x5152).

RAW previews keep their existing handling: transcodeImage still rotates them
from the RAW container orientation and only auto-orients inputs without one,
so RAW and non-RAW images are never rotated twice.

- transcodeImage: autoOrient non-RAW input and size previews from the
  oriented dimensions.
- getImageInfo: report metadata.autoOrient dimensions for non-RAW images.
- compositeOverlayToWebpFile and overlayAnnotationsOnBuffer: autoOrient
  the original, and draw annotations in the displayed coordinate space.
- Tests: service tests that reproduce the bug and guard against double
  rotation of RAW, and a workflow e2e case with a real 600x400 JPEG tagged
  orientation 6 that must come out 400x600.

* refactor(transcode): share orientation helper and test all 8 EXIF orientations

Move the autoOrient decision and the displayed-size lookup into orientedSharpOptions and displayedDimensions so getImageInfo, transcodeImage, compositeOverlayToWebpFile and overlayAnnotationsOnBuffer share one rule: auto-orient unless a RAW container orientation was already applied. Behavior is unchanged.

Add transcode.orientation.test.ts, which runs real sharp over a quadrant-colored JPEG tagged with each of the 8 EXIF orientations and checks the reported and transcoded size plus the top-left and bottom-right corner colors.

* fix(transcode): never auto-orient dcraw output

The dcraw_emu fallback reports orientation undefined because LibRaw already rotates upright, so transcodeImage applied autoOrient to the TIFF and could rotate twice if it kept an Orientation tag. extractAndValidateRawPreview now flags the fallback result as orientationApplied and transcodeImage treats it as already oriented (autoOrient false). Tests cover both the dcraw path and an embedded preview with no container orientation.

---------

Co-authored-by: Bristopher <Bristopher@users.noreply.github.com>
2026-10-10 15:41:49 +08:00
4b1b64fe2b feat(kanban): link related assets to their file or folder (#453)
Related assets in the task edit dialog were plain rows with no way to
open them. Add an opt-in `linkable` prop to TaskRelatedAssets that turns
each row's thumbnail and name into a router Link to the asset in its
project (files -> /projects/$projectId/files/$fileId, folders ->
/projects/$projectId/folders/$folderId), falling back to the task's
project when the asset has none. The edit dialog opts in; the create
dialog does not, so a click cannot discard an unsaved draft.

Co-authored-by: Frederic De Decker <hello@trinity.video>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-07 20:14:36 +08:00
yiling f8beb195dd Release v0.5.1 2026-10-06 22:29:50 +08:00
yiling a97996cb59 docs(changelog): note clickable notification cards 2026-10-06 22:18:18 +08:00
jorgeandYiling-J f870ca9b49 feat(asset): link to assets on notification cards. (#451)
* feat(asset): link to assets on notification cards.

* Update packages/webui/components/notification-card.tsx

Co-authored-by: Yiling-J <njjyl723@gmail.com>

---------

Co-authored-by: Yiling-J <njjyl723@gmail.com>
2026-10-06 22:14:11 +08:00
Yiling-J 2e5ff281a8 feat(transcode): add hardware decoding support for nvenc, qsv, and rkmpp (#452)
* feat(transcode): add hardware decoding support for nvenc, qsv, and rkmpp

* refactor(transcode): eliminate redundant hardware decode gating and dead condition
2026-10-06 17:35:14 +08:00
yiling de8decf113 fix(ci): prevent tagging main on PR workflow_dispatch docker builds 2026-10-06 11:49:49 +08:00
Cameron HarrisandClaude Opus 5.5 dd57fb9ed2 feat(transcode): decode and scale on the GPU for hardware transcodes (VA-API) (#449)
* feat(transcode): decode and scale on the GPU for VA-API transcodes

When the selected encoder is h264_vaapi, decode with -hwaccel vaapi and
scale with scale_vaapi so frames stay in GPU memory, instead of decoding
and scaling on the CPU and hwupload-ing before the encoder. On a Haswell
iGPU this makes 4K proxy/HLS renditions 3-5x faster.

Fallback order: GPU decode + VA-API encode -> software decode + VA-API
encode (previous behavior) -> libx264. Watermark overlays, HDR sources
and rotated sources skip GPU decode: ffmpeg cannot auto-insert its
rotation filter on hardware frames, so rotated input would otherwise come
out sideways instead of failing. SHUMAI_VAAPI_HW_DECODE=false disables it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(transcode): document VA-API GPU decoding and SHUMAI_VAAPI_HW_DECODE

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* refactor(transcode): generic hardware decode config, stall watchdog, reuse probed rotation

Follow-ups from comparing with Immich and Jellyfin:

- Replace the VA-API-specific helpers with a per-encoder HW_DECODE_CONFIGS
  table (input args, output args, GPU scale filter) and build the MP4 and
  HLS input/filter graph in one shared method so the paths cannot drift.
  Only h264_vaapi has an entry; other backends can be added once tested on
  real hardware. The opt-out is now SHUMAI_HW_DECODE=false.
- Kill a GPU-decode attempt with SIGKILL when its output stops growing for
  SHUMAI_HW_DECODE_STALL_TIMEOUT (default 120s) and fall back, since some
  VA-API driver failures hang ffmpeg instead of exiting (immich#31933).
- Add -noautoscale on the GPU-decode path so a mid-stream decoder reinit
  (e.g. 1080 -> 1088) cannot auto-insert a software scaler into the GPU
  graph (jellyfin#17133).
- Pass the rotation already probed into MediaMetadata through the workflow
  and activities as sourceRotation; ffprobe only runs when it is missing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 12:00:01 +08:00
Yiling-J 9a640632aa ci(release): allow manual Docker image build from external PR (#450) 2026-10-05 09:48:48 +08:00
yiling e61641d7ec fix(workflow): increase activity startToCloseTimeout to 120 minutes 2026-10-04 10:22:31 +08:00
Yiling-J 7ca8ba8b2a fix(transcode): resolve RAW transcoding hang in Docker deployments (#447) 2026-10-03 12:45:12 +08:00
Yiling-J 8805d5799a feat(transcode): add dcraw_emu fallback for RAW image preview generation (#446) 2026-10-03 11:03:31 +08:00
yiling 013c4a8156 Release v0.5.0 2026-10-02 20:28:37 +08:00
Yiling-J 20b5ebeefd fix(asset): mark asset as failed and display failure state in webui when transcoding fails (#445)
* fix(asset): mark asset as failed and display failure state in webui when transcoding fails

* fix(transcode): do not mark asset as failed if media processing already succeeded

* test(workflow): add e2e test for video transcode failure status transition

* fix(webui): update failed file card badge to top-right Transcoding Failed label with error tooltip
2026-10-02 20:09:32 +08:00
Yiling-J daa20aed20 fix(webui): add video loading state and poster placeholder (#444)
* fix(webui): add video loading state and poster placeholder

* fix(webui): prevent buffer progress events from canceling stall indicator
2026-10-02 16:19:49 +08:00
Yiling-J 3564d4d164 fix(transcode): avoid selecting attached picture streams for video transcoding (#443)
* fix(transcode): avoid selecting attached picture streams for video transcoding

Filter out attached picture streams (disposition.attached_pic) during video probing and stream selection, matching Immich's default and bitrate selection strategy. Forward explicit primary video and audio stream indices to FFmpeg pipelines to prevent picking embedded cover art or thumbnail streams.

* fix(transcode): skip poster and sprite generation for audio-only assets and add multi-stream e2e tests

* test(workflow): scope pixel format to h264 stream and use yuvj420p for mjpeg cover art
2026-10-02 13:51:17 +08:00
Yiling-J 206763e966 feat(auth): add demo user login button and update demo description (#442)
* feat(auth): add demo user login button and update description

* feat(auth): move demo hint below button and add discord link
2026-10-01 22:04:15 +08:00
Yiling-J 4e4da595a6 feat(settings): redesign video transcoding settings into dedicated cards and rename team AI settings (#441)
* feat(settings): redesign video transcoding settings into dedicated cards and rename team AI settings

* feat(settings): rename Video Strategy to MP4 Transcoding with sub-description
2026-10-01 21:19:25 +08:00
Yiling-J a21a0c9655 fix(settings): prevent deselecting last ladder and coalesce rapid toggles (#440) 2026-10-01 16:35:47 +08:00
Yiling-J fc7282581f fix(share): prevent unwatermarked HLS playback on public shares before transcode completion (#439) 2026-10-01 15:41:45 +08:00
Yiling-J e007054f47 feat(transcode): add multi-resolution strategy with configurable ladders and fallback (#438)
* feat(transcode): add multi-resolution strategy with configurable ladders and fallback

* feat(settings): show toast on settings update and add manual verification plan to PR template

* fix(webui): preserve video resolution and fix 480p label in download dropdowns

* fix(webui): display standard short-side resolution for vertical videos in seekbar

* fix(webui): fix portrait transcode resolution labeling and serialize settings toggles
2026-10-01 13:27:50 +08:00
Yiling-J a84da8678e feat(webui): switch from video.js to hls.js and native video player (#437)
* feat(webui): switch from video.js to hls.js and native video player

* fix(webui): prevent stale seek hijacking and guard native HLS compare mode
2026-09-30 20:23:44 +08:00
Yiling-J 123a8cb5f4 feat(transcode): add HLS live streaming support (#436)
* feat(transcode): add HLS live streaming support

* fix(hls): resolve version stacks for public HLS and add workflow E2E test
2026-09-30 16:31:40 +08:00
Yiling-J 5fe22ac52c feat(transcode): add initial camera RAW image support (#435)
- Add centralized RAW file extension set and detection helper for 23 common camera RAW formats
- Update getProxyType and EXTENSION_MIME_TYPES to route RAW formats into the image pipeline
- Add exiftool-vendored runtime dependency and mark as external in build-npm script
- Implement embedded JPEG extraction to temporary file with priority JpgFromRaw2 -> JpgFromRaw -> PreviewImage
- Read and apply EXIF orientation from RAW container to prevent rotation/mirroring issues
- Integrate into TranscodeService.getImageInfo and transcodeImage with proper temporary file cleanup
- Add hasUsablePreview guard in transcodeImageWorkflow to gracefully handle RAW files without embedded previews
- Add unit, service, workflow, and E2E tests for RAW processing
2026-09-29 21:09:27 +08:00
Yiling-J 11d21444cf fix(trash): prevent empty trash dialog from closing before API call completes (#434)
AlertDialogAction from Radix UI auto-closes the dialog on click.
Added e.preventDefault() so the dialog stays open and shows the
'Deleting...' loading state until the operation finishes.

Fixes both desktop and mobile file browsers.
2026-09-29 10:40:13 +08:00
yiling f2b0415580 Release v0.4.9 2026-09-28 20:17:50 +08:00
Yiling-J c9d0b476cd feat(transcode): fallback to software encoding when hardware transcode fails (#433) 2026-09-28 16:45:28 +08:00
yiling bf5ac566b6 refactor(notification): simplify email wording and remove redundant team references 2026-09-28 13:37:16 +08:00
Yiling-J af8f24aa95 docs(settings): add email notifications documentation to team settings (#432)
* docs(settings): add email notification documentation to team settings

* fix(notification): use correct webui route URLs for project and asset links in emails
2026-09-28 11:27:59 +08:00
Yiling-J d98f486c9d feat(notification): add email notification infrastructure, smtp configuration, and periodic background delivery job (#431)
* feat(notification): add email notification support and dedicated workflow

* feat(webui): add team email notification settings and test email dialog

* refactor(webui): remove redundant card header from email notification settings

* fix(notification): prevent sending notification emails to AI agents

* feat(notification): display project, avatar, upload time and resolve mention names in notification emails

* refactor(notification): remove uploadDebounceSeconds and naive workflow sleep

* refactor(notification): remove temporal notification workflow and keep email infrastructure

* fix(team): prevent leaking email notification settings and credentials in team settings

* feat(notification): add periodic background job for batched email notification delivery

* fix(notification): embed avatars and thumbnails as inline cid attachments
2026-09-28 09:58:59 +08:00
Yiling-J 94ea4c917a feat(transcode): add VA-API hardware acceleration support (#430)
* feat(transcode): add VA-API hardware acceleration support

* fix(docker): switch to jellyfin-ffmpeg 8.1.2-5 for VA-API support

* fix(transcode): probe hardware encoder usability to skip uninitialized drivers

* ci(release): add workflow_dispatch trigger with custom tag input

* fix(transcode): use 256x256 frame dimension for encoder usability probe

* feat(docker): add hwaccel transcoding compose presets matching immich

* docs: add hardware transcoding documentation and quickstart references

* feat(transcode): prioritize h264_vaapi before h264_qsv on Linux

* fix(docker): extend device permission loop to rkmpp and wsl accelerator nodes
2026-09-26 20:55:57 +08:00
Yiling-J 941bf0fd1b feat(transcode): smart poster frame selection and decoupled generation (#428)
* feat(transcode): smart poster frame selection and decoupled generation

* fix(transcode): detect MPEG-TS extension from URL pathname for signed remote sources
2026-09-25 16:37:16 +08:00
Yiling-J 59742dde78 feat(transcode): optimize video sprite generation with seek pool and compositing (#427)
* feat(transcode): optimize video sprite generation with seek pool and compositing

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

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

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

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

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

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

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

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

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

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

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

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

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

The app only needs the database inside the compose network, so the host port
mapping is unnecessary. Remove it from all local and temporal compose files.
2026-09-20 11:46:13 +08:00
223 changed files with 30163 additions and 1645 deletions
+18 -1
View File
@@ -4,6 +4,16 @@ on:
push:
branches: ['main']
tags: ['v*']
workflow_dispatch:
inputs:
tag:
description: 'Docker image tag (e.g. feature-vaapi)'
required: false
type: string
pr:
description: 'Pull request number (e.g. 449)'
required: false
type: string
jobs:
build-and-push:
@@ -14,7 +24,10 @@ jobs:
steps:
- name: Checkout repository
id: checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.pr && format('refs/pull/{0}/head', inputs.pr) || github.ref }}
# Set up Docker Buildx
- name: Set up Docker Buildx
@@ -45,7 +58,11 @@ jobs:
crpi-000nkafzu6xvpwsc.cn-hongkong.personal.cr.aliyuncs.com/shumai-one/shumai
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=branch,enable=${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.pr && !inputs.tag) }}
type=raw,value=pr-${{ inputs.pr }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.pr != '' && inputs.tag == '' }}
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag != '' }}
labels: |
org.opencontainers.image.revision=${{ steps.checkout.outputs.commit }}
# Build and push Docker image
- name: Build and push Docker image
+2 -1
View File
@@ -7,4 +7,5 @@ packages/core/src/generated
src/ui/components/ui
packages/webui/paraglide
*.md
**/*.md
**/*.md
docs/changelog.mdx
+7
View File
@@ -92,6 +92,13 @@ Briefly describe what this PR changes and why.
- Describe the checks or tests you ran.
- Include relevant outputs if applicable.
## Manual Verification Plan
- Provide concise instructions for manually verifying this change.
- Assume familiarity with the project and existing development workflow.
- Skip boilerplate steps (e.g. starting the app, logging in, opening common pages) unless they are part of the change.
- Focus on what needs to be verified, including scenarios, edge cases, and expected results.
## Notes
Add any additional context, caveats, or follow-up work.
+84
View File
@@ -12,6 +12,90 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Changed
## [0.5.2] - 2026-10-13
### Added
* **3d asset**: Add support for 3D model files (.glb, .gltf, .obj, .fbx, .stl, .dae, .usd, .usda, .usdc, .usdz) with automated turntable video rendering, hover sprite scrubbing, and an interactive 3D turntable viewer featuring 360° ruler scrubbing and degree-based markup comments
* **kanban**: Related assets on a task are now clickable, taking you directly to that file or folder in its project
* **settings**: Add an Integrations section to Team Settings with dedicated configuration for Gotenberg Document Converter, supporting connection testing and environment variable override protection
### Fixed
* **transcode**: Fix an issue where portrait photos from cameras and phones appeared sideways in thumbnails, previews, watermarked share links and annotated snapshots, and were listed with their width and height swapped
### Changed
## [0.5.1] - 2026-10-06
### Added
* **notification**: Notification cards are now clickable, taking you directly to the relevant file
* **transcode**: Add hardware decoding and GPU scaling support for NVIDIA NVENC, Intel QuickSync Video (QSV), Rockchip (RKMPP), and VA-API (Intel and AMD GPUs), significantly speeding up video proxy and HLS rendition generation across supported platforms. Set `SHUMAI_HW_DECODE=false` to turn hardware decoding off
* **transcode**: Add `dcraw_emu` fallback to generate WebP previews for camera RAW files without embedded JPEG previews
### Fixed
### Changed
## [0.5.0] - 2026-10-02
### Added
* **transcode**: Add configurable target resolution ladders (480p, 720p, 1080p, 1440p, 2160p) for MP4 Multi Resolutions transcoding in team settings, with unified resolution matching and lowest-resolution fallback for both MP4 and HLS
* **transcode**: Add HLS live streaming with fMP4/CMAF adaptive bitrate ladders (480p, 720p, 1080p, 1440p, 2160p), configurable in Transcode Settings, with automatic quality switching, manual resolution selection in the video viewer, seamless rendition switching, and full watermarking support for shared links
* **transcode**: Add basic camera RAW image support for popular camera formats (including Sony ARW, Canon CR2/CR3, Nikon NEF, Adobe DNG, Fujifilm RAF, and Panasonic RW2), extracting high-quality embedded JPEG previews and automatically applying camera orientation for fast thumbnail and proxy generation
### Fixed
- **asset**: Fix an issue where media files remained stuck in a perpetual "Preparing..." state when transcoding failed, by displaying a clear failed status and error details in the file list and file viewer
* **transcode**: Fix an issue where videos or audio-only files containing attached cover art or picture streams could cause transcoding to fail during poster generation or select a single static image instead of the video
* **webui**: Fix inconsistent video resolution labels across download menus, mobile file headers, and the video player by correctly deriving resolutions from the video's short side, including portrait videos and 480p videos
* **trash**: Fix an issue where the "Empty Trash" confirmation dialog would close immediately instead of showing a loading state while files were being permanently deleted
### Changed
* **settings**: Redesign team Video Transcoding settings with dedicated cards for Transcode Policy, Hardware Acceleration, and FFmpeg Threads, clearly explaining MP4 and HLS playback vs download behavior and storage implications
* **settings**: Rename AI Settings group to Team AI Settings in settings navigation
## [0.4.9] - 2026-09-28
### Added
- **notification**: You can now receive notifications via email, with batched digest emails and configurable team-level SMTP settings
- **transcode**: Add VA-API hardware acceleration support for Linux hosts and Docker environments with Intel and AMD GPUs, featuring automatic DRI render node discovery, variable bitrate control, and structured transcoding observability logs
- **transcode**: Add automatic fallback to software transcoding (libx264) when hardware-accelerated video encoding encounters GPU resolution constraints or runtime driver errors
- **docker**: Add modular hardware-accelerated transcoding presets matching Immich's compose configuration via `hwaccel.transcoding.yaml` with support for NVENC, QuickSync, RKMPP, and VA-API
### Fixed
### Changed
- **transcode**: Improve video poster selection using intelligent scene detection and color variance filtering to automatically skip black frames, fade-ins, and blank intros in favor of representative video content
- **transcode**: Optimize video sprite generation for large and long videos using a concurrent fast-seek pool and image compositing, avoiding full-video decoding while preserving instant single-pass generation for short clips
## [0.4.8] - 2026-09-24
### Added
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
### Fixed
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
### Changed
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
## [0.4.7] - 2026-09-19
### Added
+18 -7
View File
@@ -30,11 +30,7 @@ RUN bun run scripts/extract-runtime-deps.ts
# Stage 2: Runner
FROM oven/bun:1.4.2 AS runner
# Install ffmpeg/ffprobe
COPY --from=mwader/static-ffmpeg:8.1 /ffmpeg /usr/local/bin/
COPY --from=mwader/static-ffmpeg:8.1 /ffprobe /usr/local/bin/
# Install system dependencies for sandbox runtime and agent
# Install system dependencies and Jellyfin-FFmpeg (with VA-API support)
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
make \
@@ -56,11 +52,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
poppler-utils \
imagemagick \
fonts-noto-cjk \
libraw-bin \
libimage-exiftool-perl \
&& . /etc/os-release \
&& TARGETARCH=$(dpkg --print-architecture) \
&& FFMPEG_VERSION="8.1.2-5" \
&& curl -fsSL -o /tmp/jellyfin-ffmpeg.deb "https://github.com/jellyfin/jellyfin-ffmpeg/releases/download/v${FFMPEG_VERSION}/jellyfin-ffmpeg8_${FFMPEG_VERSION}-${VERSION_CODENAME}_${TARGETARCH}.deb" \
&& apt-get install -y --no-install-recommends /tmp/jellyfin-ffmpeg.deb \
&& rm -f /tmp/jellyfin-ffmpeg.deb \
&& ldconfig /usr/lib/jellyfin-ffmpeg/lib \
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/local/bin/ffmpeg \
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffprobe /usr/local/bin/ffprobe \
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/bin/ffmpeg \
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffprobe /usr/bin/ffprobe \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Set up working directory and make it owned by the bun user
RUN mkdir -p /app/data && chown -R bun:bun /app
# Set up working directory and make it owned by the bun user, ensure video/render group access
RUN usermod -a -G video,render bun 2>/dev/null || true \
&& mkdir -p /app/data \
&& chown -R bun:bun /app
# Switch to the non-root bun user
USER bun
+10 -4
View File
@@ -33,6 +33,7 @@ Shumai is an open-source Frame.io alternative built for creative teams to collab
* **Custom Asset Metadata**: Define dynamic metadata fields tailored to your production pipeline.
* **Share Link Watermarking**: Protect shared media with customizable text and image watermarks, and save watermark as reusable templates.
* **Wide File Format Support**: Preview common creative file formats, including images (with PSD support), videos, audio, and documents, while allowing any file type to be uploaded and stored.
* **3D Asset Turntable Previews**: Generate interactive 3D model turntable previews and videos for formats like GLB, FBX, OBJ, STL, USD, and DAE using [turntable-renderer](https://docs.shumai.one/using-shumai/3d-asset-support).
* **Office & Document PDF Proxying via Gotenberg**: Convert Word, PowerPoint, Excel, Markdown, HTML, and CSV documents to high-quality PDF proxies for in-browser previewing using [Gotenberg](https://docs.shumai.one/using-shumai/gotenberg).
* **NLE Export & Premiere Pro Plugin (Experimental)**: Export timestamped review comments to your favorite non-linear editor (Premiere Pro XML, DaVinci Resolve EDL, Final Cut Pro, Avid Media Composer) or use the experimental Premiere Pro UXP plugin to import media assets and auto-sync comments directly to sequence timeline markers. See [documentation](https://docs.shumai.one/using-shumai/nle-and-premiere).
@@ -86,6 +87,9 @@ Docker Compose is the fastest way to get Shumai running. You do not need to clon
```bash
curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/docker-compose.yaml
```
> [!NOTE]
> By default, the standard `docker-compose.yaml` uses CPU software transcoding. If your server has a GPU (NVIDIA NVENC, Intel QuickSync, AMD/Intel VA-API, or Rockchip RKMPP) and you want to enable GPU hardware acceleration, check the [Hardware Transcoding Guide](https://docs.shumai.one/configuration/hardware-transcoding).
3. Configure environment variables (optional):
* `SHUMAI_SERVER_PORT` controls the port the Shumai server listens on. The default is `3000`.
@@ -159,23 +163,24 @@ Shumai requires the following system packages on Linux:
- **`ffmpeg`** – Used for media transcoding and metadata extraction.
- **`poppler`** (`poppler-utils`) – Used for PDF page image extraction and PDF sprite preview generation (`pdftoppm`).
- **`imagemagick`** – Used for PSD format transcoding and color profile conversion to sRGB.
- **`dcraw_emu`** (`libraw` / `libraw-bin`) – Used for camera RAW format image decoding and preview generation.
- **`bubblewrap`**, **`socat`**, and **`ripgrep`** – Required by the AI agent sandbox (`anthropic-experimental/sandbox-runtime`) for process isolation, networking, and workspace search.
Install all required packages with one command:
> Ubuntu/Debian
```bash
sudo apt install -y ffmpeg poppler-utils imagemagick bubblewrap socat ripgrep
sudo apt install -y ffmpeg poppler-utils imagemagick bubblewrap socat ripgrep libraw-bin
```
> Fedora
```bash
sudo dnf install -y ffmpeg poppler-utils ImageMagick bubblewrap socat ripgrep
sudo dnf install -y ffmpeg poppler-utils ImageMagick bubblewrap socat ripgrep LibRaw
```
> Arch Linux
```bash
sudo pacman -S --noconfirm ffmpeg poppler imagemagick bubblewrap socat ripgrep
sudo pacman -S --noconfirm ffmpeg poppler imagemagick bubblewrap socat ripgrep libraw
```
> [!NOTE]
@@ -198,12 +203,13 @@ Shumai requires:
- **`ffmpeg`** – Used for media transcoding and metadata extraction.
- **`poppler`** – Used for PDF page image extraction and PDF sprite preview generation (`pdftoppm`).
- **`imagemagick`** – Used for PSD format transcoding and color profile conversion to sRGB.
- **`dcraw_emu`** (`libraw`) – Used for camera RAW format image decoding and preview generation.
- **`ripgrep`** – Required by the AI agent sandbox (`anthropic-experimental/sandbox-runtime`).
Install the required packages with Homebrew:
```bash
brew install ffmpeg poppler imagemagick ripgrep
brew install ffmpeg poppler imagemagick ripgrep libraw
```
---
+11 -6
View File
@@ -33,6 +33,7 @@ Shumai 是一个开源的 Frame.io 替代方案,专为创意团队打造,让
* **自定义素材元数据**:可以按你的制作流程,自由定义动态元数据字段。
* **分享链接水印**:通过可自定义的文字和图片水印保护共享媒体,并将水印配置保存为模板以便重复使用。
* **丰富的文件格式支持**:支持预览常见创意文件格式,包括图片(支持 PSD)、视频、音频和文档,同时可上传和存储任意类型的文件。
* **基于转盘渲染服务的 3D 资产预览**:通过集成 [turntable-renderer](https://docs.shumai.one/using-shumai/3d-asset-support) 支持为 GLB、FBX、OBJ、STL、USD 和 DAE 等 3D 模型生成高质量的交互式转盘预览与视频。
* **基于 Gotenberg 的文档 PDF 转码代理**:通过集成 [Gotenberg](https://docs.shumai.one/using-shumai/gotenberg) 支持将 Word、PowerPoint、Excel、Markdown、HTML 和 CSV 文档高质量转换为 PDF 代理文件进行在线预览。
* **非编剪辑导出与 Premiere 插件(实验性)**:支持将时间戳审阅评论导出至常用非编软件(Premiere Pro XML、DaVinci Resolve EDL、Final Cut Pro、Avid Media Composer),或使用实验性的 Premiere Pro 原生 UXP 插件导入媒体素材并将评论自动同步为时间轴标记。详见[相关文档](https://docs.shumai.one/using-shumai/nle-and-premiere)。
@@ -101,9 +102,11 @@ https://gh-proxy.com/https://raw.githubusercontent.com/shumaiOne/shumai/main/REA
2. 下载 `docker-compose.yaml` 配置文件:
```bash
curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/docker-compose-aliyun.yaml
```
> [!NOTE]
> 默认的 Docker Compose 配置使用基于 CPU 的软件转码。如果您的服务器配备了支持的显卡(NVIDIA NVENC、Intel QuickSync、AMD/Intel VA-API 或 Rockchip RKMPP)并需要开启 GPU 硬件加速转码,请参考 [硬件加速转码配置文档](https://docs.shumai.one/configuration/hardware-transcoding)。
3. 配置环境变量(可选):
* `SHUMAI_SERVER_PORT` 用于控制 Shumai 服务监听的端口,默认值为 `3000`。
@@ -185,23 +188,24 @@ mkdir shumai && cd shumai
- **`ffmpeg`** —— 用于媒体转码和元数据提取。
- **`poppler`** (`poppler-utils`) —— 用于 PDF 页面图像提取和 PDF 雪碧图预览生成 (`pdftoppm`)。
- **`imagemagick`** —— 用于 PSD 格式图像转码和 sRGB 色彩空间转换。
- **`dcraw_emu`** (`libraw` / `libraw-bin`) —— 用于相机 RAW 格式图像解码和预览图生成。
- **`bubblewrap`**、**`socat`** 和 **`ripgrep`** —— AI Agent 沙箱(`anthropic-experimental/sandbox-runtime`)所需,用于进程隔离、网络通信和工作区搜索。
可以使用以下命令一次性安装所有依赖:
> Ubuntu/Debian
```bash
sudo apt install -y ffmpeg poppler-utils imagemagick bubblewrap socat ripgrep
sudo apt install -y ffmpeg poppler-utils imagemagick bubblewrap socat ripgrep libraw-bin
```
> Fedora
```bash
sudo dnf install -y ffmpeg poppler-utils ImageMagick bubblewrap socat ripgrep
sudo dnf install -y ffmpeg poppler-utils ImageMagick bubblewrap socat ripgrep LibRaw
```
> Arch Linux
```bash
sudo pacman -S --noconfirm ffmpeg poppler imagemagick bubblewrap socat ripgrep
sudo pacman -S --noconfirm ffmpeg poppler imagemagick bubblewrap socat ripgrep libraw
```
> [!NOTE]
@@ -213,7 +217,7 @@ sudo pacman -S --noconfirm ffmpeg poppler imagemagick bubblewrap socat ripgrep
> sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0
> ```
>
> 或者,配置 AppArmor Profile,为相关可执行文件授予所需的 `userns` 权限。
> 或者,配置 AppArmor Profile,为相关可执行文件授予所需的 `userns`权限。
---
@@ -224,12 +228,13 @@ sudo pacman -S --noconfirm ffmpeg poppler imagemagick bubblewrap socat ripgrep
- **`ffmpeg`** —— 用于媒体转码和元数据提取。
- **`poppler`** —— 用于 PDF 页面图像提取和 PDF 雪碧图预览生成 (`pdftoppm`)。
- **`imagemagick`** —— 用于 PSD 格式图像转码和 sRGB 色彩空间转换。
- **`dcraw_emu`** (`libraw`) —— 用于相机 RAW 格式图像解码和预览图生成。
- **`ripgrep`** —— AI Agent 沙箱(`anthropic-experimental/sandbox-runtime`)所需。
使用 Homebrew 安装所需依赖:
```bash
brew install ffmpeg poppler imagemagick ripgrep
brew install ffmpeg poppler imagemagick ripgrep libraw
```
---
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent-app",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/cli",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/premiere-uxp",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "commonjs",
"scripts": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/transcode-app",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"bin": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/web-app",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"dependencies": {
+2
View File
@@ -16,6 +16,7 @@ import { migrateLegacyAgentAvatars } from '@shumai/core/src/agent/migration'
import { handleDaemonCommands } from '@shumai/core/src/utils/daemon'
import { authService } from '@shumai/core/src/auth/auth'
import { sandboxService } from '@shumai/core'
import { notificationJobService } from '@shumai/core/src/notification/notification-job'
if (process.argv.includes('--check')) {
console.log('✅ Web app evaluated successfully!')
@@ -58,6 +59,7 @@ async function run() {
await metadataService.syncSystemFields().catch(console.error)
await migrateLegacyAgentAvatars().catch(console.error)
assetService.startCleanupJob()
notificationJobService.start()
workflowService.start()
if (process.env.WORKFLOW_EXECUTOR === 'temporal') {
const args = process.argv.slice(2)
+71 -50
View File
@@ -33,7 +33,7 @@
},
"apps/agent": {
"name": "@shumai/agent-app",
"version": "0.4.7",
"version": "0.5.2",
"bin": {
"shumai-agent": "./src/index.ts",
},
@@ -45,7 +45,7 @@
},
"apps/cli": {
"name": "@shumai/cli",
"version": "0.4.7",
"version": "0.5.2",
"bin": {
"shumai-cli": "./src/index.ts",
},
@@ -60,7 +60,7 @@
},
"apps/premiere-uxp": {
"name": "@shumai/premiere-uxp",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@shumai/api": "workspace:*",
"@shumai/dtos": "workspace:*",
@@ -114,7 +114,7 @@
},
"apps/transcode": {
"name": "@shumai/transcode-app",
"version": "0.4.7",
"version": "0.5.2",
"bin": {
"shumai-transcode": "./src/index.ts",
},
@@ -126,7 +126,7 @@
},
"apps/web": {
"name": "@shumai/web-app",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@shumai/agent": "workspace:*",
"@shumai/api": "workspace:*",
@@ -146,7 +146,7 @@
},
"packages/agent": {
"name": "@shumai/agent",
"version": "0.4.7",
"version": "0.5.2",
"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.7",
"version": "0.5.2",
"dependencies": {
"@hono/zod-validator": "0.7.6",
"@shumai/core": "workspace:*",
@@ -185,7 +185,7 @@
},
"packages/core": {
"name": "@shumai/core",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@ai-sdk/alibaba": "2.0.38",
"@ai-sdk/amazon-bedrock": "5.0.67",
@@ -214,6 +214,8 @@
"@shumai/db": "workspace:*",
"@shumai/dtos": "workspace:*",
"@sinclair/typebox": "0.34.52",
"@temporalio/activity": "1.24.0",
"@temporalio/workflow": "1.24.0",
"adm-zip": "0.6.0",
"ai": "7.0.84",
"better-auth": "1.6.11",
@@ -221,9 +223,11 @@
"date-fns": "4.4.0",
"dotenv": "17.4.2",
"dotenv-expand": "13.0.0",
"exiftool-vendored": "38.1.0",
"extract-zip": "2.0.1",
"hono": "4.13.5",
"jittered-fractional-indexing": "1.0.1",
"nodemailer": "10.0.10",
"pdfkit": "0.20.1",
"pino": "10.3.1",
"sharp": "0.35.4",
@@ -237,12 +241,13 @@
"@modelcontextprotocol/server": "2.0.0",
"@types/adm-zip": "0.5.8",
"@types/extract-zip": "2.0.3",
"@types/nodemailer": "8.0.2",
"@types/pdfkit": "0.17.6",
},
},
"packages/db": {
"name": "@shumai/db",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"@prisma/adapter-pg": "7.10.0",
@@ -258,7 +263,7 @@
},
"packages/dtos": {
"name": "@shumai/dtos",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"zod": "4.5.4",
@@ -266,7 +271,7 @@
},
"packages/e2e": {
"name": "@shumai/e2e",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@earendil-works/pi-agent-core": "0.82.1",
"@google/genai": "2.19.0",
@@ -281,11 +286,11 @@
},
"packages/tableprinter": {
"name": "@shumai/tableprinter",
"version": "0.4.7",
"version": "0.5.2",
},
"packages/transcode": {
"name": "@shumai/transcode",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -299,7 +304,7 @@
},
"packages/webui": {
"name": "@shumai/webui",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@base-ui/react": "1.7.0",
"@dnd-kit/abstract": "0.5.0",
@@ -359,6 +364,7 @@
"cmdk": "1.1.1",
"date-fns": "4.4.0",
"embla-carousel-react": "8.6.0",
"hls.js": "1.7.3",
"hono": "4.13.5",
"input-otp": "1.5.0",
"konva": "10.3.2",
@@ -382,7 +388,6 @@
"ulid": "3.0.2",
"use-image": "1.1.4",
"vaul": "1.1.2",
"video.js": "8.24.0",
"zod": "4.5.4",
"zustand": "5.0.15",
},
@@ -401,7 +406,7 @@
},
"packages/workflow-core": {
"name": "@shumai/workflow-core",
"version": "0.4.7",
"version": "0.5.2",
"dependencies": {
"@shumai/core": "workspace:*",
"@shumai/db": "workspace:*",
@@ -907,6 +912,8 @@
"@oxc-project/types": ["@oxc-project/types@0.147.0", "", {}, "sha512-IJ3s6ltHLp45S0bh7phkX+gJO7A1Wuz2EaqpAhb8WjqDwbzMiWKHhyyT42tskaWjEYXtHtVCPpnBJVT9+dcRLg=="],
"@photostructure/tz-lookup": ["@photostructure/tz-lookup@11.7.0", "", {}, "sha512-QbKHXvleluMIlAHf2JiQTJNU5rLQBeQhLobyRqgXZ6NNGKqNikaRkjYviJ4nMU7Y75QE7bBYM8xjiFGjAukyhw=="],
"@pinojs/redact": ["@pinojs/redact@0.4.0", "", {}, "sha512-k2ENnmBugE/rzQfEcdWHcCY+/FM3VLzH9cYEsbdsoqrvzAKRhUZeRNhAZvB8OitQJ1TBed3yqWtdjzS6wJKBwg=="],
"@pkgjs/parseargs": ["@pkgjs/parseargs@0.11.0", "", {}, "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg=="],
@@ -1557,12 +1564,16 @@
"@types/lodash": ["@types/lodash@4.17.25", "", {}, "sha512-+K1NIO8I+F9/wNulfVvu23QYd0Pe9/OCqRrim4NoYIf1VoEDL90Ve4ClzpyqBLc7NpGGWRvYNCKZ1BE/Jpf8dQ=="],
"@types/luxon": ["@types/luxon@3.7.5", "", {}, "sha512-jJ41Q4z6ZVO260MNDdHfW7+7a5iMiX8Mr6ZJHcmgrvhZha6dz5704o/lF2kKl6URjH6ivEL97w9xS/MgpJEphg=="],
"@types/mdast": ["@types/mdast@4.0.4", "", { "dependencies": { "@types/unist": "*" } }, "sha512-kGaNbPh1k7AFzgpud/gMdvIm5xuECykRR+JnWKQno9TAXVa6WIVCGTPvYGekIDL4uwCZQSYbUxNBSb1aUo79oA=="],
"@types/ms": ["@types/ms@2.1.0", "", {}, "sha512-GsCCIZDE/p3i96vtEqx+7dBUGXrc7zeSK3wwPHIaRThS+9OhWIXRqzs4d6k1SVU8g91DrNRWxWUGhp5KXQb2VA=="],
"@types/node": ["@types/node@25.9.1", "", { "dependencies": { "undici-types": ">=7.24.0 <7.24.7" } }, "sha512-xfrlY7UD5rMJk3ZVJP8BNzS28J36YJg+xp+LPXV1TdWxr8uMH5A860QNxYDGQe/ylDSgjxE52Q9VnO7p75tJxg=="],
"@types/nodemailer": ["@types/nodemailer@8.0.2", "", { "dependencies": { "@types/node": "*" } }, "sha512-c7M5ox8p0nEOfbJ2E9Qcmt8/QCu/VzsiAhzBiZbvky2PhKZDHpKB3sQHBM5MEZNkCfBOaS6S9//AGPRTNB7IaA=="],
"@types/pdfkit": ["@types/pdfkit@0.17.6", "", { "dependencies": { "@types/node": "*" } }, "sha512-tIwzxk2uWKp0Cq9JIluQXJid77lYhF52EsIOwhsMF4iWLA6YneoBR1xVKYYdAysHuepUB0OX4tdwMiUDdGKmig=="],
"@types/pg": ["@types/pg@8.23.1", "", { "dependencies": { "@types/node": "*", "pg-protocol": "*", "pg-types": "^2.2.0" } }, "sha512-fKVHpikPdg4GKks3JuLEhvwSyvwzF23hnabPy6DD8ljVbC7+6J5dQzdv4arV6jqq57djnMgs1HKBxX4P8aBI3A=="],
@@ -1621,12 +1632,6 @@
"@vercel/oidc": ["@vercel/oidc@3.2.0", "", {}, "sha512-UycprH3T6n3jH0k44NHMa7pnFHGu/N05MjojYr+Mc6I7obkoLIJujSWwin1pCvdy/eOxrI/l3uDLQsmcrOb4ug=="],
"@videojs/http-streaming": ["@videojs/http-streaming@3.17.5", "", { "dependencies": { "@babel/runtime": "^7.12.5", "@videojs/vhs-utils": "^4.1.2", "aes-decrypter": "^4.0.2", "global": "^4.4.0", "m3u8-parser": "^7.2.0", "mpd-parser": "^1.4.0", "mux.js": "7.1.0", "video.js": "^7 || ^8" } }, "sha512-PRRQVu0hYW5h0XvRWpIyIpEatpMZzZtf7L1avV89Hnu+69f+0c7oLsSL9jwpg2nbvzGkdX5rQxQkz5Vc7tFR9w=="],
"@videojs/vhs-utils": ["@videojs/vhs-utils@4.1.2", "", { "dependencies": { "@babel/runtime": "^7.12.5", "global": "^4.4.0" } }, "sha512-1Dsv5dtWOq0LP1G37O46FQFA2tKAZON5UMe6dFPxT7JvPhEx8QIXcFQxan8+hHI3fX6aomFRFrUBJNgRYQDSXA=="],
"@videojs/xhr": ["@videojs/xhr@2.7.0", "", { "dependencies": { "@babel/runtime": "^7.5.5", "global": "~4.4.0", "is-function": "^1.0.1" } }, "sha512-giab+EVRanChIupZK7gXjHy90y3nncA2phIOyG3Ne5fvpiMJzvqYwiTOnEVW2S4CoYcuKJkomat7bMXA/UoUZQ=="],
"@visx/curve": ["@visx/curve@4.0.1-alpha.0", "", { "dependencies": { "@visx/vendor": "4.0.0-alpha.0" } }, "sha512-jRu61Uz274pV1zyioXmboyrLutYbnKsgjj4njSGCnhdXj5GkZvZbg+ThDb6oOzoAnJOBRLz4rzPlWvNJOzuVMg=="],
"@visx/event": ["@visx/event@4.0.1-alpha.0", "", { "dependencies": { "@types/react": "*", "@visx/point": "4.0.1-alpha.0" } }, "sha512-EQqCMSv/s8NbFjo+hz3FKsvvYfP+2QslsFJ/24/O5l/W+7UC6J6aAvO0ujVwrTwdYbuQ+vhxKi1xdPdKR/qj1g=="],
@@ -1691,8 +1696,6 @@
"@workflow/serde": ["@workflow/serde@4.1.0", "", {}, "sha512-pav4F2BoirECWR7Nf1TKt+2eETcBj7jj4cBefQ8VXQCA6NPkaKeLfj/zMgi+3zYV5ZIBT4GuUiphsj0/b9hPQQ=="],
"@xmldom/xmldom": ["@xmldom/xmldom@0.8.15", "", {}, "sha512-/5NV/vDALVFDXgLmfsy9TRCBlKwO2LNBFzpzvb9iIj+jR+eSc6DLYYvVOdivT/jm7MtU6TebYuRmzEOI7w40UA=="],
"@xtuc/ieee754": ["@xtuc/ieee754@1.2.0", "", {}, "sha512-DX8nKgqcGwsc0eJSqYt5lwP4DH5FlHnmuWWBRy7X0NcaGR0ZtuyeESgMwTYVEtxmsNGY+qit4QYT/MIYTOTPeA=="],
"@xtuc/long": ["@xtuc/long@4.2.2", "", {}, "sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ=="],
@@ -1705,8 +1708,6 @@
"adm-zip": ["adm-zip@0.6.0", "", {}, "sha512-XleryMhbuksdKtofnWZ9Sk+4CUTbms4Mb/EU32SZwToAyZ5RgVos/ki8n+yr0LWHOGKuakbXTuuYNHLQjhddgg=="],
"aes-decrypter": ["aes-decrypter@4.0.2", "", { "dependencies": { "@babel/runtime": "^7.12.5", "@videojs/vhs-utils": "^4.1.1", "global": "^4.4.0", "pkcs7": "^1.0.4" } }, "sha512-lc+/9s6iJvuaRe5qDlMTpCFjnwpkeOXp8qP3oiZ5jsj1MRg+SBVUmmICrhxHvc8OELSmc+fEyyxAuppY6hrWzw=="],
"agent-base": ["agent-base@7.1.4", "", {}, "sha512-MnA+YT8fwfJPgBx3m60MNqakm30XOkyIoH1y6huTQvC0PwZG7ki8NacLBcrPbNoo8vEZy7Jpuk7+jMO+CUovTQ=="],
"ai": ["ai@7.0.84", "", { "dependencies": { "@ai-sdk/gateway": "4.0.68", "@ai-sdk/provider": "4.0.8", "@ai-sdk/provider-utils": "5.0.33" }, "peerDependencies": { "zod": "^3.25.76 || ^4.1.8" } }, "sha512-znHNBWADOy79k8EK7636kDm5LmnjF4tMzegC2TfmlLDobDZbs0z0OXD2sxtH3eDTp5Re+pJQESvjinWJ6+kadQ=="],
@@ -1789,6 +1790,8 @@
"baseline-browser-mapping": ["baseline-browser-mapping@2.11.20", "", { "bin": { "baseline-browser-mapping": "dist/cli.cjs" } }, "sha512-H0ulySigv6icDJ1F7SjtdCD6PrhTpdYCmP0CactWy1+ekh0AFd0o1Wn5T8b+hnTmdBx19u9yhL6wvCylXMY7zw=="],
"batch-cluster": ["batch-cluster@19.2.0", "", {}, "sha512-mvozaN/7TYxl+lmXDYH+HocCcRMvW25QmghrJux2y93o+NhHPQ4wir0nBS1p8oTlinjc/l5LaNX+VFxNISrqgQ=="],
"bcrypt-pbkdf": ["bcrypt-pbkdf@1.0.2", "", { "dependencies": { "tweetnacl": "^0.14.3" } }, "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w=="],
"better-auth": ["better-auth@1.6.11", "", { "dependencies": { "@better-auth/core": "1.6.11", "@better-auth/drizzle-adapter": "1.6.11", "@better-auth/kysely-adapter": "1.6.11", "@better-auth/memory-adapter": "1.6.11", "@better-auth/mongo-adapter": "1.6.11", "@better-auth/prisma-adapter": "1.6.11", "@better-auth/telemetry": "1.6.11", "@better-auth/utils": "0.4.0", "@better-fetch/fetch": "1.1.21", "@noble/ciphers": "^2.1.1", "@noble/hashes": "^2.0.1", "better-call": "1.3.5", "defu": "^6.1.4", "jose": "^6.1.3", "kysely": "^0.28.17", "nanostores": "^1.1.1", "zod": "^4.3.6" }, "peerDependencies": { "@lynx-js/react": "*", "@prisma/client": "^5.0.0 || ^6.0.0 || ^7.0.0", "@sveltejs/kit": "^2.0.0", "@tanstack/react-start": "^1.0.0", "@tanstack/solid-start": "^1.0.0", "better-sqlite3": "^12.0.0", "drizzle-kit": ">=0.31.4", "drizzle-orm": "^0.45.2", "mongodb": "^6.0.0 || ^7.0.0", "mysql2": "^3.0.0", "next": "^14.0.0 || ^15.0.0 || ^16.0.0", "pg": "^8.0.0", "prisma": "^5.0.0 || ^6.0.0 || ^7.0.0", "react": "^18.0.0 || ^19.0.0", "react-dom": "^18.0.0 || ^19.0.0", "solid-js": "^1.0.0", "svelte": "^4.0.0 || ^5.0.0", "vitest": "^2.0.0 || ^3.0.0 || ^4.0.0", "vue": "^3.0.0" }, "optionalPeers": ["@lynx-js/react", "@prisma/client", "@sveltejs/kit", "@tanstack/react-start", "@tanstack/solid-start", "better-sqlite3", "drizzle-kit", "drizzle-orm", "mongodb", "mysql2", "next", "pg", "prisma", "react", "react-dom", "solid-js", "svelte", "vitest", "vue"] }, "sha512-Wwt6+q07dwIhsp6XiM7L1qSXVUWBEtNl+eZvwM778CguFqDZFBN9Pt6LtFaHl55t8Z+Zc//5kxcbgDY8/79vFQ=="],
@@ -1995,8 +1998,6 @@
"dom-accessibility-api": ["dom-accessibility-api@0.5.16", "", {}, "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg=="],
"dom-walk": ["dom-walk@0.1.2", "", {}, "sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w=="],
"dotenv": ["dotenv@17.4.2", "", {}, "sha512-nI4U3TottKAcAD9LLud4Cb7b2QztQMUEfHbvhTH09bqXTxnSie8WnjPALV/WMCrJZ6UV/qHJ6L03OqO3LcdYZw=="],
"dotenv-expand": ["dotenv-expand@13.0.0", "", { "dependencies": { "dotenv": "^17.4.2" } }, "sha512-aBfBS8eYIeXmpHI9ThIlA7/WLq+SLt18iXUZhb52rW89QLKQFoIpPG1bPeewoPZsTyjSSO3T7234FBVUM1V2rA=="],
@@ -2099,6 +2100,12 @@
"eventsource-parser": ["eventsource-parser@3.1.1", "", {}, "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ=="],
"exiftool-vendored": ["exiftool-vendored@38.1.0", "", { "dependencies": { "@photostructure/tz-lookup": "^11.7.0", "@types/luxon": "^3.7.5", "batch-cluster": "^19.2.0", "he": "^1.2.0", "luxon": "^3.7.2" }, "optionalDependencies": { "exiftool-vendored.exe": "13.59.2", "exiftool-vendored.pl": "13.59.2" } }, "sha512-LIERqM/Qb0oqJlSswLFKWsxGVH81skp7omsX2BPKA/dEzfLP5syNO5KL7k5UlMCf+m0jqEXrKTQr/xV5vScPow=="],
"exiftool-vendored.exe": ["exiftool-vendored.exe@13.59.2", "", { "os": "win32" }, "sha512-U0l0CApIGO+AjpFYCiNCApQsMdlf6sqCyEl4wlKKqvwVAEVcvMRw91k7zj32OPFZE+/+XlLFsc6876MpOqBLiw=="],
"exiftool-vendored.pl": ["exiftool-vendored.pl@13.59.2", "", { "os": "!win32", "bin": { "exiftool": "bin/exiftool" } }, "sha512-5B80JT9phZSUsc7zz77rQ6DfW0YssTpJ5qW/1bOH1N8XQq/jcn+9eRW9HFwhVT9uoIliw9Fg007ST3pUzQIzyw=="],
"expect-type": ["expect-type@1.4.0", "", {}, "sha512-KfYbmpRm0VbLjEvVa9yGwCi9GI34xvi7A/HXYWQO65CSD2u3MczUJSuwXKFIxlGsgBQizV9q5J9NHj4VG0n+pA=="],
"exsolve": ["exsolve@1.1.1", "", {}, "sha512-9U/jZUgjnSGyntRr6y5Muu1MJcwFl6kPu7k8qLF0IMNfLqvw0NZ4nnVDq0RVoZ0RvCyumib4Ez3KYrVfilrw+g=="],
@@ -2207,8 +2214,6 @@
"glob-to-regex.js": ["glob-to-regex.js@1.2.0", "", { "peerDependencies": { "tslib": "2" } }, "sha512-QMwlOQKU/IzqMUOAZWubUOT8Qft+Y0KQWnX9nK3ch0CJg0tTp4TvGZsTfudYKv2NzoQSyPcnA6TYeIQ3jGichQ=="],
"global": ["global@4.4.0", "", { "dependencies": { "min-document": "^2.19.0", "process": "^0.11.10" } }, "sha512-wv/LAoHdRE3BeTGz53FAamhGlPLhlssK45usmGFThIi4XqnBmjKQ16u+RNbP7WvigRZDxUsM0J3gcQ5yicaL0w=="],
"globals": ["globals@17.11.0", "", {}, "sha512-Z2I8hM+PbJDXQDq3Icgpzv+mPdwr68iZUU9d5WW4FuXfDUQfkZaZuvjMv42/5crNyw154+9+VWXbYrUgDXbxNw=="],
"globalthis": ["globalthis@1.0.4", "", { "dependencies": { "define-properties": "^1.2.1", "gopd": "^1.0.1" } }, "sha512-DpLKbNU4WylpxJykQujfCcwYWiV/Jhm50Goo0wrVILAv5jOr9d+H+UR3PhSCD2rCCEIg0uc+G+muBTwD54JhDQ=="],
@@ -2247,10 +2252,14 @@
"hast-util-whitespace": ["hast-util-whitespace@3.0.0", "", { "dependencies": { "@types/hast": "^3.0.0" } }, "sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw=="],
"he": ["he@1.2.0", "", { "bin": { "he": "bin/he" } }, "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw=="],
"heap-js": ["heap-js@2.7.1", "", {}, "sha512-EQfezRg0NCZGNlhlDR3Evrw1FVL2G3LhU7EgPoxufQKruNBSYA8MiRPHeWbU+36o+Fhel0wMwM+sLEiBAlNLJA=="],
"help-me": ["help-me@5.0.0", "", {}, "sha512-7xgomUX6ADmcYzFik0HzAxh/73YlKR9bmFzf51CZwR+b6YtzU2m0u49hQCqV6SvlqIqsaxovfwdvbnsw3b/zpg=="],
"hls.js": ["hls.js@1.7.3", "", {}, "sha512-MsPlx6yVW4Qv4C7mEVou4/gk/5cN2dVxOTnrNjPSmyH2f0Ln+/UkG10Ax1PE6OvrmTVPKgQYozTtBaPOuCzq7A=="],
"hono": ["hono@4.13.5", "", {}, "sha512-O6+/eCYRkzzzy0rPWwKLiGBR1nFuUPZynnwjxN1MBA62NNqbT0wQEzQyK2gSO5yDIDB336sXQleAhOHrzlYyKw=="],
"html-url-attributes": ["html-url-attributes@3.0.1", "", {}, "sha512-ol6UPyBWqsrO6EJySPz2O7ZSr856WDrEzM5zMqp+FJJLGMW35cLYmmZnl0vztAZxRUoNZJFTCohfjuIJ8I4QBQ=="],
@@ -2311,8 +2320,6 @@
"is-fullwidth-code-point": ["is-fullwidth-code-point@3.0.0", "", {}, "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="],
"is-function": ["is-function@1.0.2", "", {}, "sha512-lw7DUp0aWXYg+CBCN+JKkcE0Q2RayZnSvnZBlwgxHBQhqt5pZNVy4Ri7H9GmmXkdu7LUthszM+Tor1u/2iBcpQ=="],
"is-generator-function": ["is-generator-function@1.1.2", "", { "dependencies": { "call-bound": "^1.0.4", "generator-function": "^2.0.0", "get-proto": "^1.0.1", "has-tostringtag": "^1.0.2", "safe-regex-test": "^1.1.0" } }, "sha512-upqt1SkGkODW9tsGNG5mtXTXtECizwtS2kA161M+gJPc1xdb/Ax629af6YrTwcOeQHbewrPNlE5Dx7kzvXTizA=="],
"is-glob": ["is-glob@4.0.3", "", { "dependencies": { "is-extglob": "^2.1.1" } }, "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg=="],
@@ -2465,9 +2472,9 @@
"lucide-react": ["lucide-react@1.37.0", "", { "peerDependencies": { "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0" } }, "sha512-LPsB4rD1TD6wZu1djKOf9vUnS1jTNaHbolXebXDgiTdb6jeA1agIJhJsIybCmjKmQClcOaal1o1OaiYahEftyQ=="],
"lz-string": ["lz-string@1.5.0", "", { "bin": { "lz-string": "bin/bin.js" } }, "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ=="],
"luxon": ["luxon@3.7.2", "", {}, "sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew=="],
"m3u8-parser": ["m3u8-parser@7.2.0", "", { "dependencies": { "@babel/runtime": "^7.12.5", "@videojs/vhs-utils": "^4.1.1", "global": "^4.4.0" } }, "sha512-CRatFqpjVtMiMaKXxNvuI3I++vUumIXVVT/JpCpdU/FynV/ceVw1qpPyyBNindL+JlPMSesx+WX1QJaZEJSaMQ=="],
"lz-string": ["lz-string@1.5.0", "", { "bin": { "lz-string": "bin/bin.js" } }, "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ=="],
"magic-string": ["magic-string@0.30.21", "", { "dependencies": { "@jridgewell/sourcemap-codec": "^1.5.5" } }, "sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ=="],
@@ -2539,8 +2546,6 @@
"mime-match": ["mime-match@1.0.2", "", { "dependencies": { "wildcard": "^1.1.0" } }, "sha512-VXp/ugGDVh3eCLOBCiHZMYWQaTNUHv2IJrut+yXA6+JbLPXHglHwfS/5A5L0ll+jkCY7fIzRJcH6OIunF+c6Cg=="],
"min-document": ["min-document@2.19.2", "", { "dependencies": { "dom-walk": "^0.1.0" } }, "sha512-8S5I8db/uZN8r9HSLFVWPdJCvYOejMcEC82VIzNUc6Zkklf/d1gg2psfE79/vyhWOj4+J8MtwmoOz3TmvaGu5A=="],
"minimatch": ["minimatch@10.2.6", "", { "dependencies": { "brace-expansion": "^5.0.8" } }, "sha512-vpLQEs+VLCr1nU0BXS07maYoFwlDAH0gngQuuttxIwutDFEMHq2blX+8vpgxDdK3J1PwjCJiep77OitTZ4Ll1A=="],
"minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="],
@@ -2553,12 +2558,8 @@
"mkdirp-classic": ["mkdirp-classic@0.5.3", "", {}, "sha512-gKLcREMhtuZRwRAfqP3RFW+TK4JqApVBtOIftVgjuABpAtpxhPGaDcfvbhNvD0B8iD1oUr/txX35NjcaY6Ns/A=="],
"mpd-parser": ["mpd-parser@1.4.0", "", { "dependencies": { "@babel/runtime": "^7.12.5", "@videojs/vhs-utils": "^4.1.2", "@xmldom/xmldom": "^0.8.3", "global": "^4.4.0" }, "bin": { "mpd-to-m3u8-json": "bin/parse.js" } }, "sha512-blbA7XpAaOdC/PR0Tu8GiUxlx6CpBuRowQPYV7lhi9Yr9G9+dkPXIUjqjzc/NCn/uZZPopluaJlIYntIEI/VLw=="],
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
"mux.js": ["mux.js@7.1.0", "", { "dependencies": { "@babel/runtime": "^7.11.2", "global": "^4.4.0" }, "bin": { "muxjs-transmux": "bin/transmux.js" } }, "sha512-NTxawK/BBELJrYsZThEulyUMDVlLizKdxyAsMuzoCD1eFj97BVaA8D/CvKsKu6FOLYkFojN5CbM9h++ZTZtknA=="],
"mysql2": ["mysql2@3.15.3", "", { "dependencies": { "aws-ssl-profiles": "^1.1.1", "denque": "^2.1.0", "generate-function": "^2.3.1", "iconv-lite": "^0.7.0", "long": "^5.2.1", "lru.min": "^1.0.0", "named-placeholders": "^1.1.3", "seq-queue": "^0.0.5", "sqlstring": "^2.3.2" } }, "sha512-FBrGau0IXmuqg4haEZRBfHNWB5mUARw6hNwPDXXGg0XzVJ50mr/9hb267lvpVMnhZ1FON3qNd4Xfcez1rbFwSg=="],
"named-placeholders": ["named-placeholders@1.1.6", "", { "dependencies": { "lru.min": "^1.1.0" } }, "sha512-Tz09sEL2EEuv5fFowm419c1+a/jSMiBjI9gHxVLrVdbUkkNUUfjsVYs9pVZu5oCon/kmRh9TfLEObFtkVxmY0w=="],
@@ -2591,6 +2592,8 @@
"node-releases": ["node-releases@2.0.54", "", {}, "sha512-YHs7BmmcsdAI5Ozuf8JZo6PT0mv2GIWC9vMfvUC3dp65M8hn7Ux8CPL+2oBI7juNuj9d0ndhTcznq2ODBps9cQ=="],
"nodemailer": ["nodemailer@10.0.10", "", {}, "sha512-He9XskOFms62SyAKkLu8CcGcYHAo+BSHSsORI8s4PJH8qZgZY4L4lDfvyN0twvmbpyG+eGrxpyBlskj9d9rJ8A=="],
"normalize-path": ["normalize-path@3.0.0", "", {}, "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA=="],
"object-assign": ["object-assign@4.1.1", "", {}, "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="],
@@ -2687,8 +2690,6 @@
"pkce-challenge": ["pkce-challenge@5.0.1", "", {}, "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ=="],
"pkcs7": ["pkcs7@1.0.4", "", { "dependencies": { "@babel/runtime": "^7.5.5" }, "bin": { "pkcs7": "bin/cli.js" } }, "sha512-afRERtHn54AlwaF2/+LFszyAANTCggGilmcmILUzEjvs3XgFZT+xE6+QWQcAGmu4xajy+Xtj7acLOPdx5/eXWQ=="],
"pkg-types": ["pkg-types@2.3.1", "", { "dependencies": { "confbox": "^0.2.4", "exsolve": "^1.0.8", "pathe": "^2.0.3" } }, "sha512-y+ichcgc2LrADuhLNAx8DFjVfgz91pRxfZdI3UDhxHvcVEZsenLO+7XaU5vOp0u/7V/wZ+plyuQxtrDlZJ+yeg=="],
"playwright": ["playwright@1.61.1", "", { "dependencies": { "playwright-core": "1.61.1" }, "optionalDependencies": { "fsevents": "2.3.2" }, "bin": { "playwright": "cli.js" } }, "sha512-DWnY5o3YbLWK4GovuAVwpqL+1VwGNdUGrRr++8j8PtQQzvAVZUIMjKQ90fY689sEJZJBbZVw1rXaOKSTitkzPQ=="],
@@ -3093,14 +3094,6 @@
"victory-vendor": ["victory-vendor@37.3.6", "", { "dependencies": { "@types/d3-array": "^3.0.3", "@types/d3-ease": "^3.0.0", "@types/d3-interpolate": "^3.0.1", "@types/d3-scale": "^4.0.2", "@types/d3-shape": "^3.1.0", "@types/d3-time": "^3.0.0", "@types/d3-timer": "^3.0.0", "d3-array": "^3.1.6", "d3-ease": "^3.0.1", "d3-interpolate": "^3.0.1", "d3-scale": "^4.0.2", "d3-shape": "^3.1.0", "d3-time": "^3.0.0", "d3-timer": "^3.0.1" } }, "sha512-SbPDPdDBYp+5MJHhBCAyI7wKM3d5ivekigc2Dk2s7pgbZ9wIgIBYGVw4zGHBml/qTFbexrofXW6Gu4noGxrOwQ=="],
"video.js": ["video.js@8.24.0", "", { "dependencies": { "@babel/runtime": "^7.28.4", "@videojs/http-streaming": "^3.17.5", "@videojs/vhs-utils": "^4.1.2", "@videojs/xhr": "2.7.0", "aes-decrypter": "^4.0.2", "global": "4.4.0", "m3u8-parser": "^7.2.0", "mpd-parser": "^1.4.0", "mux.js": "^7.0.1", "videojs-contrib-quality-levels": "4.1.0", "videojs-font": "4.2.0", "videojs-vtt.js": "0.15.5" } }, "sha512-ZUuxTlDRkEWhpp2mvGCSFzI0Tc3zcC6IUZbIhBcZ3QW0Ms+IRp/tzYkhqexcMYwrcukRFiWWJmRANsLKvv8Vsg=="],
"videojs-contrib-quality-levels": ["videojs-contrib-quality-levels@4.1.0", "", { "dependencies": { "global": "^4.4.0" }, "peerDependencies": { "video.js": "^8" } }, "sha512-TfrXJJg1Bv4t6TOCMEVMwF/CoS8iENYsWNKip8zfhB5kTcegiFYezEA0eHAJPU64ZC8NQbxQgOwAsYU8VXbOWA=="],
"videojs-font": ["videojs-font@4.2.0", "", {}, "sha512-YPq+wiKoGy2/M7ccjmlvwi58z2xsykkkfNMyIg4xb7EZQQNwB71hcSsB3o75CqQV7/y5lXkXhI/rsGAS7jfEmQ=="],
"videojs-vtt.js": ["videojs-vtt.js@0.15.5", "", { "dependencies": { "global": "^4.3.1" } }, "sha512-yZbBxvA7QMYn15Lr/ZfhhLPrNpI/RmCSCqgIff57GC2gIrV5YfyzLfLyZMj0NnZSAz8syB4N0nHXpZg9MyrMOQ=="],
"vite": ["vite@8.2.2", "", { "dependencies": { "lightningcss": "^1.33.0", "picomatch": "^4.0.5", "postcss": "^8.5.26", "rolldown": "~1.2.4", "tinyglobby": "^0.2.17" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "@vitejs/devtools": "^0.4.0 || ^0.5.0", "esbuild": "^0.27.0 || ^0.28.0", "jiti": ">=1.21.0", "less": "^4.0.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "@vitejs/devtools", "esbuild", "jiti", "less", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-cFKLV/PRgAUlIRm5WjMjJ86jrftzpqcgH+Us+DS8mI3CDNiH30Whrz8uHL3+MOLPAgqbMBAqWdAHAphOAM+z/Q=="],
"vite-tsconfig-paths": ["vite-tsconfig-paths@6.1.1", "", { "dependencies": { "debug": "^4.1.1", "globrex": "^0.1.2", "tsconfck": "^3.0.3" }, "peerDependencies": { "vite": "*" } }, "sha512-2cihq7zliibCCZ8P9cKJrQBkfgdvcFkOOc3Y02o3GWUDLgqjWsZudaoiuOwO/gzTzy17cS5F7ZPo4bsnS4DGkg=="],
@@ -3239,6 +3232,10 @@
"@reduxjs/toolkit/reselect": ["reselect@5.3.0", "", {}, "sha512-XGoLeRAVzUTcJ1qkxPQhDJyIZ5d6zzZD9nT7AEZOaaU9UbWclhycElmhO+VD5bFeLuzhPBaOV2oXC8uG35ZSpg=="],
"@shumai/core/@temporalio/activity": ["@temporalio/activity@1.24.0", "", { "dependencies": { "@temporalio/client": "1.24.0", "@temporalio/common": "1.24.0" } }, "sha512-eBBho/r9XHe2KczYGzmaSp6e9+6c9ta/GGOBldIBr00D/cV34kJ76iAY3Ue1pQTaP7YaX3phMuOz07uUg/IKyA=="],
"@shumai/core/@temporalio/workflow": ["@temporalio/workflow@1.24.0", "", { "dependencies": { "@temporalio/common": "1.24.0", "@temporalio/proto": "1.24.0", "nexus-rpc": "^0.0.3" } }, "sha512-pIA9nxkDCCbBnNuMSffQ44HWHYe3zXFfrDpDLwzh/FUSx8uLbsBM8jwf5oUMf+5eV/qVW9PknZhOu9IFO4XnPA=="],
"@shumai/webui/@types/react-dom": ["@types/react-dom@19.2.5", "", { "peerDependencies": { "@types/react": "^19.2.0" } }, "sha512-fMPwH9v7r/pp43yUd2/Mbiex5KouJwwR3dzHkhLREUC6764VyDsqxhAxv6OFEYR1RhjOyD1naqba8ECDBe7ZQg=="],
"@spectrum-web-components/action-button/@spectrum-web-components/icon": ["@spectrum-web-components/icon@0.37.0", "", { "dependencies": { "@spectrum-web-components/base": "^0.37.0", "@spectrum-web-components/iconset": "^0.37.0" } }, "sha512-DZ1yOKHxNQygzIJ7u9akYComDnMmxuTzfmYxxt9sHdUXmc1NbMkCJqEaAG/LYsdb+hc4xWaDTT9SzArLKZ/btA=="],
@@ -3489,6 +3486,14 @@
"@prisma/studio-core/@radix-ui/react-toggle/@radix-ui/react-use-controllable-state": ["@radix-ui/react-use-controllable-state@1.2.2", "", { "dependencies": { "@radix-ui/react-use-effect-event": "0.0.2", "@radix-ui/react-use-layout-effect": "1.1.1" }, "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-BjasUjixPFdS+NKkypcyyN5Pmg83Olst0+c6vGov0diwTEo6mgdqVR6hxcEgFuh4QrAs7Rc+9KuGJ9TVCj0Zzg=="],
"@shumai/core/@temporalio/activity/@temporalio/client": ["@temporalio/client@1.24.0", "", { "dependencies": { "@grpc/grpc-js": "^1.12.4", "@temporalio/common": "1.24.0", "@temporalio/proto": "1.24.0", "abort-controller": "^3.0.0", "long": "^5.3.2", "nexus-rpc": "^0.0.3", "uuid": "^11.1.0" } }, "sha512-/GGg6ZYl+pN/bQEvq414CyjDvyM+MM1WsMzi/7SCYb3UlivVXx9nOmH/6BGx8OfYFayp11fkmfSh6rt7vW/ePQ=="],
"@shumai/core/@temporalio/activity/@temporalio/common": ["@temporalio/common@1.24.0", "", { "dependencies": { "@temporalio/proto": "1.24.0", "long": "^5.3.2", "ms": "3.0.0-canary.1", "nexus-rpc": "^0.0.3", "protobufjs": "^8.7.1" } }, "sha512-jXp77fXwynBcVNc/CaGMT33TVYnhcN26S959HDv7Q71oc0rN6d8RHWR5z0nRCDAu5CQwZQRRhVK0TRdyAiEg7Q=="],
"@shumai/core/@temporalio/workflow/@temporalio/common": ["@temporalio/common@1.24.0", "", { "dependencies": { "@temporalio/proto": "1.24.0", "long": "^5.3.2", "ms": "3.0.0-canary.1", "nexus-rpc": "^0.0.3", "protobufjs": "^8.7.1" } }, "sha512-jXp77fXwynBcVNc/CaGMT33TVYnhcN26S959HDv7Q71oc0rN6d8RHWR5z0nRCDAu5CQwZQRRhVK0TRdyAiEg7Q=="],
"@shumai/core/@temporalio/workflow/@temporalio/proto": ["@temporalio/proto@1.24.0", "", { "dependencies": { "long": "^5.3.2", "protobufjs": "^8.7.1" } }, "sha512-vhlhB9GpoyJx+78r3lDahHywpdri6LKx7kt7djLIw6XzHyb8FQTIi4lX8DSJBqKp3+HVfL1CLwiqO26KFRzg/g=="],
"@spectrum-web-components/action-button/@spectrum-web-components/icon/@spectrum-web-components/iconset": ["@spectrum-web-components/iconset@0.37.0", "", { "dependencies": { "@spectrum-web-components/base": "^0.37.0" } }, "sha512-s1TBjWeQtGdGf6n+r+aG2glv77IgR0pNs0HLusGyYt6jzWFkP276fE7Neqq/2XvG9a9zvAwngffnWS3td/Gtmg=="],
"@spectrum-web-components/action-group/@spectrum-web-components/icons-workflow/@spectrum-web-components/icon": ["@spectrum-web-components/icon@0.37.0", "", { "dependencies": { "@spectrum-web-components/base": "^0.37.0", "@spectrum-web-components/iconset": "^0.37.0" } }, "sha512-DZ1yOKHxNQygzIJ7u9akYComDnMmxuTzfmYxxt9sHdUXmc1NbMkCJqEaAG/LYsdb+hc4xWaDTT9SzArLKZ/btA=="],
@@ -3599,6 +3604,20 @@
"@prisma/studio-core/@radix-ui/react-toggle/@radix-ui/react-use-controllable-state/@radix-ui/react-use-layout-effect": ["@radix-ui/react-use-layout-effect@1.1.1", "", { "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-RbJRS4UWQFkzHTTwVymMTUv8EqYhOp8dOOviLj2ugtTiXRaRQS7GLGxZTLL1jWhMeoSCf5zmcZkqTl9IiYfXcQ=="],
"@shumai/core/@temporalio/activity/@temporalio/client/@temporalio/proto": ["@temporalio/proto@1.24.0", "", { "dependencies": { "long": "^5.3.2", "protobufjs": "^8.7.1" } }, "sha512-vhlhB9GpoyJx+78r3lDahHywpdri6LKx7kt7djLIw6XzHyb8FQTIi4lX8DSJBqKp3+HVfL1CLwiqO26KFRzg/g=="],
"@shumai/core/@temporalio/activity/@temporalio/common/@temporalio/proto": ["@temporalio/proto@1.24.0", "", { "dependencies": { "long": "^5.3.2", "protobufjs": "^8.7.1" } }, "sha512-vhlhB9GpoyJx+78r3lDahHywpdri6LKx7kt7djLIw6XzHyb8FQTIi4lX8DSJBqKp3+HVfL1CLwiqO26KFRzg/g=="],
"@shumai/core/@temporalio/activity/@temporalio/common/ms": ["ms@3.0.0-canary.1", "", {}, "sha512-kh8ARjh8rMN7Du2igDRO9QJnqCb2xYTJxyQYK7vJJS4TvLLmsbyhiKpSW+t+y26gyOyMd0riphX0GeWKU3ky5g=="],
"@shumai/core/@temporalio/activity/@temporalio/common/protobufjs": ["protobufjs@8.8.0", "", { "dependencies": { "long": "^5.3.2" } }, "sha512-N3xhQ5yyBx3vQq4gubBfASzYhJGNzeDbjqBpu61g7UVylsN/qyffU96TKWD3GbbLOKF82VGNRNvv1+BFgE31Eg=="],
"@shumai/core/@temporalio/workflow/@temporalio/common/ms": ["ms@3.0.0-canary.1", "", {}, "sha512-kh8ARjh8rMN7Du2igDRO9QJnqCb2xYTJxyQYK7vJJS4TvLLmsbyhiKpSW+t+y26gyOyMd0riphX0GeWKU3ky5g=="],
"@shumai/core/@temporalio/workflow/@temporalio/common/protobufjs": ["protobufjs@8.8.0", "", { "dependencies": { "long": "^5.3.2" } }, "sha512-N3xhQ5yyBx3vQq4gubBfASzYhJGNzeDbjqBpu61g7UVylsN/qyffU96TKWD3GbbLOKF82VGNRNvv1+BFgE31Eg=="],
"@shumai/core/@temporalio/workflow/@temporalio/proto/protobufjs": ["protobufjs@8.8.0", "", { "dependencies": { "long": "^5.3.2" } }, "sha512-N3xhQ5yyBx3vQq4gubBfASzYhJGNzeDbjqBpu61g7UVylsN/qyffU96TKWD3GbbLOKF82VGNRNvv1+BFgE31Eg=="],
"@spectrum-web-components/action-group/@spectrum-web-components/icons-workflow/@spectrum-web-components/icon/@spectrum-web-components/iconset": ["@spectrum-web-components/iconset@0.37.0", "", { "dependencies": { "@spectrum-web-components/base": "^0.37.0" } }, "sha512-s1TBjWeQtGdGf6n+r+aG2glv77IgR0pNs0HLusGyYt6jzWFkP276fE7Neqq/2XvG9a9zvAwngffnWS3td/Gtmg=="],
"@spectrum-web-components/card/@spectrum-web-components/icons-workflow/@spectrum-web-components/icon/@spectrum-web-components/iconset": ["@spectrum-web-components/iconset@0.37.0", "", { "dependencies": { "@spectrum-web-components/base": "^0.37.0" } }, "sha512-s1TBjWeQtGdGf6n+r+aG2glv77IgR0pNs0HLusGyYt6jzWFkP276fE7Neqq/2XvG9a9zvAwngffnWS3td/Gtmg=="],
@@ -3620,5 +3639,7 @@
"readdir-glob/minimatch/brace-expansion/balanced-match": ["balanced-match@1.0.2", "", {}, "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="],
"@prisma/studio-core/@radix-ui/react-toggle/@radix-ui/react-primitive/@radix-ui/react-slot/@radix-ui/react-compose-refs": ["@radix-ui/react-compose-refs@1.1.2", "", { "peerDependencies": { "@types/react": "*", "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" }, "optionalPeers": ["@types/react"] }, "sha512-z4eqJvfiNnFMHIIvXP3CY57y2WJs5g2v3X0zm9mEJkrkNv4rDxu+sg9Jh8EkXyeqBkB7SOcboo9dMVqhyrACIg=="],
"@shumai/core/@temporalio/activity/@temporalio/client/@temporalio/proto/protobufjs": ["protobufjs@8.8.0", "", { "dependencies": { "long": "^5.3.2" } }, "sha512-N3xhQ5yyBx3vQq4gubBfASzYhJGNzeDbjqBpu61g7UVylsN/qyffU96TKWD3GbbLOKF82VGNRNvv1+BFgE31Eg=="],
}
}
@@ -6,8 +6,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/18/docker
healthcheck:
@@ -28,6 +26,11 @@ services:
- '3000:3000'
volumes:
- ./data:/app/data
# Hardware Acceleration (NVENC / QuickSync / VA-API / RKMPP)
# Uncomment the extends section below for hardware acceleration:
# extends:
# file: hwaccel.transcoding.yaml
# service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
environment:
# Database Configuration
DATABASE_URL: postgres://shumai:shumai_password@shumai_postgres:5432/shumai_db?search_path=public&sslmode=disable
+5 -2
View File
@@ -6,8 +6,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql/18/docker
healthcheck:
@@ -28,6 +26,11 @@ services:
- '3000:3000'
volumes:
- ./data:/app/data
# Hardware Acceleration (NVENC / QuickSync / VA-API / RKMPP)
# Uncomment the extends section below for hardware acceleration:
# extends:
# file: hwaccel.transcoding.yaml
# service: cpu # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl] for accelerated transcoding
environment:
# Database Configuration
DATABASE_URL: postgres://shumai:shumai_password@shumai_postgres:5432/shumai_db?search_path=public&sslmode=disable
@@ -0,0 +1,44 @@
# Configurations for hardware-accelerated transcoding
services:
cpu: {}
nvenc:
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities:
- gpu
- compute
- video
quicksync:
devices:
- /dev/dri:/dev/dri
rkmpp:
security_opt: # enables full access to /sys and /proc, still far better than privileged: true
- systempaths=unconfined
- apparmor=unconfined
group_add:
- video
devices:
- /dev/rga:/dev/rga
- /dev/dri:/dev/dri
- /dev/dma_heap:/dev/dma_heap
- /dev/mpp_service:/dev/mpp_service
vaapi:
devices:
- /dev/dri:/dev/dri
vaapi-wsl: # use this for VAAPI if running in WSL2
devices:
- /dev/dri:/dev/dri
- /dev/dxg:/dev/dxg
volumes:
- /usr/lib/wsl:/usr/lib/wsl
environment:
- LIBVA_DRIVER_NAME=d3d12
@@ -7,8 +7,6 @@ services:
POSTGRES_USER: shumai
POSTGRES_PASSWORD: shumai_password
POSTGRES_DB: shumai_db
ports:
- '5432:5432'
volumes:
- postgres_data:/var/lib/postgresql
healthcheck:
+890
View File
@@ -0,0 +1,890 @@
---
title: "Changelog"
description: "Recent updates, new features, and improvements in Shumai"
---
<Update label="v0.5.2" description="October 13, 2026">
### Added
* **3d asset**: Add support for 3D model files (.glb, .gltf, .obj, .fbx, .stl, .dae, .usd, .usda, .usdc, .usdz) with automated turntable video rendering, hover sprite scrubbing, and an interactive 3D turntable viewer featuring 360° ruler scrubbing and degree-based markup comments
* **kanban**: Related assets on a task are now clickable, taking you directly to that file or folder in its project
* **settings**: Add an Integrations section to Team Settings with dedicated configuration for Gotenberg Document Converter, supporting connection testing and environment variable override protection
### Fixed
* **transcode**: Fix an issue where portrait photos from cameras and phones appeared sideways in thumbnails, previews, watermarked share links and annotated snapshots, and were listed with their width and height swapped
### Changed
</Update>
<Update label="v0.5.1" description="October 6, 2026">
### Added
* **notification**: Notification cards are now clickable, taking you directly to the relevant file
* **transcode**: Add hardware decoding and GPU scaling support for NVIDIA NVENC, Intel QuickSync Video (QSV), Rockchip (RKMPP), and VA-API (Intel and AMD GPUs), significantly speeding up video proxy and HLS rendition generation across supported platforms. Set `SHUMAI_HW_DECODE=false` to turn hardware decoding off
* **transcode**: Add `dcraw_emu` fallback to generate WebP previews for camera RAW files without embedded JPEG previews
### Fixed
### Changed
</Update>
<Update label="v0.5.0" description="October 2, 2026">
### Added
* **transcode**: Add configurable target resolution ladders (480p, 720p, 1080p, 1440p, 2160p) for MP4 Multi Resolutions transcoding in team settings, with unified resolution matching and lowest-resolution fallback for both MP4 and HLS
* **transcode**: Add HLS live streaming with fMP4/CMAF adaptive bitrate ladders (480p, 720p, 1080p, 1440p, 2160p), configurable in Transcode Settings, with automatic quality switching, manual resolution selection in the video viewer, seamless rendition switching, and full watermarking support for shared links
* **transcode**: Add basic camera RAW image support for popular camera formats (including Sony ARW, Canon CR2/CR3, Nikon NEF, Adobe DNG, Fujifilm RAF, and Panasonic RW2), extracting high-quality embedded JPEG previews and automatically applying camera orientation for fast thumbnail and proxy generation
### Fixed
- **asset**: Fix an issue where media files remained stuck in a perpetual "Preparing..." state when transcoding failed, by displaying a clear failed status and error details in the file list and file viewer
* **transcode**: Fix an issue where videos or audio-only files containing attached cover art or picture streams could cause transcoding to fail during poster generation or select a single static image instead of the video
* **webui**: Fix inconsistent video resolution labels across download menus, mobile file headers, and the video player by correctly deriving resolutions from the video's short side, including portrait videos and 480p videos
* **trash**: Fix an issue where the "Empty Trash" confirmation dialog would close immediately instead of showing a loading state while files were being permanently deleted
### Changed
* **settings**: Redesign team Video Transcoding settings with dedicated cards for Transcode Policy, Hardware Acceleration, and FFmpeg Threads, clearly explaining MP4 and HLS playback vs download behavior and storage implications
* **settings**: Rename AI Settings group to Team AI Settings in settings navigation
</Update>
<Update label="v0.4.9" description="September 28, 2026">
### Added
- **notification**: You can now receive notifications via email, with batched digest emails and configurable team-level SMTP settings
- **transcode**: Add VA-API hardware acceleration support for Linux hosts and Docker environments with Intel and AMD GPUs, featuring automatic DRI render node discovery, variable bitrate control, and structured transcoding observability logs
- **transcode**: Add automatic fallback to software transcoding (libx264) when hardware-accelerated video encoding encounters GPU resolution constraints or runtime driver errors
- **docker**: Add modular hardware-accelerated transcoding presets matching Immich's compose configuration via `hwaccel.transcoding.yaml` with support for NVENC, QuickSync, RKMPP, and VA-API
### Fixed
### Changed
- **transcode**: Improve video poster selection using intelligent scene detection and color variance filtering to automatically skip black frames, fade-ins, and blank intros in favor of representative video content
- **transcode**: Optimize video sprite generation for large and long videos using a concurrent fast-seek pool and image compositing, avoiding full-video decoding while preserving instant single-pass generation for short clips
</Update>
<Update label="v0.4.8" description="September 24, 2026">
### Added
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
### Fixed
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
### Changed
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
</Update>
<Update label="v0.4.7" description="September 19, 2026">
### Added
- **changelog**: Introduce Keep a Changelog support, historical release summaries, and automated release notes extraction
- **release**: Automatically populate GitHub release bodies from CHANGELOG.md and promote unreleased notes during version bumps
- **settings**: Add FFmpeg threads slider to team media processing settings
- **asset**: Show previews of a folder's contents and a "days left" countdown for each item in Recently Deleted
- **asset**: Show the poster and hover preview for a video in the file list while it is still transcoding, with a gently pulsing cover (or an animated waiting circle before the poster is ready), "Uploading..."/"Preparing..." labels, and the duration hidden until it is ready
### Fixed
- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status
- **transcode**: Immediately stop background video processing and transcoding when a file is permanently deleted from the trash
- **asset**: Fix proxy download filename using original file extension instead of proxy extension
- **asset**: Fix an issue where deleting or restoring a version stack from the file list did nothing
- **webui**: Center breadcrumb file action popup menu on the chevron icon
</Update>
<Update label="v0.4.6" description="September 17, 2026">
### Added
- **comment**: Add emoji reaction support for comments ([#405](https://github.com/shumaiOne/shumai/pull/405))
- **premiere-uxp**: Introduce Adobe Premiere Pro UXP plugin for Shumai ([#407](https://github.com/shumaiOne/shumai/pull/407))
- **settings**: Add team appearance setting to hide agent features ([#411](https://github.com/shumaiOne/shumai/pull/411))
### Fixed
- **premiere-uxp**: Preserve remote cloud storage presigned URLs in asset resolution ([#408](https://github.com/shumaiOne/shumai/pull/408))
- **premiere-uxp**: Scope sequence links by server endpoint and surface sync errors ([#409](https://github.com/shumaiOne/shumai/pull/409))
- **api**: Enforce SHUMAI_DEMO_MODE for API token and CLI requests ([#413](https://github.com/shumaiOne/shumai/pull/413))
### Documentation
- Add NLE export and Premiere Pro UXP plugin documentation ([#412](https://github.com/shumaiOne/shumai/pull/412))
</Update>
<Update label="v0.4.5" description="September 13, 2026">
### Added
- **core**: Export comments to FCP, Premiere, Media Composer, and Resolve ([#400](https://github.com/shumaiOne/shumai/pull/400))
- **webui**: Add NLE comments export and migrate export API to POST ([#401](https://github.com/shumaiOne/shumai/pull/401))
- **webui**: Add space key quick preview for files and folders ([#402](https://github.com/shumaiOne/shumai/pull/402))
- **webui**: Show comments count badge in file card preview area ([#403](https://github.com/shumaiOne/shumai/pull/403))
- **agent**: Use deterministic storage keys for preset avatars ([#404](https://github.com/shumaiOne/shumai/pull/404))
</Update>
<Update label="v0.4.4" description="September 9, 2026">
### Added
- **upload**: S3 multipart upload with offline resume and wake lock ([#391](https://github.com/shumaiOne/shumai/pull/391))
- **transcode**: Optimize video operations using ffmpeg http range requests ([#393](https://github.com/shumaiOne/shumai/pull/393))
- **agent**: Enable read_asset tool for autofill agent ([#396](https://github.com/shumaiOne/shumai/pull/396))
- **sandbox**: Abstract SandboxService and hot-reload allowed domains ([#398](https://github.com/shumaiOne/shumai/pull/398))
### Fixed
- **s3**: Stream downloadToFile and putObject to prevent OOM on large files ([#392](https://github.com/shumaiOne/shumai/pull/392))
- **agent**: Pass agent thinkingLevel to session name generation ([#395](https://github.com/shumaiOne/shumai/pull/395))
- **agent**: Restrict pageCount and duration recommendations to matching media types ([#397](https://github.com/shumaiOne/shumai/pull/397))
- **transcode**: Co-locate screenshots and derived artifacts in asset storage directory ([#399](https://github.com/shumaiOne/shumai/pull/399))
</Update>
<Update label="v0.4.3" description="September 6, 2026">
### Added
- **asset**: Record and display agent provenance on assets and audit logs ([#380](https://github.com/shumaiOne/shumai/pull/380))
- **agent**: Store preset avatars as real files in s3 storage ([#381](https://github.com/shumaiOne/shumai/pull/381))
- **agent**: Add built-in image and video generation tools and settings ([#382](https://github.com/shumaiOne/shumai/pull/382))
- **media-generation**: Add gemini-omni-1.1-flash video model and redesign settings UI ([#383](https://github.com/shumaiOne/shumai/pull/383))
- **settings**: Redesign image/video settings to provider dialog with model toggles ([#385](https://github.com/shumaiOne/shumai/pull/385))
- **agent**: Add asset management tools and CLI commands ([#387](https://github.com/shumaiOne/shumai/pull/387))
- **cli**: Control asset deletion via SHUMAI_ALLOW_DELETE env var ([#388](https://github.com/shumaiOne/shumai/pull/388))
### Fixed
- **webui**: Clamp file card creation info to 2 lines and show tooltip on hover ([#390](https://github.com/shumaiOne/shumai/pull/390))
### Documentation
- **agents**: Add documentation for image and video generation settings ([#389](https://github.com/shumaiOne/shumai/pull/389))
### Maintenance
- **deps**: Upgrade bun to 1.4.2 and update packages ([#384](https://github.com/shumaiOne/shumai/pull/384))
- **i18n**: Update paraglide-js to 2.25.0 and stop checking in generated code ([#386](https://github.com/shumaiOne/shumai/pull/386))
</Update>
<Update label="v0.4.2" description="September 3, 2026">
### Added
- **chat**: Support markups, attachments, and timestamps in agent 1-to-1 chat ([#368](https://github.com/shumaiOne/shumai/pull/368))
- **agent**: Move thread metadata to structured context XML ([#373](https://github.com/shumaiOne/shumai/pull/373))
- **agent**: Improve timestamp precision and proxy selection for video screenshots ([#374](https://github.com/shumaiOne/shumai/pull/374))
- **agent**: Support dynamic annotationId resolution across chat and comments ([#375](https://github.com/shumaiOne/shumai/pull/375))
- **agent**: Consolidate media tools into read_asset and add S3 key support to download_asset ([#376](https://github.com/shumaiOne/shumai/pull/376))
- **provider**: Optimize provider and model configuration management ([#377](https://github.com/shumaiOne/shumai/pull/377))
- **provider**: Add provider and model sync feature with vendored generator ([#378](https://github.com/shumaiOne/shumai/pull/378))
### Fixed
- **agent**: Set empty details in asset tool results to avoid data duplication ([#370](https://github.com/shumaiOne/shumai/pull/370))
- **webui**: Strip styles and preserve multiline text on paste in chat input ([#371](https://github.com/shumaiOne/shumai/pull/371))
- **agent**: Hide main comment sessions in dashboard sessions list ([#372](https://github.com/shumaiOne/shumai/pull/372))
### Changed
- **webui**: Use semantic system colors in notification settings ([#379](https://github.com/shumaiOne/shumai/pull/379))
</Update>
<Update label="v0.4.1" description="August 30, 2026">
### Added
- **webui**: Add manage versions option to file card context menu ([#364](https://github.com/shumaiOne/shumai/pull/364))
- **agent**: Refactor message context into unified shumai_message ([#365](https://github.com/shumaiOne/shumai/pull/365))
- **webui**: Redesign comment attachment display into compact rows ([#366](https://github.com/shumaiOne/shumai/pull/366))
### Fixed
- **asset,webui**: Disallow dropping version stacks onto files and version stacks ([#363](https://github.com/shumaiOne/shumai/pull/363))
- **webui**: Prevent empty folder flash during initial loading ([#367](https://github.com/shumaiOne/shumai/pull/367))
### Changed
- **agent**: Remove executeAgentToolWorkflow and invoke core services directly ([#362](https://github.com/shumaiOne/shumai/pull/362))
</Update>
<Update label="v0.4.0" description="August 28, 2026">
### Added
- **transcode**: Add hardware-accelerated video transcoding support ([#352](https://github.com/shumaiOne/shumai/pull/352))
- **webui**: Truncate long file names with 100ms hover tooltip ([#355](https://github.com/shumaiOne/shumai/pull/355))
- **webui**: Add simplified mobile-friendly layout for file and share lists ([#356](https://github.com/shumaiOne/shumai/pull/356))
- **webui**: Add mobile friendly file detail and public share view ([#359](https://github.com/shumaiOne/shumai/pull/359))
### Fixed
- **transcode**: Apply team hardware acceleration and source bitrate capping to watermark transcoding ([#353](https://github.com/shumaiOne/shumai/pull/353))
- **share**: Hide and soft-delete symlinks when target assets are trashed ([#354](https://github.com/shumaiOne/shumai/pull/354))
- **webui**: Fix breadcrumb file dropdown trigger stretching and alignment ([#360](https://github.com/shumaiOne/shumai/pull/360))
- **webui**: Align mobile comment cards and thread vertical indicator ([#361](https://github.com/shumaiOne/shumai/pull/361))
### Documentation
- Add SECURITY.md with a private disclosure path ([#357](https://github.com/shumaiOne/shumai/pull/357))
</Update>
<Update label="v0.3.11" description="August 25, 2026">
### Added
- **auth**: Add admin password reset CLI command and reset password web UI ([#347](https://github.com/shumaiOne/shumai/pull/347))
- **project**: Add recent viewed files section to project folder tree ([#348](https://github.com/shumaiOne/shumai/pull/348))
### Fixed
- **webui**: Prevent left carousel remounting and scroll jump on file selection ([#351](https://github.com/shumaiOne/shumai/pull/351))
</Update>
<Update label="v0.3.10" description="August 23, 2026">
### Added
- **agentic kanban**: Phase 1 not-agentic kanban board ([#330](https://github.com/shumaiOne/shumai/pull/330))
- **kanban**: Resolve latest version for linked version stack assets and update demo login text ([#342](https://github.com/shumaiOne/shumai/pull/342))
- **kanban**: Update task status permissions, reporter defaults, and participant access ([#345](https://github.com/shumaiOne/shumai/pull/345))
### Fixed
- **kanban**: Use true thumbnail and poster for task asset previews ([#343](https://github.com/shumaiOne/shumai/pull/343))
- **webui**: Sidebar selection styling, kanban active state, pointer cursors, and owner dashboard ([#344](https://github.com/shumaiOne/shumai/pull/344))
- **kanban**: Improve drag-drop to column bottom, remove empty drop line, and fix timeline alignment ([#346](https://github.com/shumaiOne/shumai/pull/346))
</Update>
<Update label="v0.3.9" description="August 18, 2026">
### Added
- **agent**: Add permission controls for chat agents ([#313](https://github.com/shumaiOne/shumai/pull/313))
- **authz**: Enforce project-aware roles for agent/skill/mcp permissions ([#314](https://github.com/shumaiOne/shumai/pull/314))
- **webui**: Use project members for asset comment mentions ([#315](https://github.com/shumaiOne/shumai/pull/315))
- **quota**: Add 2-level database-backed resource quota system ([#318](https://github.com/shumaiOne/shumai/pull/318))
- **settings**: Reorganize settings into personal, team, and AI sections ([#324](https://github.com/shumaiOne/shumai/pull/324))
- **quota**: Move usage monitoring to team dashboard ([#327](https://github.com/shumaiOne/shumai/pull/327))
### Fixed
- **webui**: Preserve selected chatbot agent preference on reload ([#323](https://github.com/shumaiOne/shumai/pull/323))
- **quota**: Exclude agents from quota rules and usage records ([#325](https://github.com/shumaiOne/shumai/pull/325))
### Documentation
- **team-settings**: Add resource quotas documentation and update readme features ([#326](https://github.com/shumaiOne/shumai/pull/326))
</Update>
<Update label="v0.3.8" description="August 15, 2026">
### Added
- **webui**: Replace legacy markdown editor with new lexical wysiwyg editor ([#308](https://github.com/shumaiOne/shumai/pull/308))
- **agent**: Add nested agents.md support across backend and webui ([#309](https://github.com/shumaiOne/shumai/pull/309))
- **webui**: Improve AGENTS.md editor placeholder and read-only notice ([#310](https://github.com/shumaiOne/shumai/pull/310))
- **version-stack**: Add manage versions dialog and version removal ([#311](https://github.com/shumaiOne/shumai/pull/311))
### Fixed
- **core**: Rename latest version child record on version stack rename ([#312](https://github.com/shumaiOne/shumai/pull/312))
</Update>
<Update label="v0.3.7" description="August 14, 2026">
### Added
- **metadata**: Replace aiAutofill boolean with autofillSource enum ([#302](https://github.com/shumaiOne/shumai/pull/302))
- **agent**: Type-safe CREATION_CONTEXT metadata on create_file/create_version ([#303](https://github.com/shumaiOne/shumai/pull/303))
- **sandbox**: Default Network Sandbox to off and add settings toggle switch ([#304](https://github.com/shumaiOne/shumai/pull/304))
- **webui**: Redesign select metadata fields and improve long text field widget ([#305](https://github.com/shumaiOne/shumai/pull/305))
- **agent**: Support dynamic newOption in select and selectMulti metadata fields ([#306](https://github.com/shumaiOne/shumai/pull/306))
### Fixed
- **webui**: Fix select field height and multi-select overflow/interaction issues ([#307](https://github.com/shumaiOne/shumai/pull/307))
</Update>
<Update label="v0.3.6" description="August 12, 2026">
### Added
- **mcp**: Add MCP server support with proxy tool and OAuth flow ([#289](https://github.com/shumaiOne/shumai/pull/289))
- **mcp**: Support tool-level directTools array and 3-state UI configuration ([#297](https://github.com/shumaiOne/shumai/pull/297))
- **webui**: Direct canvas PDF rendering with selectable text ([#299](https://github.com/shumaiOne/shumai/pull/299))
### Fixed
- **agent**: Prevent agents from accessing disabled skills ([#292](https://github.com/shumaiOne/shumai/pull/292))
- **agent**: Resolve version stack name and size in list_assets ([#296](https://github.com/shumaiOne/shumai/pull/296))
- **webui**: Content-only pinch-zoom and two-finger pan in media viewers ([#298](https://github.com/shumaiOne/shumai/pull/298))
- **i18n**: Update Chinese translation for dashboard to 仪表板 ([#301](https://github.com/shumaiOne/shumai/pull/301))
### Documentation
- **mcp**: Add MCP support documentation to README and docs ([#300](https://github.com/shumaiOne/shumai/pull/300))
</Update>
<Update label="v0.3.5" description="August 9, 2026">
### Added
- **transcode**: Add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies ([#283](https://github.com/shumaiOne/shumai/pull/283))
### Fixed
- **webui**: Resolve upload card freeze for unsupported files ([#284](https://github.com/shumaiOne/shumai/pull/284))
- **webui**: Exclude file extension when selecting file name during inline rename ([#285](https://github.com/shumaiOne/shumai/pull/285))
- Use renamed asset name in download Content-Disposition ([#286](https://github.com/shumaiOne/shumai/pull/286))
- **webui**: Batch download no longer flashes a tab per file ([#287](https://github.com/shumaiOne/shumai/pull/287))
- **webui**: Enable rename and delete actions in file detail top bar breadcrumb ([#288](https://github.com/shumaiOne/shumai/pull/288))
</Update>
<Update label="v0.3.4" description="August 8, 2026">
### Added
- **sharelink**: Add sharelink watermark support ([#270](https://github.com/shumaiOne/shumai/pull/270))
- **webui**: Remove original-file display fallbacks, use proxies only ([#273](https://github.com/shumaiOne/shumai/pull/273))
- **share**: Add allow download config to share links ([#275](https://github.com/shumaiOne/shumai/pull/275))
- **transcode**: Update preview thumbnail resolution to 300p with max length constraint ([#281](https://github.com/shumaiOne/shumai/pull/281))
### Fixed
- **share**: Resolve symlink asset downloads in public share pages ([#274](https://github.com/shumaiOne/shumai/pull/274))
- **webui**: Persist project sorting and prevent full page flash ([#276](https://github.com/shumaiOne/shumai/pull/276))
### Documentation
- **share-links**: Document allow download and lazy watermark settings ([#278](https://github.com/shumaiOne/shumai/pull/278))
- **agent**: Clarify create_file/create_version context param guidance ([#282](https://github.com/shumaiOne/shumai/pull/282))
### Maintenance
- **e2e**: Watermarked download-disabled share link coverage (image + video) ([#277](https://github.com/shumaiOne/shumai/pull/277))
- **e2e**: Stabilize watermark share spec on Firefox ([#279](https://github.com/shumaiOne/shumai/pull/279))
- Split e2e scripts into app and webui targets ([#280](https://github.com/shumaiOne/shumai/pull/280))
</Update>
<Update label="v0.3.3" description="August 5, 2026">
### Added
- **agent**: Enable LLM API call retries in AgentHarness ([#250](https://github.com/shumaiOne/shumai/pull/250))
- **audit**: Add audit log support for APIs and WebUI dashboard ([#251](https://github.com/shumaiOne/shumai/pull/251))
- **webui**: Persist agent preference in localStorage ([#254](https://github.com/shumaiOne/shumai/pull/254))
- **e2e**: Add file domain comment and draw tests ([#260](https://github.com/shumaiOne/shumai/pull/260))
- **agent**: Restrict bash access for non-owner users ([#262](https://github.com/shumaiOne/shumai/pull/262))
- **agent**: Allow create_file tool to create files directly from content ([#263](https://github.com/shumaiOne/shumai/pull/263))
- **agent**: Propagate autofill context from chat to autofill workflow ([#264](https://github.com/shumaiOne/shumai/pull/264))
- **webui**: Render select options in field creation mode and pick random option color ([#265](https://github.com/shumaiOne/shumai/pull/265))
- **project**: Include team-scoped members in project member list and add 3-section dialog layout ([#267](https://github.com/shumaiOne/shumai/pull/267))
- **webui**: Disable role dropdown for project-scoped members in team view ([#269](https://github.com/shumaiOne/shumai/pull/269))
### Fixed
- **webui**: Mention popup avatars, keyboard auto-scroll, and non-sticky section headers ([#256](https://github.com/shumaiOne/shumai/pull/256))
- **webui**: Persist field order on drag and drop ([#266](https://github.com/shumaiOne/shumai/pull/266))
### Changed
- **agent**: Load models directly from database without pi fallback ([#253](https://github.com/shumaiOne/shumai/pull/253))
- **core**: Replace generated provider files with pi-ai dynamic methods ([#255](https://github.com/shumaiOne/shumai/pull/255))
### Maintenance
- **core**: Add missing tests for methods introduced in 97069042 ([#252](https://github.com/shumaiOne/shumai/pull/252))
- **e2e**: Add domain-based auth and project web app e2e tests ([#257](https://github.com/shumaiOne/shumai/pull/257))
- **e2e**: Add file, share, and collection web app e2e tests ([#258](https://github.com/shumaiOne/shumai/pull/258))
- **e2e**: Add project-level invite and file-move e2e tests ([#259](https://github.com/shumaiOne/shumai/pull/259))
- **e2e**: Add search in file list and save-search-as-collection cases ([#261](https://github.com/shumaiOne/shumai/pull/261))
- **e2e**: Add member permission change tests ([#268](https://github.com/shumaiOne/shumai/pull/268))
</Update>
<Update label="v0.3.2" description="July 30, 2026">
### Added
- **agent**: Add output truncation and streaming limits to sandboxed bash tool ([#248](https://github.com/shumaiOne/shumai/pull/248))
### Fixed
- **agent**: Download original document asset instead of pdf proxy ([#247](https://github.com/shumaiOne/shumai/pull/247))
- **webui**: Persist chatbot sidebar input text across route navigation ([#249](https://github.com/shumaiOne/shumai/pull/249))
</Update>
<Update label="v0.3.1" description="July 30, 2026">
### Added
- **transcode**: Trigger ai metadata autofill post transcode ([#234](https://github.com/shumaiOne/shumai/pull/234))
- **dashboard**: Add agent sessions view for team owners ([#237](https://github.com/shumaiOne/shumai/pull/237))
- **db**: Preserve agent sessions on asset deletion by setting onDelete to SetNull ([#240](https://github.com/shumaiOne/shumai/pull/240))
- **agent**: Add download_asset tool and prompt instructions ([#242](https://github.com/shumaiOne/shumai/pull/242))
- **db**: Update Asset.sizeByte and AiUsage token fields to BigInt ([#244](https://github.com/shumaiOne/shumai/pull/244))
### Fixed
- **agent**: Include select option labels and field name in autofill schema ([#235](https://github.com/shumaiOne/shumai/pull/235))
- **agent**: Scope agent comment sessions to thread sessions anchored at root comments ([#239](https://github.com/shumaiOne/shumai/pull/239))
- **agent**: Disable tools for session naming and make naming non-blocking ([#241](https://github.com/shumaiOne/shumai/pull/241))
- **webui**: Update file size formatting to SI decimal standard ([#245](https://github.com/shumaiOne/shumai/pull/245))
- **s3**: Enforce property syntax in S3Service interface and fix ReadableStream handling in S3StorageService ([#246](https://github.com/shumaiOne/shumai/pull/246))
</Update>
<Update label="v0.3.0" description="July 28, 2026">
### Added
- **file-browser**: Add copy name and path option to context menu ([#225](https://github.com/shumaiOne/shumai/pull/225))
- **agent**: Inject user name and role into chat context ([#226](https://github.com/shumaiOne/shumai/pull/226))
- **agent**: Refactor database session storage to normalized DAG entries and lazy thread sync ([#229](https://github.com/shumaiOne/shumai/pull/229))
- **agent**: Support ENABLE_WEAKER_NESTED_SANDBOX environment variable ([#233](https://github.com/shumaiOne/shumai/pull/233))
### Fixed
- **agent**: Ensure atomic appendEntry and persist leaf entries in DatabaseSessionStorage ([#224](https://github.com/shumaiOne/shumai/pull/224))
- Sharp version mismatch bug ([#230](https://github.com/shumaiOne/shumai/pull/230))
- **agent**: Resolve S3 MIME type detection and prompt parameter in image analysis ([#232](https://github.com/shumaiOne/shumai/pull/232))
### Changed
- **agent**: Remove implicit agent mention trigger in comment threads ([#227](https://github.com/shumaiOne/shumai/pull/227))
### Maintenance
- **workflow**: Add docker compose deployment verification job ([#231](https://github.com/shumaiOne/shumai/pull/231))
</Update>
<Update label="v0.2.3" description="July 25, 2026">
### Fixed
- **webui**: Show right sidebar by default on file detail page ([#219](https://github.com/shumaiOne/shumai/pull/219))
- **webui**: Refresh file list and detail when agent executes asset creation tools ([#220](https://github.com/shumaiOne/shumai/pull/220))
- **webui**: Fix space key drag overlay and shift range selection for version stacks ([#221](https://github.com/shumaiOne/shumai/pull/221))
- **transcode**: Handle timestamp rounding tolerance for screenshot annotations ([#223](https://github.com/shumaiOne/shumai/pull/223))
### Changed
- **e2e**: Split transcode workflow E2E tests into per-workflow test files ([#222](https://github.com/shumaiOne/shumai/pull/222))
</Update>
<Update label="v0.2.2" description="July 23, 2026">
### Added
- **webui**: Integrate AI usage API into dashboard page ([#216](https://github.com/shumaiOne/shumai/pull/216))
- **ai-usage**: Add team and member token usage tracking and APIs ([#215](https://github.com/shumaiOne/shumai/pull/215))
- **transcode**: Add PSD support via ImageMagick and enforce sRGB conversion ([#217](https://github.com/shumaiOne/shumai/pull/217))
### Fixed
- **search**: Fix buildSqlCondition date range, numeric metadata, and string parsing bugs ([#213](https://github.com/shumaiOne/shumai/pull/213))
- **webui**: Prevent horizontal overflow in search dialog result rows ([#214](https://github.com/shumaiOne/shumai/pull/214))
- **webui**: Invalidate upload tasks query when upload task starts and completes ([#218](https://github.com/shumaiOne/shumai/pull/218))
</Update>
<Update label="v0.2.1" description="July 22, 2026">
### Added
- **skill**: Add team owner skill permission control ([#209](https://github.com/shumaiOne/shumai/pull/209))
### Fixed
- **agent**: Handle non-builtin models in getModelFromDb and upgrade pi-ai ([#211](https://github.com/shumaiOne/shumai/pull/211))
- **provider**: Preserve model ids on provider update ([#212](https://github.com/shumaiOne/shumai/pull/212))
### Changed
- **core**: Split generated providers into per-provider files ([#210](https://github.com/shumaiOne/shumai/pull/210))
</Update>
<Update label="v0.2.0" description="July 21, 2026">
### Added
- **transcode**: Add PDF preview, sprite generation, and annotation support ([#193](https://github.com/shumaiOne/shumai/pull/193))
- **web**: Register pdf.worker route in production ([#195](https://github.com/shumaiOne/shumai/pull/195))
- **agent**: Add read_pdf_pages tool and PDF page context support ([#196](https://github.com/shumaiOne/shumai/pull/196))
- **transcode**: Split monolithic transcodeMedia into focused workflows ([#197](https://github.com/shumaiOne/shumai/pull/197))
- **transcode**: Add PDF proxy support for TXT and CSV files ([#199](https://github.com/shumaiOne/shumai/pull/199))
- **asset**: Replace mediaType/mimeType logic with proxyType ([#200](https://github.com/shumaiOne/shumai/pull/200))
- **docker**: Install fonts-noto-cjk in runner stage ([#202](https://github.com/shumaiOne/shumai/pull/202))
- **transcode**: Add markdown file to pdf proxy support ([#203](https://github.com/shumaiOne/shumai/pull/203))
- **chat**: Track context asset changes and update agent context ([#204](https://github.com/shumaiOne/shumai/pull/204))
- **agent**: Refactor media tools to static injection with mandatory assetId and authz ([#208](https://github.com/shumaiOne/shumai/pull/208))
### Fixed
- **transcode**: Mark pdfkit as external and extract for docker runtime ([#201](https://github.com/shumaiOne/shumai/pull/201))
- **agent**: Include skill id in formatSkillsForPrompt ([#205](https://github.com/shumaiOne/shumai/pull/205))
- **asset**: Exclude soft-deleted children from latestChildren preview ([#206](https://github.com/shumaiOne/shumai/pull/206))
- **agent**: Pass latest version asset from version stack to prompt builder ([#207](https://github.com/shumaiOne/shumai/pull/207))
</Update>
<Update label="v0.1.10" description="July 16, 2026">
### Added
- **workflow-e2e**: Add E2E tests for agentAutofillMedia workflow ([#188](https://github.com/shumaiOne/shumai/pull/188))
- **comments**: Support comment deletion and video player shortcuts ([#191](https://github.com/shumaiOne/shumai/pull/191))
- **agent**: Support disabling specific tools for agents ([#192](https://github.com/shumaiOne/shumai/pull/192))
### Maintenance
- **e2e**: Add E2E workflow tests for remaining agent and transcode services ([#189](https://github.com/shumaiOne/shumai/pull/189))
</Update>
<Update label="v0.1.9" description="July 14, 2026">
### Added
- **e2e**: Set up fullstack app-level e2e test framework and signup test case ([#184](https://github.com/shumaiOne/shumai/pull/184))
- **chat**: Chatbot UI ([#185](https://github.com/shumaiOne/shumai/pull/185))
- **agent**: Support aborting agent execution ([#186](https://github.com/shumaiOne/shumai/pull/186))
### Changed
- **api/chat**: Remove direct Prisma query from API layer ([#187](https://github.com/shumaiOne/shumai/pull/187))
</Update>
<Update label="v0.1.8" description="July 10, 2026">
### Added
- **chatbot**: Implement type-safe Chat APIs with compaction support ([#180](https://github.com/shumaiOne/shumai/pull/180))
### Fixed
- **webui**: Enable build splitting and code-split all page routes ([#183](https://github.com/shumaiOne/shumai/pull/183))
### Documentation
- **readme**: Clarify displayed file size represents original file size ([#182](https://github.com/shumaiOne/shumai/pull/182))
</Update>
<Update label="v0.1.7" description="July 6, 2026">
### Added
- **audio**: Support frame-accurate audio playback, comments, and AI safeguards ([#175](https://github.com/shumaiOne/shumai/pull/175))
- **i18n**: Localize members dialog, notifications, uploads, user menus, dates, and players ([#178](https://github.com/shumaiOne/shumai/pull/178))
- **comments**: Allow marking comments as complete or incomplete ([#179](https://github.com/shumaiOne/shumai/pull/179))
### Fixed
- **upload**: Resolve empty and generic MIME types in confirmFileUpload ([#176](https://github.com/shumaiOne/shumai/pull/176))
### Changed
- **webui**: Modularize file viewer components into registry-driven architecture ([#174](https://github.com/shumaiOne/shumai/pull/174))
### Documentation
- Improve documentation and examples for S3 compatible storage ([#177](https://github.com/shumaiOne/shumai/pull/177))
</Update>
<Update label="v0.1.6" description="July 4, 2026">
### Added
- **file-browser**: Show video duration on file card preview ([#170](https://github.com/shumaiOne/shumai/pull/170))
- **webui**: Compare versions view for version stacks ([#171](https://github.com/shumaiOne/shumai/pull/171))
### Fixed
- **webui**: Resolve conditional hooks and setState-in-render errors ([#167](https://github.com/shumaiOne/shumai/pull/167))
- **webui**: Resolve video player total frames mismatch ([#172](https://github.com/shumaiOne/shumai/pull/172))
- **version-stack**: Resolve correct latest version ID of version stack ([#173](https://github.com/shumaiOne/shumai/pull/173))
### Maintenance
- **webui**: Video player e2e framework + Safari playhead fix ([#166](https://github.com/shumaiOne/shumai/pull/166))
- **webui**: Add frame-accurate comment seek roundtrip e2e ([#168](https://github.com/shumaiOne/shumai/pull/168))
- **webui**: Verify video player restarts playback after end ([#169](https://github.com/shumaiOne/shumai/pull/169))
</Update>
<Update label="v0.1.5" description="July 2, 2026">
### Changed
- **storage**: Use original filenames for stored files ([#165](https://github.com/shumaiOne/shumai/pull/165))
### Maintenance
- **release**: Add Aliyun ACR push to release workflow ([#164](https://github.com/shumaiOne/shumai/pull/164))
</Update>
<Update label="v0.1.4" description="July 1, 2026">
### Added
- **transcode**: Change video poster resolution to 480p ([#161](https://github.com/shumaiOne/shumai/pull/161))
- **auth**: Allow setting user locale on signup ([#163](https://github.com/shumaiOne/shumai/pull/163))
### Fixed
- **webui**: Preserve video ended state by skipping playhead snap on ended ([#162](https://github.com/shumaiOne/shumai/pull/162))
</Update>
<Update label="v0.1.3" description="June 30, 2026">
### Added
- **webui**: Add i18n support using paraglide-js ([#156](https://github.com/shumaiOne/shumai/pull/156))
- **video**: Add frame-accurate video player, SMPTE timecodes, and format switcher ([#157](https://github.com/shumaiOne/shumai/pull/157))
### Fixed
- **webui**: Align video timeline duration and formatting with frameio ([#158](https://github.com/shumaiOne/shumai/pull/158))
- **webui**: Fix missing left sidebar for nested folders ([#159](https://github.com/shumaiOne/shumai/pull/159))
- **api**: Fix update team settings and make request schema type-safe ([#160](https://github.com/shumaiOne/shumai/pull/160))
</Update>
<Update label="v0.1.2" description="June 25, 2026">
### Changed
- **s3**: Remove automatic port appending to AWS_ENDPOINT_URL_S3 ([#155](https://github.com/shumaiOne/shumai/pull/155))
</Update>
<Update label="v0.1.1" description="June 23, 2026">
### Added
- **docker**: Add root entrypoint with privilege dropping for data volumes ([#151](https://github.com/shumaiOne/shumai/pull/151))
</Update>
<Update label="v0.1.0" description="June 22, 2026">
### Added
- **share**: Secure share info API and fix wrong password feedback ([#150](https://github.com/shumaiOne/shumai/pull/150))
### Fixed
- **webui**: Truncate long folder, collection, and share link names in sidebar ([#149](https://github.com/shumaiOne/shumai/pull/149))
</Update>
<Update label="v0.0.11" description="June 22, 2026">
### Added
- **cli**: Add shumai-cli and token authentication ([#144](https://github.com/shumaiOne/shumai/pull/144))
- **settings**: Use singular headers and remove collapse/counters for single agent types ([#145](https://github.com/shumaiOne/shumai/pull/145))
- **folders**: Auto expand folder tree in left sidebar on navigation ([#146](https://github.com/shumaiOne/shumai/pull/146))
- **metadata**: Add single user and multiple user custom fields ([#147](https://github.com/shumaiOne/shumai/pull/147))
### Maintenance
- **cli**: Rename npm package to @shumai-one/shumai-cli ([#148](https://github.com/shumaiOne/shumai/pull/148))
</Update>
<Update label="v0.0.10" description="June 21, 2026">
### Changed
- **web**: Dynamically register production HTML bundle routes ([#142](https://github.com/shumaiOne/shumai/pull/142))
### Documentation
- **readme**: Polish structure, correct grammar, and add dependencies table ([#143](https://github.com/shumaiOne/shumai/pull/143))
</Update>
<Update label="v0.0.9" description="June 20, 2026">
### Added
- **webui**: Show app version in avatar menu ([#139](https://github.com/shumaiOne/shumai/pull/139))
- **cli**: Add background daemonization and subcommands ([#141](https://github.com/shumaiOne/shumai/pull/141))
### Maintenance
- **release**: Add smoke tests to local release stage ([#140](https://github.com/shumaiOne/shumai/pull/140))
</Update>
<Update label="v0.0.8" description="June 19, 2026">
### Added
- **api**: Implement read-only mode for reviewers ([#122](https://github.com/shumaiOne/shumai/pull/122))
- **server**: Allow customizing server port via SHUMAI_SERVER_PORT ([#124](https://github.com/shumaiOne/shumai/pull/124))
- **embedding**: Defer embedding workflow, use transcoded assets, and execute chunks in separate activities ([#125](https://github.com/shumaiOne/shumai/pull/125))
- **webui**: Add external drag-and-drop file and folder upload support ([#126](https://github.com/shumaiOne/shumai/pull/126))
- **agent**: Implement overlapping video chunks for semantic search ([#127](https://github.com/shumaiOne/shumai/pull/127))
- **webui**: Support jumping to video timestamp from search results ([#128](https://github.com/shumaiOne/shumai/pull/128))
- **auth**: Add demo mode support ([#131](https://github.com/shumaiOne/shumai/pull/131))
- **auth**: Refine demo mode support ([#132](https://github.com/shumaiOne/shumai/pull/132))
- **webui**: Default right sidebar to collapsed for new users ([#133](https://github.com/shumaiOne/shumai/pull/133))
- **webui**: Use Shadcn Switch in toggle field and Rating component in search filter panel ([#137](https://github.com/shumaiOne/shumai/pull/137))
- **upload**: Track byte-level progress with XMLHttpRequest ([#138](https://github.com/shumaiOne/shumai/pull/138))
### Fixed
- **transcode**: Handle high-precision FPS using rational fractions ([#123](https://github.com/shumaiOne/shumai/pull/123))
- **db**: Automatically update project updatedAt on asset modification ([#129](https://github.com/shumaiOne/shumai/pull/129))
- **webui**: Use system colors for fields and improve search filter select options ([#130](https://github.com/shumaiOne/shumai/pull/130))
- **search**: Fix hasAny and hasNone operators on metadata filter ([#134](https://github.com/shumaiOne/shumai/pull/134))
- **webui**: Resolve folder tree sync, search dialog reset, and sidebar actions issues ([#136](https://github.com/shumaiOne/shumai/pull/136))
### Changed
- **webui**: Fix search dialog layout height, scroll areas, and restrict filter toggle click ([#135](https://github.com/shumaiOne/shumai/pull/135))
</Update>
<Update label="v0.0.7" description="June 17, 2026">
### Added
- **workflow**: Configure transcode and agent concurrency via environment variables ([#116](https://github.com/shumaiOne/shumai/pull/116))
- **webui**: Replace hardcoded colors with system tokens ([#119](https://github.com/shumaiOne/shumai/pull/119))
- **webui**: Replace native overflow with shadcn ScrollArea in settings ([#120](https://github.com/shumaiOne/shumai/pull/120))
- **api**: Use enum for API protocol in provider config ([#121](https://github.com/shumaiOne/shumai/pull/121))
### Fixed
- **webui**: Reload video player and reset state when switching assets ([#114](https://github.com/shumaiOne/shumai/pull/114))
### Changed
- **transcode**: Relocate TranscodeService to core and flatten API package ([#115](https://github.com/shumaiOne/shumai/pull/115))
### Documentation
- Improve and restructure shumai documentation ([#118](https://github.com/shumaiOne/shumai/pull/118))
</Update>
<Update label="v0.0.6" description="June 15, 2026">
### Added
- **sandbox**: Add pending domains support for network sandbox ([#109](https://github.com/shumaiOne/shumai/pull/109))
- **webui**: Always show right sidebar and implement left vertical carousel ([#111](https://github.com/shumaiOne/shumai/pull/111))
### Fixed
- **build**: Propagate termination signals to active child process in wrappers ([#102](https://github.com/shumaiOne/shumai/pull/102))
- **transcode**: Make deterministic transcode activity failures non-retryable in Temporal ([#104](https://github.com/shumaiOne/shumai/pull/104))
- **player**: Implement seekbar dragging and match hover highlight color ([#108](https://github.com/shumaiOne/shumai/pull/108))
- **webui**: Avoid refetching all pages on file/folder reorder ([#112](https://github.com/shumaiOne/shumai/pull/112))
- **webui**: Force video-player mime type to video/mp4 ([#113](https://github.com/shumaiOne/shumai/pull/113))
### Changed
- **webui**: Use system color design tokens in video player components ([#106](https://github.com/shumaiOne/shumai/pull/106))
- **webui**: Use requestAnimationFrame for smooth video progress bar updates ([#107](https://github.com/shumaiOne/shumai/pull/107))
- **webui**: Fetch agents in mention input list dynamically ([#110](https://github.com/shumaiOne/shumai/pull/110))
### Documentation
- **readme**: Add comprehensive README.md ([#103](https://github.com/shumaiOne/shumai/pull/103))
- **readme**: Improve remote deployment and temporal execution instructions ([#105](https://github.com/shumaiOne/shumai/pull/105))
</Update>
<Update label="v0.0.5" description="June 13, 2026">
### Added
- **npm**: Auto deploy database migrations on package start ([#101](https://github.com/shumaiOne/shumai/pull/101))
</Update>
<Update label="v0.0.4" description="June 12, 2026">
### Fixed
- **cli/docker**: Resolve global CLI external dependencies and fix Docker 404 error ([#100](https://github.com/shumaiOne/shumai/pull/100))
</Update>
<Update label="v0.0.3" description="June 12, 2026">
### Fixed
- **cli**: Resolve platform binary path resolution under nested node_modules ([#99](https://github.com/shumaiOne/shumai/pull/99))
</Update>
<Update label="v0.0.2" description="June 12, 2026">
### Fixed
- **npm**: Add repository metadata to package.json for provenance verification ([#98](https://github.com/shumaiOne/shumai/pull/98))
### Maintenance
- Add release-npm.yaml workflow ([#97](https://github.com/shumaiOne/shumai/pull/97))
</Update>
<Update label="v0.0.1" description="June 12, 2026">
### Added
- Initial release of Shumai
</Update>
+32 -5
View File
@@ -24,12 +24,13 @@ Shumai is configured via environment variables. You can define these variables i
---
## Authentication Config
## Authentication & Application Config
| Variable | Description | Example / Default |
| :------------------- | :--------------------------------------------------------------------- | :--------------------------------------------------------------- |
| `BETTER_AUTH_SECRET` | A secure, random 32-byte secret used to sign session cookies and JWTs. | Generate with `openssl rand -base64 32` |
| `BETTER_AUTH_URL` | The public URL of your Hono backend API. Used for redirect flows. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback) |
| Variable | Description | Example / Default |
| :------------------- | :--------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------- |
| `BETTER_AUTH_SECRET` | A secure, random 32-byte secret used to sign session cookies and JWTs. | Generate with `openssl rand -base64 32` |
| `BETTER_AUTH_URL` | The public URL of your Hono backend API. Used for redirect flows and notification email links fallback. | `http://localhost:3000` (respects `SHUMAI_SERVER_PORT` fallback) |
| `APP_URL` | The public URL of the web application. Used for notification email deep links (falls back to `BETTER_AUTH_URL`). | `https://shumai.example.com` |
---
@@ -98,3 +99,29 @@ API keys to AI providers on startup.
| `GEMINI_API_KEY` | API key for Google Gemini provider. | `AIzaSy...` |
| `OPENAI_API_KEY` | API key for OpenAI provider. | `sk-proj-...` |
| `ANTHROPIC_API_KEY` | API key for Anthropic provider. | `sk-ant-...` |
---
## External Integrations Config
Environment variables can configure external microservices globally. When set, these environment variables take precedence over any team-level settings configured in **Team Settings → Integrations**, and lock the corresponding settings fields in the WebUI to read-only.
### Gotenberg Document Converter
Used to convert Office documents, HTML, Markdown, and CSV files into high-fidelity PDF proxies for in-browser previewing. See the [Gotenberg Guide](/using-shumai/gotenberg) for setup instructions.
| Variable | Description | Example / Default |
| :------------------------------ | :----------------------------------------------------------------------- | :---------------------- |
| `GOTENBERG_URL` | Base URL of the external Gotenberg conversion API. | `http://gotenberg:3000` |
| `GOTENBERG_BASIC_AUTH_USERNAME` | Username when Basic Authentication is enabled on the Gotenberg instance. | `admin` |
| `GOTENBERG_BASIC_AUTH_PASSWORD` | Password when Basic Authentication is enabled on the Gotenberg instance. | `secret` |
### 3D Turntable Renderer
Used to convert 3D model files (GLB, OBJ, FBX, USD, STL, DAE) into interactive 360° turntable video proxies, posters, and hover sprites. See the [3D Asset Support Guide](/using-shumai/3d-asset-support) for setup instructions.
| Variable | Description | Example / Default |
| :--------------------------------------- | :-------------------------------------------------------------------------------------------------------------- | :------------------------------- |
| `TURNTABLE_RENDERER_URL` | Base URL of the external turntable-renderer service. | `http://turntable-renderer:3000` |
| `TURNTABLE_RENDERER_BASIC_AUTH_USERNAME` | Username when Basic Authentication is enabled on the turntable renderer (alias: `TURNTABLE_RENDERER_USERNAME`). | `admin` |
| `TURNTABLE_RENDERER_BASIC_AUTH_PASSWORD` | Password when Basic Authentication is enabled on the turntable renderer (alias: `TURNTABLE_RENDERER_PASSWORD`). | `secret` |
+233
View File
@@ -0,0 +1,233 @@
---
title: Hardware Transcoding
description: Accelerate video transcoding and reduce CPU load with GPU hardware acceleration.
---
High-resolution camera recordings, phone videos, and animation media files require proxy transcoding to play smoothly in web browsers. Shumai transcodes these assets in the background, generating a universal `180p` proxy for instant scrubbing alongside full-resolution preview streams.
Hardware-accelerated transcoding allows you to offload video encoding to a dedicated or integrated GPU, dramatically speeding up processing and freeing host CPU cores for other services.
Shumai includes a built-in usability probe that tests hardware encoders at startup, alongside automatic runtime fallback during video processing. If GPU drivers or device nodes are unavailable, or if a hardware encoder encounters hardware limits (such as resolution or dimension constraints on certain GPUs) or runtime driver errors, Shumai seamlessly falls back to software encoding (`libx264`) without failing user tasks.
---
## Supported Backends
| Backend | Hardware Platform | Container Driver / Devices |
| :-------------- | :--------------------------------- | :----------------------------------------------- |
| **`nvenc`** | NVIDIA GPUs | NVIDIA Container Toolkit (`gpu, compute, video`) |
| **`quicksync`** | Intel Integrated & Arc GPUs | `/dev/dri` render nodes |
| **`vaapi`** | AMD & Intel GPUs | `/dev/dri` render nodes |
| **`rkmpp`** | Rockchip ARM SoCs (e.g. RK3588) | `/dev/rga`, `/dev/dri`, `/dev/mpp_service` |
| **`vaapi-wsl`** | Windows Subsystem for Linux (WSL2) | `/dev/dri`, `/dev/dxg`, `/usr/lib/wsl` |
---
## Limitations
- The instructions on this page focus on **Docker Compose**. Other container orchestrators (such as Kubernetes or Podman) require equivalent device passthrough configurations.
- **Docker Desktop on macOS** runs inside a Linux virtual machine and does not support Apple Silicon VideoToolbox passthrough. (VideoToolbox hardware acceleration is supported when running Shumai natively via NPM or from source).
- Hardware transcoding produces slightly different bitrate characteristics compared to software encoding. Shumai uses adaptive variable bitrate (VBR) rate control tailored to web streaming to maintain visual fidelity.
---
## Prerequisites
### NVENC (NVIDIA)
1. Ensure the official NVIDIA graphics driver is installed on the host:
```bash
nvidia-smi
```
2. Install the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) on the host and restart Docker:
```bash
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
```
### QuickSync & VA-API (Intel / AMD)
1. Verify that the Linux kernel has initialized the Direct Rendering Infrastructure (DRI) render node:
```bash
ls -la /dev/dri
```
You should see `card0` and `renderD128` (or similar).
2. Shumai's Docker image automatically adjusts group permissions on container startup so the non-root application user can access host `/dev/dri` devices without permission errors.
#### GPU decoding
With VA-API, Shumai decodes and resizes video on the GPU as well as encoding it, so frames never leave GPU memory. This is much faster than decoding on the CPU, especially for 4K sources on integrated graphics. (Other backends currently decode on the CPU and encode on the GPU.)
Some videos automatically use CPU decoding with GPU encoding instead:
- Codecs your GPU cannot decode, such as HEVC or 10-bit video on older Intel chips. Shumai tries the GPU first and retries on the CPU within a second.
- Rotated videos, such as portrait phone recordings, so they keep the correct orientation.
- Watermarked share links and HDR sources.
If a GPU-decode attempt stops making progress for 2 minutes (some driver bugs make ffmpeg hang instead of failing), Shumai stops it and retries on the CPU. Change the limit with `SHUMAI_HW_DECODE_STALL_TIMEOUT` (in seconds).
To always decode on the CPU, set `SHUMAI_HW_DECODE=false` on the `shumai` service.
### WSL2 (Windows)
- Ensure you are running Windows 11 with WSL2 and have installed the appropriate GPU drivers on the Windows host.
- Use the `vaapi-wsl` preset which maps `/dev/dxg` and `/usr/lib/wsl` into the container.
---
## Setup with Docker Compose
Shumai uses a modular `hwaccel.transcoding.yaml` companion file to configure hardware devices.
### Step 1: Download Configuration Files
In your Shumai deployment directory, download the companion `hwaccel.transcoding.yaml` alongside `docker-compose.yaml`:
```bash
# Global / Official
curl -o hwaccel.transcoding.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/hwaccel.transcoding.yaml
# Accelerated Mirror (Mainland China)
curl -o hwaccel.transcoding.yaml https://gh-proxy.com/https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/hwaccel.transcoding.yaml
```
### Step 2: Enable Hardware Acceleration in Docker Compose
Open `docker-compose.yaml` (or `docker-compose-aliyun.yaml`), find the commented `extends` block under the `shumai` service, and uncomment it:
```yaml
services:
shumai:
# ...
# Hardware Acceleration (NVENC / QuickSync / VA-API / RKMPP)
extends:
file: hwaccel.transcoding.yaml
service: nvenc # set to one of [nvenc, quicksync, rkmpp, vaapi, vaapi-wsl]
```
Replace `nvenc` with your target backend:
- `nvenc` for NVIDIA GPUs
- `quicksync` for Intel Quick Sync
- `vaapi` for AMD or Intel VA-API
- `rkmpp` for Rockchip SoCs
- `vaapi-wsl` for WSL2 on Windows
### Step 3: Start the Stack
Restart or recreate the Shumai container:
```bash
docker compose up -d
```
---
## Single Compose File Setup (Unraid / Portainer)
If your environment or container manager does not support multi-file `extends`, you can inline the hardware configuration directly into the `shumai` service in `docker-compose.yaml`:
<AccordionGroup>
<Accordion title="NVIDIA NVENC">
```yaml
services:
shumai:
# ...
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities:
- gpu
- compute
- video
```
</Accordion>
<Accordion title="Intel QuickSync / AMD VA-API">
```yaml services: shumai: # ... devices: - /dev/dri:/dev/dri ```
</Accordion>
<Accordion title="WSL2 (Windows)">
```yaml services: shumai: # ... devices: - /dev/dri:/dev/dri - /dev/dxg:/dev/dxg volumes: -
/usr/lib/wsl:/usr/lib/wsl environment: - LIBVA_DRIVER_NAME=d3d12 ```
</Accordion>
<Accordion title="Rockchip RKMPP">
```yaml
services:
shumai:
# ...
security_opt:
- systempaths=unconfined
- apparmor=unconfined
group_add:
- video
devices:
- /dev/rga:/dev/rga
- /dev/dri:/dev/dri
- /dev/dma_heap:/dev/dma_heap
- /dev/mpp_service:/dev/mpp_service
```
</Accordion>
</AccordionGroup>
---
## Web UI Settings
In the Shumai Web UI, navigate to **Team Settings** > **Transcoding Settings**.
- **Auto (Recommended)**: Shumai automatically probes candidate hardware encoders in optimal order (`h264_nvenc` &rarr; `h264_vaapi` &rarr; `h264_qsv` &rarr; `h264_amf` &rarr; `libx264`). If hardware acceleration is unavailable, it gracefully uses software encoding.
- **Explicit Encoder**: You can pin the transcode pipeline to a specific encoder (e.g. `NVENC`, `Quick Sync`, `VA-API`).
- **Off**: Forces CPU software encoding (`libx264`) for all video jobs.
---
## Verification & Monitoring
### Check Transcode Logs
When video transcoding begins on an uploaded asset, Shumai writes a structured log indicating the chosen encoder:
```bash
docker compose logs -f shumai
```
Look for the `Starting video transcoding` log entry:
```json
{
"level": 30,
"time": 1790414665096,
"encoder": "h264_nvenc",
"hardwareAcceleration": "auto",
"inputFile": "/tmp/transcode-.../video.mp4",
"outputFile": "/tmp/transcode-.../video-180p.mp4",
"msg": "Starting video transcoding"
}
```
If hardware acceleration was successfully initialized, `encoder` will show `h264_nvenc`, `h264_vaapi`, or `h264_qsv`.
### Monitor GPU Utilization
While transcoding a video, you can observe hardware utilization on the host:
- **NVIDIA**:
```bash
nvidia-smi
# or
nvtop
```
- **Intel**:
```bash
sudo intel_gpu_top
```
- **AMD**:
```bash
sudo radeontop
```
+15 -1
View File
@@ -12,6 +12,14 @@
"light": "#F5B895",
"dark": "#A8384D"
},
"navbar": {
"links": [
{
"label": "Changelog",
"href": "/changelog"
}
]
},
"navigation": {
"groups": [
{
@@ -36,6 +44,7 @@
"using-shumai/collections",
"using-shumai/share-links",
"using-shumai/nle-and-premiere",
"using-shumai/3d-asset-support",
"using-shumai/gotenberg"
]
},
@@ -57,16 +66,21 @@
"pages": [
"using-shumai/transcode-settings",
"using-shumai/quotas-settings",
"using-shumai/email-notifications",
"using-shumai/password-reset"
]
},
{
"group": "Configuration",
"pages": ["configuration/env-variables"]
"pages": ["configuration/env-variables", "configuration/hardware-transcoding"]
},
{
"group": "Temporal Deployment",
"pages": ["configuration/temporal"]
},
{
"group": "Releases",
"pages": ["changelog"]
}
]
}
+8
View File
@@ -12,9 +12,14 @@ We support three installation options. For most administrators, **Docker Compose
Docker Compose automatically configures and spins up all required services (the web application, a database, and local storage).
1. **Download the Configuration**:
```bash
curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/docker-compose.yaml
```
> [!TIP]
> **Hardware Acceleration:** By default, the standard Compose stack uses CPU-based software transcoding. If your server has a dedicated or integrated GPU (NVIDIA, Intel, AMD, or Rockchip), see the [Hardware Transcoding Guide](/configuration/hardware-transcoding) to enable GPU acceleration via the companion `hwaccel.transcoding.yaml`.
2. **Start the Services**:
```bash
docker compose up -d
@@ -39,6 +44,9 @@ To handle media processing and security isolation, the host machine must have th
- **FFmpeg & FFprobe**: Required for video transcoding and metadata extraction.
- _macOS_: `brew install ffmpeg`
- _Linux (Ubuntu/Debian)_: `sudo apt-get install ffmpeg`
- **dcraw_emu (LibRaw)**: Required for camera RAW image decoding and preview generation.
- _macOS_: `brew install libraw`
- _Linux (Ubuntu/Debian)_: `sudo apt-get install libraw-bin`
- **Agent Sandbox Utilities**: Used to run custom automation scripts securely.
- _macOS_: `brew install ripgrep`
- _Linux (Ubuntu/Debian)_: `sudo apt-get install bubblewrap socat ripgrep`
+153
View File
@@ -0,0 +1,153 @@
---
title: 3D Asset Support with Turntable Renderer
description: Render interactive 3D model turntable previews, sprite scrubbing, and video proxies using turntable-renderer.
---
3D models and mesh assets cannot always be rendered consistently or inspected reliably across diverse client web browsers and mobile devices. Shumai integrates with [turntable-renderer](https://github.com/shumaiOne/turntable-renderer) — a standalone service that executes isolated, headless Blender 5.2 LTS subprocesses — to convert 3D model uploads into standardized, high-fidelity turntable previews.
Turntable Renderer automatically produces:
- **1080×1080 Turntable Video (`turntable.mp4`)**: A 4-second, 24-frame, 6 fps video rotating the model 360° (15° per frame) clockwise under dark studio lighting with a pure black background.
- **Poster Image (`poster.webp`)**: A crisp still poster for grid cards and immediate file display.
- **Hover Sprite Sheet (`sprite.webp`)**: A fast scrubbing sheet allowing users to rotate and inspect the model directly from the file browser on hover.
- **Interactive 3D Viewer**: A specialized web viewer featuring 360° ruler scrubbing, rotation angle control (0° to 345°), playback controls, and angle-specific review comments and visual markups.
---
## Supported File Types
When turntable-renderer is configured, Shumai automatically generates 3D turntable proxies for the following formats:
| Format / Standard | Extensions |
| --------------------------- | --------------------------------- |
| Binary glTF | `.glb` |
| Universal Scene Description | `.usd`, `.usda`, `.usdc`, `.usdz` |
| Autodesk FBX | `.fbx` |
| Wavefront OBJ | `.obj` |
| Stereolithography (STL) | `.stl` |
| COLLADA | `.dae` |
---
## Configuration
Shumai supports configuring the turntable renderer either through the **WebUI** or via **Environment Variables**.
### 1. WebUI (Team Settings → Integrations)
Team owners can configure the turntable renderer directly from the web interface:
1. Navigate to **Team Settings** from the sidebar.
2. Select the **Integrations** tab.
3. Under **3D Turntable Renderer**, enter the **Server URL** (e.g. `http://turntable-renderer:3000` or `http://localhost:3003`).
4. Enter the **Username** and **Password** if Basic Authentication is enabled on the service.
5. Click **Test Connection** to verify that Shumai can communicate with the renderer and check the detected Blender version.
6. Click **Save Changes**.
### 2. Environment Variables
You can also configure turntable-renderer globally across the system using environment variables on the machine running Shumai or the transcode workers:
| Variable | Required | Description |
| ---------------------------------------- | --------------- | ------------------------------------------------------------------------------------- |
| `TURNTABLE_RENDERER_URL` | Yes (to enable) | Base URL of the turntable renderer service, e.g. `http://turntable-renderer:3000`. |
| `TURNTABLE_RENDERER_BASIC_AUTH_USERNAME` | No | Username when Basic Authentication is enabled (alias: `TURNTABLE_RENDERER_USERNAME`). |
| `TURNTABLE_RENDERER_BASIC_AUTH_PASSWORD` | No | Password when Basic Authentication is enabled (alias: `TURNTABLE_RENDERER_PASSWORD`). |
### Configuration Priority & Read-Only Mode
> [!IMPORTANT]
> **Environment variables take highest priority.** If `TURNTABLE_RENDERER_URL` is set in your environment, Shumai will always use the environment variable configuration.
>
> When configured via environment variables, the settings in **Team Settings → Integrations** will display a **Configured via environment variables (Read-only)** badge, and the input fields will be locked to prevent accidental changes or configuration drift.
---
## Deploying Turntable Renderer
### Docker Quickstart
The easiest way to run `turntable-renderer` is using the prebuilt Docker image:
```bash
docker run -d --rm \
--name turntable-renderer \
-p 3003:3000 \
-e TURNTABLE_RENDERER_API_BASIC_AUTH_USERNAME=admin \
-e TURNTABLE_RENDERER_API_BASIC_AUTH_PASSWORD=your_password \
shumaione/turntable-renderer:latest
```
> **Note**: Host port `3003` maps to internal container port `3000`.
### Docker Compose Setup
Add a `turntable-renderer` service to your `docker-compose.yaml`:
```yaml
services:
turntable-renderer:
image: shumaione/turntable-renderer:latest
restart: unless-stopped
ports:
- '3003:3000'
environment:
TURNTABLE_RENDERER_API_BASIC_AUTH_USERNAME: admin
TURNTABLE_RENDERER_API_BASIC_AUTH_PASSWORD: your_password
```
Then point Shumai at it:
```bash
TURNTABLE_RENDERER_URL=http://localhost:3003
TURNTABLE_RENDERER_BASIC_AUTH_USERNAME=admin
TURNTABLE_RENDERER_BASIC_AUTH_PASSWORD=your_password
```
_(If both Shumai and turntable-renderer run within the same Docker Compose network, use `http://turntable-renderer:3000` as the URL)._
### GPU Acceleration
A dedicated GPU is optional — turntable-renderer's CPU rendering pipeline is fast enough for modest hardware. When a GPU is passed into the container, it is automatically detected and leveraged.
#### Intel / AMD (Open Source Drivers)
Pass the DRI render node:
```bash
docker run -d --rm \
--name turntable-renderer \
--shm-size=1gb \
-p 3003:3000 \
--device /dev/dri \
-e TURNTABLE_RENDERER_API_BASIC_AUTH_USERNAME=admin \
-e TURNTABLE_RENDERER_API_BASIC_AUTH_PASSWORD=your_password \
shumaione/turntable-renderer:latest
```
#### NVIDIA (Proprietary Drivers)
Requires host driver 580+ and the NVIDIA Container Toolkit (`--runtime nvidia`):
```bash
docker run -d --rm \
--name turntable-renderer \
--shm-size=1gb \
-p 3003:3000 \
--runtime nvidia \
--gpus all \
--device /dev/nvidia-modeset \
-e TURNTABLE_RENDERER_API_BASIC_AUTH_USERNAME=admin \
-e TURNTABLE_RENDERER_API_BASIC_AUTH_PASSWORD=your_password \
shumaione/turntable-renderer:latest
```
---
## Behavior Without Turntable Renderer
If turntable-renderer is not configured or unreachable:
- The 3D model upload completes successfully with status `processed`.
- No turntable video proxy, sprite, or poster is generated.
- The original raw 3D file is safely preserved and can be downloaded by team members.
+127
View File
@@ -0,0 +1,127 @@
---
title: Email Notifications
description: Configure team SMTP settings, deliver batched activity digest emails, and send test emails.
---
Shumai includes a built-in email notification system that delivers updates on team activities—such as comments, mentions, new asset uploads, status changes, and Kanban tasks—directly to team members' inboxes.
To prevent inbox clutter and notification fatigue, Shumai does not send emails for every single action individually. Instead, a background delivery service aggregates pending notifications and sends periodic, batched digest emails with inline thumbnails and deep links.
---
## Configuring SMTP Settings
Email notification settings are managed at the team level by **Team Owners**.
To configure outgoing mail:
1. Click on **Team Settings** in the sidebar.
2. Select the **Email Notifications** tab.
3. Turn on the **Enable Email Notifications** switch.
4. Fill in your SMTP server credentials and sender information.
5. Click **Save** or **Save and Send Test Email**.
### SMTP Server Settings
| Field | Description | Example / Default |
| :---------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------- |
| **SMTP Host** | The hostname or IP address of your outgoing SMTP server. | `smtp.example.com` or `smtp.sendgrid.net` |
| **SMTP Port** | The port used to connect to your SMTP server. | `587` (default, STARTTLS), `465` (SSL/TLS), or `25` |
| **Username** | The username or API key required to authenticate with the SMTP server. | `user@example.com` or `apikey` |
| **Password** | The authentication password or API secret. | `••••••••` |
| **SSL / TLS (SMTPS)** | Connect directly using SSL/TLS encryption. Typically required when connecting over port `465`. | `Disabled` (default) |
| **Ignore Certificate Errors** | Allows connections with self-signed, invalid, or unverified TLS certificates. Useful for local testing (e.g. Mailpit, MailHog) or private corporate relays. | `Disabled` (default) |
> [!TIP]
> **Password Retention**: When updating existing email settings, you can leave the password input blank to keep the currently stored password. For security, stored passwords are never returned in cleartext to the client.
### Sender Information
| Field | Description | Example / Default |
| :----------- | :-------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------- |
| **From** | The sender name and email address that will appear in the `From` header. Ensure your SMTP provider is authorized to send on behalf of this address. | `Shumai <noreply@example.com>` |
| **Reply-To** | _(Optional)_ An email address to receive replies if members respond directly to a notification email. | `support@example.com` |
---
## Testing SMTP Delivery
Before relying on email delivery, you can verify your configuration and credentials directly from the settings page:
1. Click **Save and Send Test Email**.
2. In the **Send Test Email** modal, verify or adjust the sender `From` address.
3. Click **Send Test Email**.
Shumai will perform an active handshake verification (`transport.verify()`) against your SMTP server and dispatch a styled test message to the email address of the currently logged-in administrator.
If the handshake or delivery fails (for example, due to an invalid password, blocked outbound port, or rejected sender address), an error toast is displayed with the exact message returned by the SMTP server.
---
## Delivery Architecture & Digest Batching
Shumai uses an asynchronous, batched architecture for email delivery:
```
[ Team Activity ]
(Comments, Uploads, Mentions, Kanban)
│
▼
[ Database Queue ] (status: pending)
│
▼ (Every 3 minutes)
[ Notification Background Job ]
│
├─ Filter recipients (check user preferences & project scope)
├─ Exclude self-actions and AI agents
├─ Group & collapse items (clusters > 3 summarized)
├─ Fetch avatars & thumbnails as inline CID attachments
│
▼
[ Nodemailer Transport ] ──> SMTP Server ──> [ Member Inboxes ]
```
### 1. Periodic Background Delivery
Notifications are queued in PostgreSQL with a `pending` status. A background job runs periodically every **3 minutes**, acquiring pending notifications using atomic queue locking (`FOR UPDATE SKIP LOCKED`). This ensures safe delivery without duplicate emails even when multiple server instances run concurrently.
### 2. Digest Bundling
Rather than sending an email immediately for each action, all notifications collected for a recipient during the 3-minute window are combined into a single digest email. This keeps team communication organized and eliminates inbox spam during heavy collaboration sessions.
### 3. Smart Activity Collapsing
When an event cluster contains a high volume of items (for example, when an editor uploads dozens of video clips at once), Shumai automatically groups and collapses the items:
- If **3 or fewer** items are in a group, each item is displayed with its individual thumbnail and details.
- If **more than 3** items are uploaded together, Shumai summarizes them into a single concise notification (e.g., _"Alice uploaded 12 new files to Project Alpha"_) with a preview of the first three file names.
### 4. Inline CID Attachments
Avatars and video/image asset thumbnails are retrieved from storage and embedded directly into the email as inline MIME attachments (`cid:...`).
Unlike external image links, inline CID attachments:
- Display immediately in desktop and mobile email clients (such as Apple Mail, Gmail, and Outlook) without being blocked by "show remote content" security warnings.
- Do not require publicly accessible S3 URLs or reverse-proxy authentication to render.
### 5. Deep Linking
Every notification card in the email includes deep-linking action buttons (such as **View Asset**, **View Project**, or **View Task**) that navigate members straight to the corresponding resource in Shumai.
To ensure links point to your public domain instead of `localhost`, configure the `APP_URL` or `BETTER_AUTH_URL` environment variable on your Shumai server:
```bash
APP_URL=https://shumai.example.com
```
---
## Member Preferences & Filtering
Email delivery respects team permissions and member choices:
- **Personal Preferences**: Team members can independently choose which types of activities they receive by opening **Team Settings > Notifications**. If a user disables notifications for a category (e.g. general comments or status updates), Shumai will not include those items in their email digests.
- **Self-Action Suppression**: Members never receive notification emails for their own comments, uploads, or task updates (unless they explicitly enable the **Your Uploads** preference to be notified when their own media transcoding completes).
- **Project Scope**: Members whose access is restricted to specific projects only receive email digests for activities within those assigned projects, unless they are explicitly `@mentioned`.
- **AI Agents**: Automated AI agent accounts are automatically excluded from receiving email notifications.
+25 -1
View File
@@ -32,7 +32,22 @@ When Gotenberg is configured, Shumai automatically generates a PDF proxy for the
## Configuration
Gotenberg support is opt-in and controlled by the following environment variables on the machine running the transcode workers:
Shumai supports configuring Gotenberg either through the **WebUI** or via **Environment Variables**.
### 1. WebUI (Team Settings → Integrations)
Team owners can configure Gotenberg directly from the web interface:
1. Navigate to **Team Settings** from the sidebar.
2. Select the **Integrations** tab.
3. Under **Gotenberg Document Converter**, enter the **Server URL** (e.g. `http://gotenberg:3000` or `http://localhost:3000`).
4. Enter the **Username** and **Password** if Basic Authentication is enabled on the service.
5. Click **Test Connection** to test communication with Gotenberg and verify its health.
6. Click **Save Changes**.
### 2. Environment Variables
Gotenberg can also be configured globally across the system using environment variables on the machine running Shumai or the transcode workers:
| Variable | Required | Description |
| ------------------------------- | --------------- | ---------------------------------------------------------------- |
@@ -40,6 +55,15 @@ Gotenberg support is opt-in and controlled by the following environment variable
| `GOTENBERG_BASIC_AUTH_USERNAME` | No | Username when Basic Authentication is enabled on Gotenberg. |
| `GOTENBERG_BASIC_AUTH_PASSWORD` | No | Password when Basic Authentication is enabled on Gotenberg. |
### Configuration Priority & Read-Only Mode
> [!IMPORTANT]
> **Environment variables take highest priority.** If `GOTENBERG_URL` is set in your environment, Shumai will always use the environment variable configuration.
>
> When configured via environment variables, the settings in **Team Settings → Integrations** will display a **Configured via environment variables (Read-only)** badge, and the input fields will be locked to prevent accidental changes or configuration drift.
### Deploying Gotenberg
### Docker Quickstart
You can start a Gotenberg container with a single command:
+8
View File
@@ -44,3 +44,11 @@ If you want to mute a specific project entirely (except for direct `@mentions` w
- The **Bell** icon in the navigation bar displays a red badge when you have unread notifications.
- Click the bell to open your notification feed panel.
- Click any notification card to mark it as read and jump directly to the relevant file and comment thread.
---
## Email Notifications
In addition to in-app notifications, Team Owners can configure outgoing SMTP settings to deliver batched activity digest emails to team members. The email delivery engine honors each member's individual notification preferences configured above.
See the [Email Notifications Guide](/using-shumai/email-notifications) for full SMTP setup instructions, test email workflows, and delivery architecture details.
+61 -15
View File
@@ -1,31 +1,77 @@
---
title: Media Transcoding Settings
description: Configure video transcode strategies and preview proxy generation.
title: Video Transcoding
description: Configure video transcode policies, MP4 and HLS streaming resolutions, hardware acceleration, and FFmpeg threads.
---
High-resolution camera formats and raw media files cannot be rendered natively in web browsers. Shumai transcodes these assets into web-friendly streaming formats in the background.
High-resolution camera formats and raw media files cannot be rendered natively in web browsers. Shumai transcodes video assets into web-friendly streaming and preview formats in the background.
Team Owners can customize video transcoding behavior from the **Team Settings > Video Transcoding** page.
Regardless of the selected transcoding strategy, Shumai's pipeline will **always** generate at least one lightweight `180p` proxy version of the raw file to ensure fast scrubbing, thumbnail generation, and instant previews.
---
## Video Transcode Strategies
## Transcode Policy
Team Owners can select how the transcoding engine handles uploaded files. Shumai evaluates the original file's dimensions against its standard target resolutions (2160p, 1080p, 720p, 540p, and 360p) to determine the output.
The **Transcode Policy** card configures both MP4 video transcoding and HLS adaptive streaming.
### 1. Best Match
### Playback and Download Behavior
- **Behavior**: Shumai checks the longest dimension (width or height) of the uploaded file. It then finds the highest standard resolution that is equal to or smaller than the original file, preventing unnecessary upscaling. If the original video is exceptionally small, it defaults to a minimum target of `360p`.
- **Output**: Generates exactly two web-optimized files: the universal `180p` proxy and the single calculated "best match" resolution.
- **Use Case**: This is the recommended option. It ensures web compatibility without wasting processing time and storage space on redundant lower-resolution versions.
Shumai uses a dual-format strategy for video delivery:
### 2. Transcode All
- **When HLS is disabled**: Both in-browser video playback and file downloads will use the generated MP4 file(s).
- **When HLS is enabled**: In-browser video playback uses HLS (HTTP Live Streaming) for smooth, adaptive bitrate playback, while file downloads will use the generated MP4 file(s).
- **Behavior**: Shumai calculates the "best match" resolution exactly as it does in the previous strategy. However, instead of stopping at one version, it processes the video into the best match _and_ every standard resolution smaller than it.
- **Output**: Generates a full cascade of files. For example, if the best match for an upload is `1080p`, Shumai will generate the `180p` proxy, `1080p`, `720p`, `540p`, and `360p` versions.
- **Use Case**: Ideal for environments requiring adaptive bitrate streaming, ensuring consistent playback performance across all client devices regardless of varying network conditions.
<Warning>
**Storage Usage Notice**: Enabling HLS generates multi-bitrate segment files (`.ts` / `.m4s`) and
playlist manifests in addition to standard MP4 proxies. This can significantly increase storage
consumption on your storage bucket.
</Warning>
![Transcode Settings](../transcode.webp)
### MP4 Transcoding
Generate web-compatible MP4 files for file downloads and standard video playback. Team Owners can select how MP4 transcodes are generated for uploaded files:
#### 1. Best Match
- **Behavior**: Shumai checks the longest dimension of the uploaded video and generates a single optimal resolution matching or smaller than the source quality, preventing unnecessary upscaling.
- **Output**: Generates the lightweight `180p` proxy and the calculated best-match MP4 file.
- **Use Case**: Recommended default. Minimizes processing time and storage space while ensuring universal playback and download compatibility.
#### 2. Multi Resolutions
- **Behavior**: Select specific target resolution ladders to generate: `480p`, `720p`, `1080p`, `1440p`, and `2160p`. Resolutions are only generated up to the source video resolution (content is never upscaled).
- **Output**: Generates the `180p` proxy plus all selected resolution ladders that do not exceed the source resolution.
- **Use Case**: Ideal when users need to download multiple specific resolutions (e.g. 720p for fast sharing and 1080p for review).
### HLS Streaming
When **HLS Streaming** is toggled on, Shumai produces an adaptive bitrate HLS package for uploaded videos:
- **Resolution Ladders**: Configure which resolutions to generate for HLS streaming (`480p`, `720p`, `1080p`, `1440p`, `2160p`). Ladders are only generated up to the original video resolution.
- **Player Integration**: The web player will automatically stream via HLS when available, dynamically switching bitrates based on client network bandwidth.
![Video Transcoding](../transcode.webp)
---
## Hardware Acceleration
To offload encoding workloads from CPUs to GPUs, Shumai supports hardware-accelerated video encoding:
- **Disabled (Software)**: Uses the standard CPU `libx264` software encoder with Constant Rate Factor (CRF).
- **Auto Detect**: Automatically probes and leverages available GPU/hardware acceleration (NVIDIA NVENC, Intel QuickSync, AMD/Intel VA-API, Apple VideoToolbox, Rockchip RKMPP).
See the [Hardware Transcoding Guide](/configuration/hardware-transcoding) for Docker Compose configuration, GPU passthrough, and driver prerequisites.
---
## FFmpeg Threads
The **FFmpeg Threads** slider controls the maximum number of CPU threads used by FFmpeg during transcoding tasks:
- **Auto (0)**: FFmpeg automatically selects the optimal thread count based on host CPU core availability.
- **Manual (1 - 32)**: Restricts FFmpeg to a fixed number of threads, useful for throttling CPU consumption on shared worker nodes.
---
@@ -33,4 +79,4 @@ Team Owners can select how the transcoding engine handles uploaded files. Shumai
Transcoding is resource-intensive. Depending on your scaling needs, your administrator can run the transcode engine on the main server (Single-Server mode) or delegate tasks to specialized transcoding worker machines (Temporal Worker mode).
Note: In all modes, the processing machine must have the standard system media utilities (`ffmpeg` and `ffprobe`) installed.
In all modes, the processing machine must have system media utilities (`ffmpeg` and `ffprobe`) installed. See the [Temporal Deployment Guide](/configuration/temporal) for setting up distributed transcoding workers.
+4 -2
View File
@@ -1,6 +1,6 @@
{
"name": "shumai",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"repository": {
@@ -39,7 +39,9 @@
"release:patch": "bun run scripts/release.ts patch",
"release:minor": "bun run scripts/release.ts minor",
"release:major": "bun run scripts/release.ts major",
"changelog:extract": "bun run scripts/extract-changelog.ts"
"changelog:extract": "bun run scripts/extract-changelog.ts",
"docs:changelog": "bun run scripts/generate-docs-changelog.ts",
"docs:changelog:check": "bun run scripts/generate-docs-changelog.ts --check"
},
"devDependencies": {
"@eslint/js": "10.0.1",
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/agent",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+132
View File
@@ -662,6 +662,23 @@ describe('Agent Activities', () => {
const pdfPrompt = mockHarness.prompt.mock.calls[1]?.[0] ?? ''
expect(pdfPrompt).toContain('Document pages: 50')
expect(pdfPrompt).not.toContain('Video duration')
// For a 3D asset, should produce 3D Model recommendation
await autofillAiActivity({
teamId: 't1',
assetId: 'model-3',
assetName: 'robot.glb',
mediaType: 'model/gltf-binary',
images: [],
fields: [{ id: 'f1', config: { name: 'F1', type: 'text' } }],
context,
})
const modelPrompt = mockHarness.prompt.mock.calls[2]?.[0] ?? ''
expect(modelPrompt).toContain('3D Model: This asset has an orthogonal 4-view composite image')
expect(modelPrompt).toContain(
'Front view at top-left, Right side view at top-right, Back view at bottom-left, Left side view at bottom-right',
)
})
})
@@ -1170,6 +1187,43 @@ describe('Agent Database Activities Integration', () => {
expect((rootEntry as any)?.details?.thread).toBeUndefined()
})
it('should set media position to degree for 3D asset comments', async () => {
const asset3d = await prisma.asset.create({
data: {
name: 'robot.glb',
type: 'file',
status: 'processed',
mediaType: 'model/gltf-binary',
media: { proxyType: '3d' } as unknown as PrismaJson.MediaInfo,
projectId: project.id,
},
})
const comment3d = await prisma.assetComment.create({
data: {
assetId: asset3d.id,
message: 'Nice angle',
creatorId: user.id,
second: 0.5, // 45°
},
})
const sessionId = await initializeAgentSessionActivity({
teamId: team.id,
agentId: 'test-agent-id',
userCommentId: comment3d.id,
userId: user.id,
})
const storage = new DatabaseSessionStorage(sessionId)
const pathEntries = await storage.getPathToRoot(comment3d.id)
const entry = pathEntries.find((e) => e.id === comment3d.id)
expect(entry).toBeDefined()
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- test entry position parsing
expect((entry as any)?.details?.position).toEqual({ type: 'degree', degree: 45 })
})
it('should return user name and role for team member', async () => {
const info = await getUserTeamInfoActivity({
userId: user.id,
@@ -2105,5 +2159,83 @@ describe('Agent Database Activities Integration', () => {
expect(systemPromptArg).toContain('<thread id="..." reply_count="..." />')
expect(systemPromptArg).toContain('read_thread')
})
it('agentChatActivity injects # 3D Model Inspection into systemPrompt', async () => {
const user = await prisma.user.create({
data: { name: 'User_3d_Prompt', email: `prompt-3d-${Date.now()}@example.com` },
})
const team = await prisma.team.create({
data: { name: 'Team_3d_Prompt_' + Date.now() },
})
const project = await prisma.project.create({
data: { name: 'Project_3d_Prompt', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'robot.glb',
type: 'file',
status: 'processed',
mediaType: 'model/gltf-binary',
media: { proxyType: '3d' } as unknown as PrismaJson.MediaInfo,
projectId: project.id,
},
})
const comment = await prisma.assetComment.create({
data: {
assetId: asset.id,
creatorId: user.id,
message: 'Check this 3d model',
},
})
const mockSession = {
id: 'mock-session-id',
subscribe: vi.fn(),
getEntries: vi.fn().mockResolvedValue([]),
getStorage: vi.fn().mockReturnValue({ sessionId: 'mock-session-id' }),
}
const mockHarness = {
subscribe: vi.fn(),
prompt: vi.fn().mockResolvedValue({
content: [{ type: 'text', text: 'Response' }],
usage: { input: 10, output: 20 },
}),
}
vi.mocked(piAgent.createAgentSession).mockResolvedValue({
session: mockSession as unknown as Session<DatabaseSessionMetadata>,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Mock AgentHarness instance for activity test
harness: mockHarness as unknown as AgentHarness<any, any, any, any>,
})
const context = {
agent: { id: 'agent-1', provider: { name: 'google' }, modelRef: { modelId: 'gemini' } },
dbProviders: [],
teamSkills: [],
allowedDomains: [],
} as unknown as AgentExecutionContext
await agentChatActivity({
teamId: team.id,
agentId: 'agent-1',
message: 'Hello',
imageUrls: [],
projectId: project.id,
folderId: asset.id,
assetId: asset.id,
sessionId: 'mock-session-id',
userCommentId: comment.id,
userId: user.id,
context,
})
const lastCall = vi.mocked(piAgent.createAgentSession).mock.calls.at(-1)
const systemPromptArg = lastCall?.[0].systemPrompt as string
expect(systemPromptArg).toContain('# 3D Model Inspection')
expect(systemPromptArg).toContain('media_type="3d"')
expect(systemPromptArg).toContain('config3d')
expect(systemPromptArg).toContain('<position type="degree" degree="..." />')
})
})
})
+21 -3
View File
@@ -21,6 +21,7 @@ import {
import { aiUsageService } from '@shumai/core/src/ai-usage/ai-usage'
import { quotaService, QuotaExceededError } from '@shumai/core/src/quota/quota-service'
import { getProxyType } from '@shumai/core/src/utils/mime'
import { secondToDegree } from '@shumai/core/src/utils/model3d'
import {
UpdateAssetMetadataRequest,
type ShumaiMessageContext,
@@ -179,6 +180,8 @@ User messages may contain a <context> block detailing the user, active asset loc
systemPrompt += `\n\n# Comment Threads\nWhen operating in comment mode, previous top-level messages in the conversation history may contain a <thread id="..." reply_count="..." /> tag indicating an earlier discussion thread with replies. If a user's question refers to or depends on earlier comments or discussions, you can use the 'read_thread' tool with the thread ID to inspect all replies in that thread.`
}
systemPrompt += `\n\n# 3D Model Inspection\nWhen interacting with 3D model assets (media_type="3d"), you can visually inspect the asset using 'read_asset'. Calling 'read_asset' with config3d: null (or config3d: {}) returns an orthogonal 4-view composite image (Front at top-left, Right side at top-right, Back at bottom-left, Left side at bottom-right). If a <position type="degree" degree="..." /> tag is present or a specific angle is discussed, pass 'config3d: { degree: ... }' (integer 0, 15, 30, ..., 345) to inspect that view angle. If an <annotation id="..." /> tag is present on a 3D asset, pass 'annotationId' to inspect the angle with the user's visual markup drawings overlaid.`
if (agent.type === 'autofill') {
systemPrompt += `\n\n# Autofill Instructions\nWhen performing metadata autofill, inspect the asset content using the 'read_asset' tool. If 'read_asset' fails or returns an error, do not autofill any metadata and report to the user directly. Do not try anything fancy, for example downloading the file or using python/ffmpeg to extract content.`
}
@@ -564,6 +567,7 @@ export async function autofillAiActivity(params: AutofillAiParams) {
const proxyType = getProxyType(params.mediaType, params.assetName)
const isVideoOrAudio = proxyType === 'video' || proxyType === 'audio'
const isPdf = proxyType === 'pdf'
const is3d = proxyType === '3d'
if (params.duration !== undefined && params.duration > 0 && (!proxyType || isVideoOrAudio)) {
promptLines.push(
@@ -575,11 +579,16 @@ export async function autofillAiActivity(params: AutofillAiParams) {
`- Document pages: ${params.pageCount}. Recommended inspection: call read_asset with docConfig: { mode: "pages", startPage: 1, endPage: ${Math.min(params.pageCount, 20)} } or mode: "text".`,
)
}
if (is3d) {
promptLines.push(
'- 3D Model: This asset has an orthogonal 4-view composite image (2x2 grid showing Front view at top-left, Right side view at top-right, Back view at bottom-left, Left side view at bottom-right). Call read_asset to inspect the 4 views.',
)
}
promptLines.push(
'',
'Instructions:',
`1. Call the "read_asset" tool with assetId: "${params.assetId || ''}" to inspect the asset content (use imageConfig, videoConfig, or docConfig according to the media type).`,
`1. Call the "read_asset" tool with assetId: "${params.assetId || ''}" to inspect the asset content (use imageConfig, videoConfig, or docConfig according to the media type; for 3D assets, call read_asset directly to inspect the 4-view composite image).`,
'2. After analyzing the retrieved content, call the "autofill_metadata" tool to provide the extracted metadata values.',
'3. If "read_asset" fails or returns an error, do not autofill any metadata and report to the user directly. Do not try anything fancy, for example downloading the file or using python/ffmpeg to extract content.',
)
@@ -834,7 +843,9 @@ export async function initializeAgentSessionActivity(params: {
let position: ShumaiMediaPosition | undefined = undefined
if (c.second !== null && c.second !== undefined) {
if (proxyType === 'pdf') {
if (proxyType === '3d') {
position = { type: 'degree', degree: secondToDegree(c.second) }
} else if (proxyType === 'pdf') {
position = { type: 'page', page: Math.round(c.second) }
} else {
position = { type: 'time', seconds: c.second }
@@ -852,7 +863,14 @@ export async function initializeAgentSessionActivity(params: {
id: att.asset.id,
name: att.asset.name,
type: att.asset.type,
mediaType: attProxyType as 'image' | 'video' | 'pdf' | 'audio' | 'other' | undefined,
mediaType: attProxyType as
| 'image'
| 'video'
| 'pdf'
| 'audio'
| '3d'
| 'other'
| undefined,
mimeType: att.asset.mediaType || undefined,
})
}
+4
View File
@@ -154,6 +154,10 @@ export async function generateEmbeddingActivity(params: GenerateEmbeddingParams)
start.toString(),
'-i',
inputSource,
'-map',
'0:V:0',
'-map',
'0:a:0?',
'-t',
(end - start).toString(),
'-c',
@@ -350,5 +350,24 @@ describe('serializeContextToXml', () => {
'<context>\n <annotation id="test&lt;id&gt;&amp;&quot;123&quot;" />\n</context>',
)
})
it('serializes position type="degree" with integer degree attribute without seconds', () => {
const context: ShumaiMessageContext = {
currentAsset: {
id: 'ast_3d',
name: 'robot.glb',
type: 'file',
mediaType: '3d',
path: 'robot.glb',
},
position: {
type: 'degree',
degree: 45,
},
}
expect(serializeContextToXml(context)).toBe(
'<context>\n <current_asset id="ast_3d" name="robot.glb" type="file" media_type="3d" path="robot.glb" />\n <position type="degree" degree="45" />\n</context>',
)
})
})
})
@@ -4,6 +4,7 @@ import { setupTestDbHooks } from '@shumai/db/test'
import { resolveAnnotationsById } from './annotation-resolver'
import { DatabaseSessionStorage } from '../database-session-storage'
import type { SessionTreeEntry } from '@earendil-works/pi-agent-core'
import { degreeToSecond } from '@shumai/core/src/utils/model3d'
describe('resolveAnnotationsById', () => {
setupTestDbHooks()
@@ -210,6 +211,89 @@ describe('resolveAnnotationsById', () => {
])
})
it('resolves annotations and degree position timestamp from 1-on-1 chat AgentSessionEntry for 3D assets', async () => {
const user = await prisma.user.create({
data: { name: 'User 3D', email: 'user3d@test.com', password: 'pw' },
})
const team = await prisma.team.create({
data: { name: 'Team 3D' },
})
const project = await prisma.project.create({
data: { name: 'Project 3D', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'robot.glb',
type: 'file',
projectId: project.id,
status: 'uploaded',
},
})
const agentUser = await prisma.user.create({
data: { name: 'Agent 3D', email: 'agent3d@example.com', type: 'agent' },
})
const agent = await prisma.agent.create({
data: {
id: agentUser.id,
teamId: team.id,
type: 'chat',
config: { provider: 'test-provider', model: 'test-model' },
},
})
const storage = await DatabaseSessionStorage.create({
agentId: agent.id,
userId: user.id,
assetId: asset.id,
})
storage.currentMessageContext = {
currentAsset: {
id: asset.id,
name: asset.name,
type: 'file',
path: asset.name,
},
position: { type: 'degree', degree: 45 },
annotation: true,
annotations: [
{
type: 'rectangle',
x: 10,
y: 20,
width: 30,
height: 40,
},
],
}
const userEntry: SessionTreeEntry = {
type: 'message',
id: '01JTEST3DENTRY123456789',
parentId: null,
timestamp: new Date().toISOString(),
message: {
role: 'user',
content: 'Check markup at 45 degrees',
timestamp: Date.now(),
},
}
await storage.appendEntry(userEntry)
const result = await resolveAnnotationsById(asset.id, '01JTEST3DENTRY123456789')
expect(result.timestamp).toBeCloseTo(degreeToSecond(45))
expect(result.annotations).toEqual([
{
type: 'rectangle',
x: 10,
y: 20,
width: 30,
height: 40,
},
])
})
it('throws an error when AgentSessionEntry belongs to a different asset', async () => {
const user = await prisma.user.create({
data: { name: 'User', email: 'user3@test.com', password: 'pw' },
@@ -1,5 +1,6 @@
import { prisma } from '@shumai/db'
import type { ShumaiMessageContext } from '@shumai/dtos'
import { degreeToSecond } from '@shumai/core/src/utils/model3d'
export async function resolveAnnotationsById(
assetId: string,
@@ -44,7 +45,14 @@ export async function resolveAnnotationsById(
const list = details?.annotations
const annotations =
Array.isArray(list) && list.length > 0 ? (list as unknown as PrismaJson.AnnotationList) : null
const timestamp = details?.position?.type === 'time' ? details.position.seconds : null
let timestamp: number | null = null
if (details?.position?.type === 'time') {
timestamp = details.position.seconds
} else if (details?.position?.type === 'degree') {
timestamp = degreeToSecond(details.position.degree)
} else if (details?.position?.type === 'page') {
timestamp = details.position.page
}
return { annotations, timestamp }
}
+471
View File
@@ -11,6 +11,7 @@ import { s3Service } from '@shumai/core/src/s3/s3'
import { workflowService } from '@shumai/workflow-core'
import { authzService } from '@shumai/core/src/authz/authz'
import * as annotationResolver from './annotation-resolver'
import { degreeToSecond } from '@shumai/core/src/utils/model3d'
vi.mock('@shumai/db', async (importOriginal) => {
const actual = await importOriginal<typeof import('@shumai/db')>()
@@ -211,6 +212,476 @@ describe('readAssetTool', () => {
})
})
describe('3D Assets', () => {
it('should read 3D asset 4-views image and return image with quadrant layout description', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
storageKey: { key: 'raw/robot.glb' },
media: {
proxyType: '3d',
imageTranscodes: [{ key: 'proxy/views.webp' }],
},
} as unknown as Asset)
vi.mocked(s3Service.getObject).mockResolvedValue({
buffer: Buffer.from('fake-views-bytes'),
contentType: 'image/webp',
} as unknown as { buffer: Buffer; contentType: string })
const tool = createReadAssetTool('user-1')
const result = await tool.execute('call-3d', {
assetId: 'model-1',
annotationId: null,
imageConfig: null,
videoConfig: null,
docConfig: null,
})
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user-1' },
permission: 'Read',
type: 'asset',
id: 'model-1',
})
expect(s3Service.getObject).toHaveBeenCalledWith('shumai', 'proxy/views.webp')
const textItem = result.content[0] as { type: 'text'; text: string }
const imageItem = result.content[1] as { type: 'image'; data: string; mimeType: string }
expect(textItem.text).toContain('Orthogonal 4-view composite image')
expect(textItem.text).toContain('Top-Left quadrant: Front view (0°)')
expect(textItem.text).toContain('Top-Right quadrant: Right side view (90°)')
expect(textItem.text).toContain('Bottom-Left quadrant: Back view (180°)')
expect(textItem.text).toContain('Bottom-Right quadrant: Left side view (270°)')
expect(imageItem.type).toBe('image')
expect(imageItem.data).toBe(Buffer.from('fake-views-bytes').toString('base64'))
expect(result.details.key).toBe('proxy/views.webp')
})
it('should support s3KeyOnly mode for 3D assets', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
media: {
proxyType: '3d',
imageTranscodes: [{ key: 'proxy/views.webp' }],
},
} as unknown as Asset)
const tool = createReadAssetTool('user-1')
const result = await tool.execute('call-3d-s3', {
assetId: 'model-1',
annotationId: null,
s3KeyOnly: true,
imageConfig: null,
videoConfig: null,
docConfig: null,
})
expect(result.content).toHaveLength(1)
const textItem = result.content[0] as { type: 'text'; text: string }
expect(textItem.text).toContain('proxy/views.webp')
expect(textItem.text).toContain('Front view (0°)')
expect(result.details.key).toBe('proxy/views.webp')
})
it('should throw error if videoConfig is passed for 3D assets', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
media: {
proxyType: '3d',
imageTranscodes: [{ key: 'proxy/views.webp' }],
},
} as unknown as Asset)
const tool = createReadAssetTool('user-1')
await expect(
tool.execute('call-3d-err', {
assetId: 'model-1',
annotationId: null,
imageConfig: null,
videoConfig: { start: 0, end: 4, count: 4 },
docConfig: null,
}),
).rejects.toThrow(
"To inspect specific angles pass 'config3d: { degree: ... }'; do not pass videoConfig",
)
})
it('should throw error if 3D asset imageTranscodes is missing when overview is requested', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
media: {
proxyType: '3d',
imageTranscodes: [],
},
} as unknown as Asset)
const tool = createReadAssetTool('user-1')
await expect(
tool.execute('call-3d-err2', {
assetId: 'model-1',
annotationId: null,
imageConfig: null,
videoConfig: null,
docConfig: null,
}),
).rejects.toThrow('4-views image (views.webp) is missing')
})
it('should extract specific turntable frame when config3d.degree is provided', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
projectId: 'proj-1',
media: {
proxyType: '3d',
videoTranscodes: [{ key: 'proxy/turntable.mp4' }],
imageTranscodes: [{ key: 'proxy/views.webp' }],
},
} as unknown as Asset)
vi.mocked(prisma.workflowTask.create).mockResolvedValue({
id: 'task-shot-3d',
} as unknown as WorkflowTask)
vi.mocked(workflowService.executeWait).mockResolvedValue({
id: 'task-shot-3d',
status: WorkflowTaskStatus.completed,
output: {
screenshots: [{ key: 'proxy/shot-45.webp', timestamp: 0.5833 }],
},
} as unknown as WorkflowTask)
vi.mocked(s3Service.getObject).mockResolvedValue({
buffer: Buffer.from('fake-shot-45-bytes'),
contentType: 'image/webp',
} as unknown as { buffer: Buffer; contentType: string })
const tool = createReadAssetTool('user-1')
const result = await tool.execute('call-3d-degree', {
assetId: 'model-1',
annotationId: null,
config3d: { degree: 45 },
imageConfig: null,
videoConfig: null,
docConfig: null,
})
expect(prisma.workflowTask.create).toHaveBeenCalledWith({
data: expect.objectContaining({
type: WorkflowTaskType.transcode_screenshot,
assetId: 'model-1',
payload: {
projectId: 'proj-1',
screenshot: {
start: expect.any(Number),
end: expect.any(Number),
count: 1,
commentTimestamp: expect.any(Number),
annotations: undefined,
},
},
}),
})
const textItem = result.content[0] as { type: 'text'; text: string }
const imageItem = result.content[1] as { type: 'image'; data: string; mimeType: string }
expect(textItem.text).toContain('view at 45°:')
expect(imageItem.data).toBe(Buffer.from('fake-shot-45-bytes').toString('base64'))
expect(result.details.key).toBe('proxy/shot-45.webp')
})
it('should throw error when config3d.degree is not a multiple of 15 or out of range', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
media: {
proxyType: '3d',
videoTranscodes: [{ key: 'proxy/turntable.mp4' }],
},
} as unknown as Asset)
const tool = createReadAssetTool('user-1')
await expect(
tool.execute('call-3d-invalid-deg', {
assetId: 'model-1',
annotationId: null,
config3d: { degree: 40 },
imageConfig: null,
videoConfig: null,
docConfig: null,
}),
).rejects.toThrow('Invalid turntable degree: 40')
await expect(
tool.execute('call-3d-out-of-range', {
assetId: 'model-1',
annotationId: null,
config3d: { degree: 360 },
imageConfig: null,
videoConfig: null,
docConfig: null,
}),
).rejects.toThrow('Invalid turntable degree: 360')
})
it('should extract frame with overlaid markups when annotationId is provided on 3D asset', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
projectId: 'proj-1',
media: {
proxyType: '3d',
videoTranscodes: [{ key: 'proxy/turntable.mp4' }],
},
} as unknown as Asset)
vi.spyOn(annotationResolver, 'resolveAnnotationsById').mockResolvedValue({
annotations: [
{
type: 'freehand',
color: '#ff0000',
points: [
[0, 0],
[10, 10],
],
},
],
timestamp: 0.5, // 0.5s = 45°
})
vi.mocked(prisma.workflowTask.create).mockResolvedValue({
id: 'task-shot-ann',
} as unknown as WorkflowTask)
vi.mocked(workflowService.executeWait).mockResolvedValue({
id: 'task-shot-ann',
status: WorkflowTaskStatus.completed,
output: {
screenshots: [{ key: 'proxy/shot-annotated.webp', timestamp: 0.5 }],
},
} as unknown as WorkflowTask)
vi.mocked(s3Service.getObject).mockResolvedValue({
buffer: Buffer.from('fake-shot-ann-bytes'),
contentType: 'image/webp',
} as unknown as { buffer: Buffer; contentType: string })
const tool = createReadAssetTool('user-1')
const result = await tool.execute('call-3d-ann', {
assetId: 'model-1',
annotationId: 'comm-1',
config3d: null,
imageConfig: null,
videoConfig: null,
docConfig: null,
})
expect(prisma.workflowTask.create).toHaveBeenCalledWith({
data: expect.objectContaining({
type: WorkflowTaskType.transcode_screenshot,
assetId: 'model-1',
payload: {
projectId: 'proj-1',
screenshot: {
start: 0.5,
end: 0.5,
count: 1,
commentTimestamp: 0.5,
annotations: [
{
type: 'freehand',
color: '#ff0000',
points: [
[0, 0],
[10, 10],
],
},
],
},
},
}),
})
const textItem = result.content[0] as { type: 'text'; text: string }
expect(textItem.text).toContain('view at 45° with visual markups overlaid:')
expect(result.details.key).toBe('proxy/shot-annotated.webp')
})
it('should extract turntable frame at resolved degree angle for 3D session annotations', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
projectId: 'proj-1',
media: {
proxyType: '3d',
videoTranscodes: [{ key: 'proxy/turntable.mp4' }],
},
} as unknown as Asset)
const expectedTime = degreeToSecond(90)
vi.spyOn(annotationResolver, 'resolveAnnotationsById').mockResolvedValue({
annotations: [
{
type: 'box',
color: '#00ff00',
points: [
[10, 20],
[40, 60],
],
},
],
timestamp: expectedTime,
})
vi.mocked(prisma.workflowTask.create).mockResolvedValue({
id: 'task-shot-3d-session',
} as unknown as WorkflowTask)
vi.mocked(workflowService.executeWait).mockResolvedValue({
id: 'task-shot-3d-session',
status: WorkflowTaskStatus.completed,
output: {
screenshots: [{ key: 'proxy/shot-annotated-90.webp', timestamp: expectedTime }],
},
} as unknown as WorkflowTask)
vi.mocked(s3Service.getObject).mockResolvedValue({
buffer: Buffer.from('fake-shot-90-bytes'),
contentType: 'image/webp',
} as unknown as { buffer: Buffer; contentType: string })
const tool = createReadAssetTool('user-1')
const result = await tool.execute('call-3d-session-ann', {
assetId: 'model-1',
annotationId: 'session-entry-1',
config3d: null,
imageConfig: null,
videoConfig: null,
docConfig: null,
})
expect(prisma.workflowTask.create).toHaveBeenCalledWith({
data: expect.objectContaining({
type: WorkflowTaskType.transcode_screenshot,
assetId: 'model-1',
payload: {
projectId: 'proj-1',
screenshot: {
start: expectedTime,
end: expectedTime,
count: 1,
commentTimestamp: expectedTime,
annotations: [
{
type: 'box',
color: '#00ff00',
points: [
[10, 20],
[40, 60],
],
},
],
},
},
}),
})
const textItem = result.content[0] as { type: 'text'; text: string }
expect(textItem.text).toContain('view at 90° with visual markups overlaid:')
expect(result.details.key).toBe('proxy/shot-annotated-90.webp')
})
it('should throw error if config3d.degree conflicts with annotation angle', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
projectId: 'proj-1',
media: {
proxyType: '3d',
videoTranscodes: [{ key: 'proxy/turntable.mp4' }],
},
} as unknown as Asset)
vi.spyOn(annotationResolver, 'resolveAnnotationsById').mockResolvedValue({
annotations: [
{
type: 'box',
color: '#ff0000',
points: [
[0, 0],
[10, 10],
],
},
],
timestamp: 0.5, // 45°
})
const tool = createReadAssetTool('user-1')
await expect(
tool.execute('call-3d-conflict', {
assetId: 'model-1',
annotationId: 'comm-1',
config3d: { degree: 90 }, // Conflicts with 45°
imageConfig: null,
videoConfig: null,
docConfig: null,
}),
).rejects.toThrow(
'Annotation "comm-1" was drawn at 45°, but degree 90° was specified. Do not pass a conflicting degree with annotationId.',
)
})
it('should throw error if 3D asset turntable video is missing when angle inspection is requested', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
vi.mocked(prisma.asset.findUnique).mockResolvedValue({
id: 'model-1',
name: 'robot.glb',
mediaType: 'model/gltf-binary',
media: {
proxyType: '3d',
videoTranscodes: [],
},
} as unknown as Asset)
const tool = createReadAssetTool('user-1')
await expect(
tool.execute('call-3d-missing-turntable', {
assetId: 'model-1',
annotationId: null,
config3d: { degree: 45 },
imageConfig: null,
videoConfig: null,
docConfig: null,
}),
).rejects.toThrow('turntable video (turntable.mp4) is missing')
})
})
describe('Video Assets', () => {
it('should throw error if videoConfig is missing for video assets', async () => {
vi.mocked(authzService.hasPermission).mockResolvedValue()
+237 -3
View File
@@ -7,6 +7,12 @@ import { workflowService } from '@shumai/workflow-core'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { resolveAnnotationsById } from './annotation-resolver'
import { getFileMimeType } from '@shumai/core/src/utils/file-mime'
import { is3dModel } from '@shumai/core/src/utils/mime'
import {
isValidTurntableDegree,
secondToDegree,
degreeToSecond,
} from '@shumai/core/src/utils/model3d'
export const readAssetSchema = Type.Object(
{
@@ -37,6 +43,31 @@ export const readAssetSchema = Type.Object(
),
Type.Null(),
]),
config3d: Type.Optional(
Type.Union([
Type.Object(
{
degree: Type.Optional(
Type.Union([
Type.Integer({
minimum: 0,
maximum: 345,
description:
'Turntable rotation degree (integer: 0, 15, 30, ..., 345 in 15° increments) to inspect a specific angle of a 3D model. Leave null/omitted to view the 4-view composite overview.',
}),
Type.Null(),
]),
),
},
{
additionalProperties: false,
description:
'Configuration for 3D model assets. Pass null if inspecting another asset type. Optionally pass degree to inspect a specific turntable angle, or leave null/omitted to view the 4-view composite overview.',
},
),
Type.Null(),
]),
),
videoConfig: Type.Union([
Type.Object(
{
@@ -167,12 +198,12 @@ export function createReadAssetTool(
label: 'Read Asset',
description:
'Inspects and reads the content of an asset in the workspace. ' +
'Supports visual analysis for images, video frame extraction, PDF page rendering, and direct text reading for text/markdown files. ' +
'Pass assetId, and provide the specific config (imageConfig, videoConfig, or docConfig) while setting unused configs to null. ' +
'Supports visual analysis for images, 3D models (overview or specific degree angle), video frame extraction, PDF page rendering, and direct text reading for text/markdown files. ' +
'Pass assetId, and provide the specific config (imageConfig, config3d, videoConfig, or docConfig) while setting unused configs to null. ' +
'Optionally provide annotationId to view visual markups drawn on the asset.',
parameters: readAssetSchema,
execute: async (_toolCallId, params) => {
const { assetId, annotationId, s3KeyOnly, videoConfig, docConfig } = params
const { assetId, annotationId, s3KeyOnly, config3d, videoConfig, docConfig } = params
if (agentType === 'autofill' && !userId) {
if (!targetAssetId) {
@@ -243,6 +274,209 @@ export function createReadAssetTool(
const filename = asset.name?.toLowerCase() || ''
const bucket = process.env.S3_BUCKET || 'shumai'
// ----------------------------------------------------------------------
// Branch 0: 3D Assets (Orthogonal 4-View Composite Image or Degree Angle)
// ----------------------------------------------------------------------
const is3d = proxyType === '3d' || is3dModel(mediaType, filename)
if (is3d) {
if (videoConfig) {
throw new Error(
`Asset ${asset.id} is a 3D model. To inspect specific angles pass 'config3d: { degree: ... }'; do not pass videoConfig.`,
)
}
if (config3d?.degree !== undefined && config3d?.degree !== null) {
if (!isValidTurntableDegree(config3d.degree)) {
throw new Error(
`Invalid turntable degree: ${config3d.degree}. Degree must be an integer multiple of 15 between 0 and 345 (e.g. 0, 15, 30, 45, ..., 345).`,
)
}
}
let annotations: PrismaJson.AnnotationList | null = null
let commentTimestamp: number | null = null
if (annotationId) {
const resolved = await resolveAnnotationsById(asset.id, annotationId)
annotations = resolved.annotations
commentTimestamp = resolved.timestamp
if (commentTimestamp !== null && commentTimestamp !== undefined) {
const commentDegree = secondToDegree(commentTimestamp)
if (
config3d?.degree !== undefined &&
config3d?.degree !== null &&
config3d.degree !== commentDegree
) {
throw new Error(
`Annotation "${annotationId}" was drawn at ${commentDegree}°, but degree ${config3d.degree}° was specified. Do not pass a conflicting degree with annotationId.`,
)
}
}
}
if ((config3d?.degree !== undefined && config3d?.degree !== null) || annotationId) {
if (!mediaInfo?.videoTranscodes || mediaInfo.videoTranscodes.length === 0) {
throw new Error(
`Asset ${asset.id} is a 3D model, but its turntable video (turntable.mp4) is missing.`,
)
}
let targetDegree: number
let targetSecond: number
if (config3d?.degree !== undefined && config3d?.degree !== null) {
targetDegree = config3d.degree
targetSecond = degreeToSecond(targetDegree)
} else {
targetSecond =
commentTimestamp !== null && commentTimestamp !== undefined ? commentTimestamp : 0
targetDegree = secondToDegree(targetSecond)
}
const task = await prisma.workflowTask.create({
data: {
assetId: asset.id,
projectId: asset.projectId || 'none',
type: WorkflowTaskType.transcode_screenshot,
status: WorkflowTaskStatus.pending,
payload: {
projectId: asset.projectId || 'none',
screenshot: {
start: targetSecond,
end: targetSecond,
count: 1,
commentTimestamp: targetSecond,
annotations: annotations ?? undefined,
},
},
},
})
const completedTask = await workflowService.executeWait(task)
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- transcode screenshot output
const output = completedTask.output as any
const screenshots = output?.screenshots as
| Array<{ key: string; timestamp: number }>
| undefined
if (!screenshots || screenshots.length === 0) {
throw new Error(
`Failed to extract 3D turntable frame for asset ${asset.id} at ${targetDegree}°.`,
)
}
const shotKey = screenshots[0].key
const downloadUrl = await s3Service.presign(
bucket,
shotKey,
'GET',
true,
asset.name || undefined,
)
const content: Array<TextContent | ImageContent> = []
const hasMarkup = Boolean(annotations && annotations.length > 0)
const textDescription = hasMarkup
? `3D asset "${asset.name}" (ID: ${asset.id}, S3 Key: "${shotKey}") view at ${targetDegree}° with visual markups overlaid:`
: `3D asset "${asset.name}" (ID: ${asset.id}, S3 Key: "${shotKey}") view at ${targetDegree}°:`
if (s3KeyOnly) {
content.push({
type: 'text',
text: textDescription,
})
} else {
const { buffer, contentType } = await s3Service.getObject(bucket, shotKey)
const actualMimeType =
contentType && contentType !== 'application/octet-stream' ? contentType : 'image/webp'
content.push({
type: 'text',
text: textDescription,
})
content.push({
type: 'image',
data: buffer.toString('base64'),
mimeType: actualMimeType,
})
}
return {
content,
details: {
assetId: asset.id,
name: asset.name,
mediaType: asset.mediaType,
key: shotKey,
downloadUrl,
sourceKeys: [shotKey],
},
}
}
if (!mediaInfo?.imageTranscodes || mediaInfo.imageTranscodes.length === 0) {
throw new Error(
`Asset ${asset.id} is a 3D model, but its 4-views image (views.webp) is missing.`,
)
}
const mediaKey = mediaInfo.imageTranscodes[0].key
if (!mediaKey) {
throw new Error(`Asset ${asset.id} is a 3D model, but its 4-views image key is missing.`)
}
const keyToUse = mediaKey
const mimeType = 'image/webp'
const downloadUrl = await s3Service.presign(
bucket,
keyToUse,
'GET',
true,
asset.name || undefined,
)
const content: Array<TextContent | ImageContent> = []
const textDescription = [
`3D asset "${asset.name}" (ID: ${asset.id}, MIME: ${mimeType}, S3 Key: "${keyToUse}"):`,
'Orthogonal 4-view composite image (2x2 grid across 360° rotation):',
'- Top-Left quadrant: Front view (0°)',
'- Top-Right quadrant: Right side view (90°)',
'- Bottom-Left quadrant: Back view (180°)',
'- Bottom-Right quadrant: Left side view (270°)',
].join('\n')
if (s3KeyOnly) {
content.push({
type: 'text',
text: textDescription,
})
} else {
const { buffer, contentType } = await s3Service.getObject(bucket, keyToUse)
const actualMimeType =
contentType && contentType !== 'application/octet-stream' ? contentType : mimeType
content.push({
type: 'text',
text: textDescription,
})
content.push({
type: 'image',
data: buffer.toString('base64'),
mimeType: actualMimeType,
})
}
return {
content,
details: {
assetId: asset.id,
name: asset.name,
mediaType: asset.mediaType,
key: keyToUse,
downloadUrl,
sourceKeys: [keyToUse],
},
}
}
// ----------------------------------------------------------------------
// Branch 1: Image Assets
// ----------------------------------------------------------------------
@@ -129,6 +129,42 @@ describe('createReadThreadTool', () => {
expect(textContent).toContain('- [Ai Agent] (id: reply-1, has_markup: false): Agent answer')
})
it('should format 3d asset comment timestamps as degree: X°', async () => {
vi.mocked(prisma.assetComment.findUnique).mockResolvedValue({
id: 'root-3d',
message: 'Notice this angle',
creator: { name: 'Alice' },
second: 0.5,
annotation: [{ type: 'box' }],
asset: {
media: { proxyType: '3d' },
mediaType: 'model/gltf-binary',
name: 'robot.glb',
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
vi.mocked(prisma.assetComment.findMany).mockResolvedValue([
{
id: 'reply-3d-1',
message: 'Looking at back side',
creator: { name: 'Bob' },
second: 2.0,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
] as any)
const tool = createReadThreadTool()
const result = await tool.execute('call-3d', { threadId: 'root-3d' })
const textContent = (result.content[0] as { text: string }).text
expect(textContent).toContain(
'Thread Root [Alice] (id: root-3d, degree: 45°, has_markup: true): Notice this angle',
)
expect(textContent).toContain(
'- [Bob] (id: reply-3d-1, degree: 180°, has_markup: false): Looking at back side',
)
})
it('should describe threadId parameter as referencing <thread id="..." /> in <context>', () => {
const tool = createReadThreadTool()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
+26 -9
View File
@@ -1,6 +1,8 @@
import { prisma } from '@shumai/db'
import { Type } from 'typebox'
import { type AgentTool } from '@earendil-works/pi-agent-core'
import { secondToDegree } from '@shumai/core/src/utils/model3d'
import { getProxyType } from '@shumai/core/src/utils/mime'
const readThreadSchema = Type.Object({
threadId: Type.String({
@@ -9,14 +11,21 @@ const readThreadSchema = Type.Object({
}),
})
function formatCommentMeta(c: {
id: string
second?: number | null
annotation?: unknown
}): string {
function formatCommentMeta(
c: {
id: string
second?: number | null
annotation?: unknown
},
proxyType?: string,
): string {
const parts = [`id: ${c.id}`]
if (c.second !== null && c.second !== undefined) {
parts.push(`time: ${c.second}s`)
if (proxyType === '3d') {
parts.push(`degree: ${secondToDegree(c.second)}°`)
} else {
parts.push(`time: ${c.second}s`)
}
}
const hasMarkup = Boolean(c.annotation && Array.isArray(c.annotation) && c.annotation.length > 0)
parts.push(`has_markup: ${hasMarkup}`)
@@ -34,7 +43,10 @@ export const createReadThreadTool = (): AgentTool<
execute: async (_toolCallId, params) => {
const rootComment = await prisma.assetComment.findUnique({
where: { id: params.threadId },
include: { creator: true },
include: {
creator: true,
asset: { select: { media: true, mediaType: true, name: true } },
},
})
if (!rootComment) {
@@ -61,9 +73,14 @@ export const createReadThreadTool = (): AgentTool<
include: { creator: true },
})
const proxyType =
(rootComment.asset?.media as PrismaJson.MediaInfo | null)?.proxyType ||
getProxyType(rootComment.asset?.mediaType, rootComment.asset?.name) ||
undefined
const isRootAgent = rootComment.creator?.type === 'agent' || rootComment.sessionId !== null
const rootAuthor = rootComment.creator?.name || (isRootAgent ? 'Ai Agent' : 'User')
const rootMeta = formatCommentMeta(rootComment)
const rootMeta = formatCommentMeta(rootComment, proxyType)
let output = `Thread Root [${rootAuthor}] ${rootMeta}: ${rootComment.message || ''}\n\nReplies (${replies.length}):`
if (replies.length === 0) {
@@ -72,7 +89,7 @@ export const createReadThreadTool = (): AgentTool<
for (const reply of replies) {
const isAgent = reply.creator?.type === 'agent' || reply.sessionId !== null
const author = reply.creator?.name || (isAgent ? 'Ai Agent' : 'User')
const replyMeta = formatCommentMeta(reply)
const replyMeta = formatCommentMeta(reply, proxyType)
output += `\n- [${author}] ${replyMeta}: ${reply.message || ''}`
}
}
@@ -806,4 +806,89 @@ describe('Agent Chat Workflow', () => {
}),
)
})
it('should format mediaPosition as degree for 3D assets in 1-on-1 chat', async () => {
mockActivities.getAssetActivity.mockResolvedValue({
id: 'a-3d',
project: { teamId: 't1' },
type: 'file',
name: 'model.glb',
mediaType: 'model/gltf-binary',
media: { proxyType: '3d' },
parentId: null,
})
const task = await prisma.workflowTask.create({
data: {
type: 'chat',
status: 'pending',
assetId: 'a-3d',
payload: {
projectId: 'p1',
agent: {
agentId: 'b1',
prompt: 'Look at this angle',
sessionId: 'session-3d-1',
second: 0.5, // 0.5s turntable time = 45°
},
},
},
})
await agentChat(task)
expect(mockActivities.agentChatActivity).toHaveBeenCalledWith(
expect.objectContaining({
messageContext: expect.objectContaining({
position: { type: 'degree', degree: 45 },
}),
}),
)
})
it('should format mediaPosition as degree for 3D assets in comment mode', async () => {
mockActivities.getAssetActivity.mockResolvedValue({
id: 'a-3d',
project: { teamId: 't1' },
type: 'file',
name: 'model.glb',
mediaType: 'model/gltf-binary',
media: { proxyType: '3d' },
parentId: null,
})
mockActivities.getCommentActivity.mockResolvedValue({
id: 'comment-3d-1',
creatorId: 'user-c1',
message: 'Look at the back',
replyToId: null,
second: 2.0, // 2.0s = 180°
attachments: [],
})
const task = await prisma.workflowTask.create({
data: {
type: 'chat',
status: 'pending',
assetId: 'a-3d',
payload: {
projectId: 'p1',
agent: {
agentId: 'b1',
userCommentId: 'comment-3d-1',
},
},
},
})
await agentChat(task)
expect(mockActivities.agentChatActivity).toHaveBeenCalledWith(
expect.objectContaining({
messageContext: expect.objectContaining({
position: { type: 'degree', degree: 180 },
}),
}),
)
})
})
+4 -1
View File
@@ -8,6 +8,7 @@ import type {
ShumaiMediaPosition,
} from '@shumai/dtos'
import { getProxyType } from '@shumai/core/src/utils/mime'
import { secondToDegree } from '@shumai/core/src/utils/model3d'
export async function agentChat(task: WorkflowTask): Promise<void> {
const {
@@ -273,7 +274,9 @@ export async function agentChat(task: WorkflowTask): Promise<void> {
// Build position
let mediaPosition: ShumaiMediaPosition | undefined
if (commentTimestamp !== undefined && commentTimestamp !== null) {
if (proxyType === 'pdf') {
if (proxyType === '3d') {
mediaPosition = { type: 'degree', degree: secondToDegree(commentTimestamp) }
} else if (proxyType === 'pdf') {
mediaPosition = { type: 'page', page: Math.round(commentTimestamp) }
} else {
mediaPosition = { type: 'time', seconds: commentTimestamp }
@@ -211,6 +211,68 @@ describe('Agent Embedding Workflow', () => {
})
})
it('should run agent embedding workflow successfully for 3D asset using 4-views image', async () => {
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
agent: { id: 'b1' },
asset: {
id: 'model-1',
mediaType: 'model/gltf-binary',
storageKey: { key: 'raw/model.glb' },
media: {
proxyType: '3d',
imageTranscodes: [{ key: 'files/views.webp', format: 'webp' }],
},
},
chunkDuration: 60.0,
chunkOverlap: 5.0,
})
const task = await prisma.workflowTask.create({
data: {
type: 'ai_embedding',
status: 'pending',
assetId: 'model-1',
teamId: 't1',
},
})
await agentEmbeddingMedia(task)
expect(mockActivities.generateImageEmbeddingActivity).toHaveBeenCalledWith({
teamId: 't1',
assetKey: 'files/views.webp',
mediaType: 'image/webp',
})
})
it('should reject 3D asset for embeddings if imageTranscodes is missing', async () => {
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
agent: { id: 'b1' },
asset: {
id: 'model-1',
mediaType: 'model/gltf-binary',
storageKey: { key: 'raw/model.glb' },
media: {
proxyType: '3d',
imageTranscodes: [],
},
},
})
const task = await prisma.workflowTask.create({
data: {
type: 'ai_embedding',
status: 'pending',
assetId: 'model-1',
teamId: 't1',
},
})
await expect(agentEmbeddingMedia(task)).rejects.toThrow(
'unsupported media type for embeddings: model/gltf-binary',
)
})
it('should run agent embedding workflow successfully for video in chunks', async () => {
mockActivities.getEmbeddingContextActivity.mockResolvedValue({
agent: { id: 'b1' },
@@ -70,7 +70,10 @@ export async function agentEmbeddingMedia(task: WorkflowTask): Promise<void> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { asset, chunkDuration, chunkOverlap } = context as any
const isImage = asset.mediaType?.startsWith('image/')
const mediaInfo = asset.media as PrismaJson.MediaInfo | null
const is3dWithViews =
mediaInfo?.proxyType === '3d' && (mediaInfo.imageTranscodes?.length ?? 0) > 0
const isImage = asset.mediaType?.startsWith('image/') || is3dWithViews
const isVideo = asset.mediaType?.startsWith('video/')
if (!isImage && !isVideo) {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/api",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
+43
View File
@@ -774,4 +774,47 @@ describe('file api', () => {
mockGetProjectIds.mockRestore()
})
describe('GET /files/:fileId/m3u8 routes', () => {
it('returns master playlist with correct content-type', async () => {
const mockMaster = vi
.spyOn(assetService, 'getHlsMasterPlaylist')
.mockResolvedValue('#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=4628000\n1080p/index.m3u8\n')
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/asset-1/m3u8/master.m3u8')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('application/vnd.apple.mpegurl')
const text = await res.text()
expect(text).toContain('#EXTM3U')
expect(text).toContain('1080p/index.m3u8')
expect(mockMaster).toHaveBeenCalledWith({ assetId: 'asset-1' })
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user1', name: 'Test User' },
permission: Permission.Read,
type: 'asset',
id: 'asset-1',
})
mockMaster.mockRestore()
})
it('returns variant playlist with rewritten URLs', async () => {
const mockVariant = vi
.spyOn(assetService, 'getHlsVariantPlaylist')
.mockResolvedValue(
'#EXTM3U\n#EXT-X-MAP:URI="http://presigned/init.mp4"\nhttp://presigned/seg0.m4s\n',
)
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/asset-1/m3u8/1080p/index.m3u8')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('application/vnd.apple.mpegurl')
const text = await res.text()
expect(text).toContain('http://presigned/init.mp4')
expect(mockVariant).toHaveBeenCalledWith({ assetId: 'asset-1', resolution: '1080p' })
mockVariant.mockRestore()
})
})
})
+65
View File
@@ -480,5 +480,70 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json({ url })
},
)
.get('/files/:fileId/m3u8', async (c) => {
const fileId = c.req.param('fileId')
const user = c.get('user')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Asset,
id: fileId,
})
const playlist = await assetService.getHlsMasterPlaylist({ assetId: fileId })
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
})
.get('/files/:fileId/m3u8/master.m3u8', async (c) => {
const fileId = c.req.param('fileId')
const user = c.get('user')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Asset,
id: fileId,
})
const playlist = await assetService.getHlsMasterPlaylist({ assetId: fileId })
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
})
.get('/files/:fileId/m3u8/:resolution', async (c) => {
const fileId = c.req.param('fileId')
let resolution = c.req.param('resolution')
if (resolution.endsWith('.m3u8')) {
resolution = resolution.replace(/\.m3u8$/, '')
}
const user = c.get('user')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Asset,
id: fileId,
})
const playlist = await assetService.getHlsVariantPlaylist({ assetId: fileId, resolution })
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
})
.get('/files/:fileId/m3u8/:resolution/index.m3u8', async (c) => {
const fileId = c.req.param('fileId')
const resolution = c.req.param('resolution')
const user = c.get('user')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Asset,
id: fileId,
})
const playlist = await assetService.getHlsVariantPlaylist({ assetId: fileId, resolution })
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
})
export default route
+110 -7
View File
@@ -2,27 +2,34 @@ import { describe, expect, it, vi, beforeEach } from 'vitest'
import { Hono, type Context, type Next } from 'hono'
import notificationRoute from './notification'
import { notificationService } from '@shumai/core/src/notification/notification'
import { emailService } from '@shumai/core/src/notification/email'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
const mockUser = { id: 'user1', name: 'Test User', email: 'test@example.com' }
vi.mock('./middleware/auth', () => ({
authMiddleware: async (
c: Context<{ Variables: { user: { id: string; name: string } } }>,
next: Next,
) => {
c.set('user', { id: 'user1', name: 'Test User' })
authMiddleware: async (c: Context<{ Variables: { user: typeof mockUser } }>, next: Next) => {
c.set('user', mockUser)
await next()
},
}))
vi.mock('@shumai/core/src/authz/authz')
vi.mock('@shumai/core/src/notification/notification')
vi.mock('@shumai/core/src/notification/email', () => ({
emailService: {
getEmailSettings: vi.fn(),
updateEmailSettings: vi.fn(),
sendTestEmail: vi.fn(),
},
}))
vi.mock('@shumai/core/src/user-metadata/user-metadata')
describe('notification api', () => {
const app = new Hono<{ Variables: { user: { id: string; name: string } } }>()
const app = new Hono<{ Variables: { user: typeof mockUser } }>()
.use('*', async (c, next) => {
c.set('user', { id: 'user1', name: 'Test User' })
c.set('user', mockUser)
await next()
})
.route('/', notificationRoute)
@@ -155,4 +162,100 @@ describe('notification api', () => {
},
)
})
it('GET /teams/:teamId/notifications/email - requires admin and returns settings', async () => {
const mockSettings = {
enabled: true,
host: 'smtp.example.com',
port: 587,
username: 'user',
password: 'secret-password',
smtps: true,
ignoreCert: false,
from: 'noreply@example.com',
replyTo: '',
}
vi.mocked(emailService.getEmailSettings).mockResolvedValue(mockSettings)
const res = await app.request('/teams/t1/notifications/email')
expect(res.status).toBe(200)
const json = await res.json()
expect(json).toEqual(mockSettings)
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: expect.objectContaining({ id: 'user1' }),
permission: Permission.Admin,
type: ResourceType.Team,
id: 't1',
})
expect(emailService.getEmailSettings).toHaveBeenCalledWith('t1')
})
it('PUT /teams/:teamId/notifications/email - requires admin and updates settings', async () => {
const updateInput = {
enabled: true,
host: 'mail.example.com',
port: 465,
username: 'user',
password: 'new-password',
smtps: true,
ignoreCert: false,
from: 'shumai@example.com',
replyTo: 'support@example.com',
}
vi.mocked(emailService.updateEmailSettings).mockResolvedValue(updateInput)
const res = await app.request('/teams/t1/notifications/email', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(updateInput),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json).toEqual(updateInput)
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: expect.objectContaining({ id: 'user1' }),
permission: Permission.Admin,
type: ResourceType.Team,
id: 't1',
})
expect(emailService.updateEmailSettings).toHaveBeenCalledWith('t1', updateInput)
})
it('POST /teams/:teamId/notifications/email/test - requires admin and sends test email', async () => {
const testReq = {
host: 'smtp.example.com',
port: 587,
from: 'noreply@example.com',
}
vi.mocked(emailService.sendTestEmail).mockResolvedValue({
success: true,
messageId: '<test-msg-id@example.com>',
})
const res = await app.request('/teams/t1/notifications/email/test', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(testReq),
})
expect(res.status).toBe(200)
const json = await res.json()
expect(json).toEqual({
success: true,
messageId: '<test-msg-id@example.com>',
})
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: expect.objectContaining({ id: 'user1' }),
permission: Permission.Admin,
type: ResourceType.Team,
id: 't1',
})
expect(emailService.sendTestEmail).toHaveBeenCalledWith(
't1',
expect.objectContaining({ id: 'user1', email: 'test@example.com' }),
testReq,
)
})
})
+55
View File
@@ -1,11 +1,14 @@
import { zValidator } from '@hono/zod-validator'
import { Hono } from 'hono'
import { notificationService } from '@shumai/core/src/notification/notification'
import { emailService } from '@shumai/core/src/notification/email'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import {
listNotificationsRequestSchema,
markNotificationReadRequestSchema,
notificationSettingsSchema,
updateEmailNotificationSettingsSchema,
testEmailRequestSchema,
} from '@shumai/dtos'
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
import type { Prisma } from '@shumai/db'
@@ -109,5 +112,57 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json({ success: true })
},
)
.get('/teams/:teamId/notifications/email', async (c) => {
const teamId = c.req.param('teamId')
const user = c.get('user')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
const settings = await emailService.getEmailSettings(teamId)
return c.json(settings)
})
.put(
'/teams/:teamId/notifications/email',
zValidator('json', updateEmailNotificationSettingsSchema),
async (c) => {
const teamId = c.req.param('teamId')
const user = c.get('user')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
const settings = await emailService.updateEmailSettings(teamId, req)
return c.json(settings)
},
)
.post(
'/teams/:teamId/notifications/email/test',
zValidator('json', testEmailRequestSchema),
async (c) => {
const teamId = c.req.param('teamId')
const user = c.get('user')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
const result = await emailService.sendTestEmail(teamId, user, req)
return c.json(result)
},
)
export default route
+151 -9
View File
@@ -38,9 +38,12 @@ import type { AssetInfo } from '@shumai/dtos'
async function applyWatermarkToAssetMedia(
asset: AssetInfo,
watermarkMedia: PrismaJson.MediaInfo | null,
shareId?: string,
password?: string,
): Promise<AssetInfo> {
if (!asset.media) return asset
if (asset.proxyType !== 'video' && asset.proxyType !== 'image') return asset
if (asset.proxyType !== 'video' && asset.proxyType !== 'image' && asset.proxyType !== '3d')
return asset
const updatedMedia = { ...asset.media }
const bucket = process.env.S3_BUCKET || 'shumai'
@@ -55,10 +58,28 @@ async function applyWatermarkToAssetMedia(
width: vt.width ?? 0,
height: vt.height ?? 0,
size: 0,
hdr: vt.hdr,
resolution: vt.resolution,
})),
)
: []
if (watermarkMedia?.videoTranscodes && watermarkMedia.videoTranscodes.length > 0) {
if (updatedMedia.videoPreview) {
const watermarkedKey =
watermarkMedia.videoPreview?.key || watermarkMedia.videoTranscodes[0]?.key
if (watermarkedKey) {
updatedMedia.videoPreview = {
...updatedMedia.videoPreview,
key: watermarkedKey,
url: await s3Service.presign(bucket, watermarkedKey, 'GET'),
}
}
}
} else {
delete updatedMedia.videoPreview
}
updatedMedia.imageTranscodes =
watermarkMedia?.imageTranscodes && watermarkMedia.imageTranscodes.length > 0
? await Promise.all(
@@ -73,6 +94,19 @@ async function applyWatermarkToAssetMedia(
)
: []
if (watermarkMedia?.isHls && watermarkMedia.hls?.key && shareId) {
const pwQuery = password ? `?p=${encodeURIComponent(password)}` : ''
updatedMedia.isHls = true
updatedMedia.hls = {
key: watermarkMedia.hls.key,
url: `/api/shares/${shareId}/files/${asset.id}/m3u8/master.m3u8${pwQuery}`,
resolutions: watermarkMedia.hls.resolutions,
}
} else {
updatedMedia.isHls = false
delete updatedMedia.hls
}
return {
...asset,
media: updatedMedia,
@@ -169,7 +203,8 @@ const route = app
zValidator('query', sharedChildrenRequestSchema),
async (c) => {
const folderId = c.req.param('folderId')
const password = c.req.header('x-share-password')
const password =
c.req.header('x-share-password') || c.req.query('password') || c.req.query('p')
const req = c.req.valid('query')
try {
@@ -196,7 +231,7 @@ const route = app
// Resolve symlink targets once and reuse for the media lookup, so each
// item costs a single query instead of two.
const targetIds = await Promise.all(
res.data.map((item) => assetService.resolveTargetAssetId(item.id)),
res.data.map((item) => assetService.resolveLatestVersionId(item.id)),
)
const wfMap = await watermarkService.getCompletedWatermarkMediaMap(
targetIds,
@@ -205,9 +240,21 @@ const route = app
res.data = await Promise.all(
res.data.map(async (item, index) =>
applyWatermarkToAssetMedia(item, wfMap.get(targetIds[index]) ?? null),
applyWatermarkToAssetMedia(
item,
wfMap.get(targetIds[index]) ?? null,
shareLink.id,
password,
),
),
)
} else if (res.data.length > 0) {
const pwQuery = password ? `?p=${encodeURIComponent(password)}` : ''
for (const item of res.data) {
if (item.media?.isHls && item.media.hls?.key) {
item.media.hls.url = `/api/shares/${shareLink.id}/files/${item.id}/m3u8/master.m3u8${pwQuery}`
}
}
}
return c.json(res)
@@ -218,25 +265,33 @@ const route = app
)
.get('/shares/:shareId/files/:fileId', async (c) => {
const fileId = c.req.param('fileId')
const password = c.req.header('x-share-password')
const password = c.req.header('x-share-password') || c.req.query('password') || c.req.query('p')
try {
const shareLink = await shareService.verifyPublicAccess(fileId, password)
let asset = await assetService.getAsset({ assetId: fileId })
// Only video/image assets are subject to watermark protection; skip the
// Only video/image/3d assets are subject to watermark protection; skip the
// watermark lookup entirely for other media types (pdf, audio, ...).
if (
shareLink.watermarkConfigId &&
(asset.proxyType === 'video' || asset.proxyType === 'image')
(asset.proxyType === 'video' || asset.proxyType === 'image' || asset.proxyType === '3d')
) {
const targetAssetId = await assetService.resolveTargetAssetId(fileId)
const targetAssetId = await assetService.resolveLatestVersionId(fileId)
const wfMap = await watermarkService.getCompletedWatermarkMediaMap(
[targetAssetId],
shareLink.watermarkConfigId,
)
asset = await applyWatermarkToAssetMedia(asset, wfMap.get(targetAssetId) ?? null)
asset = await applyWatermarkToAssetMedia(
asset,
wfMap.get(targetAssetId) ?? null,
shareLink.id,
password,
)
} else if (asset.media?.isHls && asset.media.hls?.key) {
const pwQuery = password ? `?p=${encodeURIComponent(password)}` : ''
asset.media.hls.url = `/api/shares/${shareLink.id}/files/${asset.id}/m3u8/master.m3u8${pwQuery}`
}
return c.json(asset)
@@ -359,5 +414,92 @@ const route = app
}
},
)
.get('/shares/:shareId/files/:fileId/m3u8', async (c) => {
const fileId = c.req.param('fileId')
const password = c.req.header('x-share-password') || c.req.query('password') || c.req.query('p')
try {
const shareLink = await shareService.verifyPublicAccess(fileId, password)
const targetAssetId = await assetService.resolveLatestVersionId(fileId)
let playlist = await assetService.getHlsMasterPlaylist({
assetId: targetAssetId,
watermarkConfigId: shareLink.watermarkConfigId,
})
if (password) {
playlist = playlist.replace(
/([0-9]+p\/index\.m3u8)/g,
`$1?p=${encodeURIComponent(password)}`,
)
}
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
} catch (err) {
return handlePublicShareError(c, err)
}
})
.get('/shares/:shareId/files/:fileId/m3u8/master.m3u8', async (c) => {
const fileId = c.req.param('fileId')
const password = c.req.header('x-share-password') || c.req.query('password') || c.req.query('p')
try {
const shareLink = await shareService.verifyPublicAccess(fileId, password)
const targetAssetId = await assetService.resolveLatestVersionId(fileId)
let playlist = await assetService.getHlsMasterPlaylist({
assetId: targetAssetId,
watermarkConfigId: shareLink.watermarkConfigId,
})
if (password) {
playlist = playlist.replace(
/([0-9]+p\/index\.m3u8)/g,
`$1?p=${encodeURIComponent(password)}`,
)
}
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
} catch (err) {
return handlePublicShareError(c, err)
}
})
.get('/shares/:shareId/files/:fileId/m3u8/:resolution', async (c) => {
const fileId = c.req.param('fileId')
let resolution = c.req.param('resolution')
if (resolution.endsWith('.m3u8')) {
resolution = resolution.replace(/\.m3u8$/, '')
}
const password = c.req.header('x-share-password') || c.req.query('password') || c.req.query('p')
try {
const shareLink = await shareService.verifyPublicAccess(fileId, password)
const targetAssetId = await assetService.resolveLatestVersionId(fileId)
const playlist = await assetService.getHlsVariantPlaylist({
assetId: targetAssetId,
resolution,
watermarkConfigId: shareLink.watermarkConfigId,
})
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
} catch (err) {
return handlePublicShareError(c, err)
}
})
.get('/shares/:shareId/files/:fileId/m3u8/:resolution/index.m3u8', async (c) => {
const fileId = c.req.param('fileId')
const resolution = c.req.param('resolution')
const password = c.req.header('x-share-password') || c.req.query('password') || c.req.query('p')
try {
const shareLink = await shareService.verifyPublicAccess(fileId, password)
const targetAssetId = await assetService.resolveLatestVersionId(fileId)
const playlist = await assetService.getHlsVariantPlaylist({
assetId: targetAssetId,
resolution,
watermarkConfigId: shareLink.watermarkConfigId,
})
c.header('Content-Type', 'application/vnd.apple.mpegurl')
return c.body(playlist)
} catch (err) {
return handlePublicShareError(c, err)
}
})
export default route
+273 -1
View File
@@ -277,6 +277,12 @@ describe('Share API', () => {
},
],
imageTranscodes: [],
isHls: true,
hls: {
key: 'files/orig-hls/master.m3u8',
url: '/api/files/video-pending/m3u8/master.m3u8',
resolutions: [{ resolution: '1080p', width: 1920, height: 1080 }],
},
original: { key: 'files/orig.mp4' },
},
},
@@ -331,9 +337,11 @@ describe('Share API', () => {
size: 0,
},
])
// Pending item → original transcodes emptied
// Pending item → original transcodes emptied and HLS cleared
expect(body.data[1].media.videoTranscodes).toEqual([])
expect(body.data[1].media.imageTranscodes).toEqual([])
expect(body.data[1].media.isHls).toBe(false)
expect(body.data[1].media.hls).toBeUndefined()
// Non-media item → untouched
expect(body.data[2].media.pdfTranscode).toEqual({ url: 'u', key: 'files/doc.pdf' })
})
@@ -418,6 +426,51 @@ describe('Share API', () => {
expect(body.media.imageTranscodes).toEqual([])
})
test('serves watermarked transcodes with hdr flags preserved when watermark enabled and completed', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(
new Map([
[
'file1',
watermarkMediaInfo({
videoTranscodes: [
{ key: 'files/watermarked-1080p.mp4', width: 1920, height: 1080, hdr: false },
{ key: 'files/watermarked-1080p-hdr.mp4', width: 1920, height: 1080, hdr: true },
],
}),
],
]),
)
const res = await app.request('/shares/share1/files/file1', {
method: 'GET',
headers: { 'x-share-password': 'pass' },
})
expect(res.status).toBe(200)
const body = await res.json()
expect(body.media.videoTranscodes).toEqual([
{
id: 'files/watermarked-1080p.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-1080p.mp4',
width: 1920,
height: 1080,
size: 0,
hdr: false,
},
{
id: 'files/watermarked-1080p-hdr.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-1080p-hdr.mp4',
width: 1920,
height: 1080,
size: 0,
hdr: true,
},
])
})
test('serves empty transcode arrays while watermark transcoding is in flight', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
@@ -433,6 +486,148 @@ describe('Share API', () => {
expect(body.media.imageTranscodes).toEqual([])
})
test('clears HLS fields while watermark transcoding is in flight', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
vi.spyOn(assetService, 'getAsset').mockResolvedValue({
...videoAsset,
media: {
...videoAsset.media,
isHls: true,
hls: {
key: 'files/hls/master.m3u8',
url: '/api/files/file1/m3u8/master.m3u8',
resolutions: [{ resolution: '1080p', width: 1920, height: 1080 }],
},
},
})
const res = await app.request('/shares/share1/files/file1', {
method: 'GET',
headers: { 'x-share-password': 'pass' },
})
expect(res.status).toBe(200)
const body = await res.json()
expect(body.media.isHls).toBe(false)
expect(body.media.hls).toBeUndefined()
})
test('serves watermarked turntable video for a 3d asset when watermark enabled and completed', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
const asset3d = {
id: 'file1',
name: 'model.glb',
sizeByte: 1024,
fileCount: 0,
type: 'file',
status: 'processed',
proxyType: '3d',
media: {
proxyType: '3d',
videoPreview: {
url: 'http://s3/unwatermarked-turntable.mp4',
key: 'files/turntable.mp4',
},
videoTranscodes: [
{
id: 'orig-turntable',
url: 'http://s3/unwatermarked-turntable.mp4',
key: 'files/turntable.mp4',
width: 1080,
height: 1080,
},
],
original: { key: 'files/model.glb' },
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any
vi.spyOn(assetService, 'getAsset').mockResolvedValue(asset3d)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(
new Map([
[
'file1',
watermarkMediaInfo({
proxyType: '3d',
videoTranscodes: [
{
key: 'files/watermarked-turntable.mp4',
width: 1080,
height: 1080,
resolution: '1080p',
},
],
videoPreview: { key: 'files/watermarked-turntable.mp4', width: 1080, height: 1080 },
}),
],
]),
)
const res = await app.request('/shares/share1/files/file1', {
method: 'GET',
headers: { 'x-share-password': 'pass' },
})
expect(res.status).toBe(200)
const body = await res.json()
expect(body.media.videoTranscodes).toEqual([
{
id: 'files/watermarked-turntable.mp4',
url: 'http://s3/presigned',
key: 'files/watermarked-turntable.mp4',
width: 1080,
height: 1080,
size: 0,
resolution: '1080p',
},
])
expect(body.media.videoPreview?.url).toBe('http://s3/presigned')
expect(body.media.videoPreview?.key).toBe('files/watermarked-turntable.mp4')
})
test('strips videoPreview url and serves empty videoTranscodes for a 3d asset while watermark is in flight', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
const asset3d = {
id: 'file1',
name: 'model.glb',
sizeByte: 1024,
fileCount: 0,
type: 'file',
status: 'processed',
proxyType: '3d',
media: {
proxyType: '3d',
videoPreview: {
url: 'http://s3/unwatermarked-turntable.mp4',
key: 'files/turntable.mp4',
},
videoTranscodes: [
{
id: 'orig-turntable',
url: 'http://s3/unwatermarked-turntable.mp4',
key: 'files/turntable.mp4',
width: 1080,
height: 1080,
},
],
original: { key: 'files/model.glb' },
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any
vi.spyOn(assetService, 'getAsset').mockResolvedValue(asset3d)
vi.spyOn(watermarkService, 'getCompletedWatermarkMediaMap').mockResolvedValue(new Map())
const res = await app.request('/shares/share1/files/file1', {
method: 'GET',
headers: { 'x-share-password': 'pass' },
})
expect(res.status).toBe(200)
const body = await res.json()
expect(body.media.videoTranscodes).toEqual([])
expect(body.media.videoPreview?.url).toBeUndefined()
})
test('leaves non-video/image media untouched when watermark enabled', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue(shareLinkWithWatermark)
vi.spyOn(assetService, 'getAsset').mockResolvedValue({
@@ -821,4 +1016,81 @@ describe('Share API', () => {
expect(getDownloadUrlSpy).not.toHaveBeenCalled()
})
})
describe('GET /shares/:shareId/files/:fileId/m3u8 routes', () => {
test('returns master playlist with query password preserved in variant URLs', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
id: 'share1',
watermarkConfigId: null,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
vi.spyOn(assetService, 'getHlsMasterPlaylist').mockResolvedValue(
'#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=4628000\n1080p/index.m3u8\n',
)
const res = await app.request('/shares/share1/files/file1/m3u8/master.m3u8?p=secret123')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('application/vnd.apple.mpegurl')
const text = await res.text()
expect(text).toContain('1080p/index.m3u8?p=secret123')
expect(shareService.verifyPublicAccess).toHaveBeenCalledWith('file1', 'secret123')
expect(assetService.getHlsMasterPlaylist).toHaveBeenCalledWith({
assetId: 'file1',
watermarkConfigId: null,
})
})
test('returns variant playlist with rewritten segment URLs', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
id: 'share1',
watermarkConfigId: 'wm1',
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
vi.spyOn(assetService, 'getHlsVariantPlaylist').mockResolvedValue(
'#EXTM3U\n#EXT-X-MAP:URI="http://presigned/init.mp4"\nhttp://presigned/seg0.m4s\n',
)
const res = await app.request('/shares/share1/files/file1/m3u8/1080p/index.m3u8')
expect(res.status).toBe(200)
expect(res.headers.get('content-type')).toContain('application/vnd.apple.mpegurl')
const text = await res.text()
expect(text).toContain('http://presigned/init.mp4')
expect(assetService.getHlsVariantPlaylist).toHaveBeenCalledWith({
assetId: 'file1',
resolution: '1080p',
watermarkConfigId: 'wm1',
})
})
test('returns 401 when password is invalid', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockRejectedValue(
new ShareLinkPasswordInvalidError('Invalid password'),
)
const res = await app.request('/shares/share1/files/file1/m3u8/master.m3u8?p=wrong')
expect(res.status).toBe(401)
const body = await res.json()
expect(body.error).toBe('Unauthorized')
})
test('resolves latest version id when fileId is a symlink to a version stack', async () => {
vi.spyOn(shareService, 'verifyPublicAccess').mockResolvedValue({
id: 'share1',
watermarkConfigId: null,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any)
vi.spyOn(assetService, 'resolveLatestVersionId').mockResolvedValue('child-version-file-id')
vi.spyOn(assetService, 'getHlsMasterPlaylist').mockResolvedValue(
'#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=4628000\n1080p/index.m3u8\n',
)
const res = await app.request('/shares/share1/files/symlink1/m3u8/master.m3u8')
expect(res.status).toBe(200)
expect(assetService.resolveLatestVersionId).toHaveBeenCalledWith('symlink1')
expect(assetService.getHlsMasterPlaylist).toHaveBeenCalledWith({
assetId: 'child-version-file-id',
watermarkConfigId: null,
})
})
})
})
+267 -4
View File
@@ -52,6 +52,22 @@ vi.mock('@shumai/core/src/auditLog/auditLog', () => ({
},
}))
vi.mock('@shumai/core/src/turntable/turntable', () => ({
turntableService: {
getSettings: vi.fn(),
updateSettings: vi.fn(),
testConnection: vi.fn(),
},
}))
vi.mock('@shumai/core/src/gotenberg/gotenberg', () => ({
gotenbergService: {
getSettings: vi.fn(),
updateSettings: vi.fn(),
testConnection: vi.fn(),
},
}))
describe('team api', () => {
const app = new Hono().use('*', authMiddleware).route('/', teamRoute)
let mockCreateTeam: any // eslint-disable-line @typescript-eslint/no-explicit-any
@@ -223,18 +239,39 @@ describe('team api', () => {
expect(mockGetSettings).toHaveBeenCalledWith('t1')
})
it('GET /teams/:teamId/settings does not return emailNotification to readers', async () => {
mockGetSettings.mockResolvedValue({
semanticSearchEnabled: false,
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', threads: 0 },
appearance: { hideAgent: false },
})
const res = await app.request('/teams/t1/settings')
expect(res.status).toBe(200)
const data = await res.json()
expect(data.emailNotification).toBeUndefined()
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
type: ResourceType.Team,
id: 't1',
permission: Permission.Read,
}),
)
})
it('PATCH /teams/:teamId/settings updates settings', async () => {
mockUpdateSettings.mockResolvedValue({ transcode: { videoStrategy: 'all' } })
mockUpdateSettings.mockResolvedValue({ transcode: { videoStrategy: 'multi' } })
const res = await app.request('/teams/t1/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: 'transcode.videoStrategy', value: 'all' }),
body: JSON.stringify({ key: 'transcode.videoStrategy', value: 'multi' }),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.transcode.videoStrategy).toBe('all')
expect(data.transcode.videoStrategy).toBe('multi')
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
type: ResourceType.Team,
@@ -242,7 +279,30 @@ describe('team api', () => {
permission: Permission.Admin,
}),
)
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.videoStrategy', 'all')
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.videoStrategy', 'multi')
})
it('PATCH /teams/:teamId/settings updates transcode.videoResolutions', async () => {
mockUpdateSettings.mockResolvedValue({
transcode: { videoResolutions: ['720p', '1080p'] },
})
const res = await app.request('/teams/t1/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
key: 'transcode.videoResolutions',
value: ['720p', '1080p'],
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.transcode.videoResolutions).toEqual(['720p', '1080p'])
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'transcode.videoResolutions', [
'720p',
'1080p',
])
})
it('PATCH /teams/:teamId/settings updates transcode.hardwareAcceleration', async () => {
@@ -594,5 +654,208 @@ describe('team api', () => {
}),
)
})
it('GET /teams/:teamId/turntable-settings returns turntable settings', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.getSettings).mockResolvedValue({
url: 'http://localhost:3001',
username: 'user',
hasPassword: true,
isEnvConfigured: false,
})
const res = await app.request('/teams/t1/turntable-settings')
expect(res.status).toBe(200)
const data = await res.json()
expect(data).toEqual({
url: 'http://localhost:3001',
username: 'user',
hasPassword: true,
isEnvConfigured: false,
})
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
permission: Permission.Read,
type: ResourceType.Team,
id: 't1',
}),
)
})
it('PUT /teams/:teamId/turntable-settings updates settings when not env configured', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.updateSettings).mockResolvedValue({
url: 'http://custom:3001',
username: 'newuser',
hasPassword: true,
isEnvConfigured: false,
})
const res = await app.request('/teams/t1/turntable-settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3001',
username: 'newuser',
password: 'secretpassword',
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.url).toBe('http://custom:3001')
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
permission: Permission.Admin,
type: ResourceType.Team,
id: 't1',
}),
)
})
it('PUT /teams/:teamId/turntable-settings returns 400 when env configured', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.updateSettings).mockRejectedValue(
new Error(
'Turntable settings are configured via environment variables and cannot be edited',
),
)
const res = await app.request('/teams/t1/turntable-settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3001',
}),
})
expect(res.status).toBe(400)
const data = await res.json()
expect(data.message).toContain('configured via environment variables')
})
it('POST /teams/:teamId/turntable-settings/test tests connection', async () => {
const { turntableService } = await import('@shumai/core/src/turntable/turntable')
vi.mocked(turntableService.testConnection).mockResolvedValue({
ok: true,
version: '1.0.0',
blender: '5.2.0',
})
const res = await app.request('/teams/t1/turntable-settings/test', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3001',
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.ok).toBe(true)
expect(data.blender).toBe('5.2.0')
})
it('GET /teams/:teamId/gotenberg-settings returns gotenberg settings', async () => {
const { gotenbergService } = await import('@shumai/core/src/gotenberg/gotenberg')
vi.mocked(gotenbergService.getSettings).mockResolvedValue({
url: 'http://localhost:3000',
username: 'user',
hasPassword: true,
isEnvConfigured: false,
})
const res = await app.request('/teams/t1/gotenberg-settings')
expect(res.status).toBe(200)
const data = await res.json()
expect(data).toEqual({
url: 'http://localhost:3000',
username: 'user',
hasPassword: true,
isEnvConfigured: false,
})
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
permission: Permission.Read,
type: ResourceType.Team,
id: 't1',
}),
)
})
it('PUT /teams/:teamId/gotenberg-settings updates settings when not env configured', async () => {
const { gotenbergService } = await import('@shumai/core/src/gotenberg/gotenberg')
vi.mocked(gotenbergService.updateSettings).mockResolvedValue({
url: 'http://custom:3000',
username: 'newuser',
hasPassword: true,
isEnvConfigured: false,
})
const res = await app.request('/teams/t1/gotenberg-settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3000',
username: 'newuser',
password: 'secretpassword',
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.url).toBe('http://custom:3000')
expect(authzService.hasPermission).toHaveBeenCalledWith(
expect.objectContaining({
permission: Permission.Admin,
type: ResourceType.Team,
id: 't1',
}),
)
})
it('PUT /teams/:teamId/gotenberg-settings returns 400 when env configured', async () => {
const { gotenbergService } = await import('@shumai/core/src/gotenberg/gotenberg')
vi.mocked(gotenbergService.updateSettings).mockRejectedValue(
new Error(
'Gotenberg settings are configured via environment variables and cannot be edited',
),
)
const res = await app.request('/teams/t1/gotenberg-settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3000',
}),
})
expect(res.status).toBe(400)
const data = await res.json()
expect(data.message).toContain('configured via environment variables')
})
it('POST /teams/:teamId/gotenberg-settings/test tests connection', async () => {
const { gotenbergService } = await import('@shumai/core/src/gotenberg/gotenberg')
vi.mocked(gotenbergService.testConnection).mockResolvedValue({
ok: true,
version: '8.3.0',
})
const res = await app.request('/teams/t1/gotenberg-settings/test', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
url: 'http://custom:3000',
}),
})
expect(res.status).toBe(200)
const data = await res.json()
expect(data.ok).toBe(true)
expect(data.version).toBe('8.3.0')
})
})
})
+118
View File
@@ -10,6 +10,8 @@ import {
updateTeamSettingsRequestSchema,
listMembersQuerySchema,
updateSandboxSettingsRequestSchema,
updateTurntableSettingsRequestSchema,
updateGotenbergSettingsRequestSchema,
updateMeRequestSchema,
updateTeamMemberRoleRequestSchema,
createApiTokenRequestSchema,
@@ -23,6 +25,8 @@ import {
import { apiTokenService } from '@shumai/core/src/user/api-token'
import { aiUsageService } from '@shumai/core/src/ai-usage/ai-usage'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
import { turntableService } from '@shumai/core/src/turntable/turntable'
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
import { NotificationType } from '@shumai/db'
import type { Prisma } from '@shumai/db'
@@ -265,6 +269,120 @@ const route = new Hono<{ Variables: { user: User } }>()
return c.json(sandbox)
},
)
.get('/teams/:teamId/turntable-settings', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Team,
id: teamId,
})
const settings = await turntableService.getSettings(teamId)
return c.json(settings)
})
.put(
'/teams/:teamId/turntable-settings',
zValidator('json', updateTurntableSettingsRequestSchema),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
try {
const settings = await turntableService.updateSettings(teamId, req)
return c.json(settings)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
return c.json({ message }, 400)
}
},
)
.post(
'/teams/:teamId/turntable-settings/test',
zValidator('json', updateTurntableSettingsRequestSchema.partial()),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
const res = await turntableService.testConnection(req, teamId)
return c.json(res)
},
)
.get('/teams/:teamId/gotenberg-settings', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Team,
id: teamId,
})
const settings = await gotenbergService.getSettings(teamId)
return c.json(settings)
})
.put(
'/teams/:teamId/gotenberg-settings',
zValidator('json', updateGotenbergSettingsRequestSchema),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
try {
const settings = await gotenbergService.updateSettings(teamId, req)
return c.json(settings)
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
return c.json({ message }, 400)
}
},
)
.post(
'/teams/:teamId/gotenberg-settings/test',
zValidator('json', updateGotenbergSettingsRequestSchema.partial()),
async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
const req = c.req.valid('json')
await authzService.hasPermission({
user,
permission: Permission.Admin,
type: ResourceType.Team,
id: teamId,
})
const res = await gotenbergService.testConnection(req, teamId)
return c.json(res)
},
)
.get('/teams/:teamId/user-metadata', async (c) => {
const user = c.get('user')
const teamId = c.req.param('teamId')
+3 -1
View File
@@ -105,15 +105,17 @@ const route = new Hono<{ Variables: { user: User } }>()
await uploadService.confirmFileUpload(user.id, taskId, req)
if (!req.errorMessage) {
const context = await assetService.getAssetContext(req.fileId)
await notificationService.create({
type: NotificationType.successful_file_uploaded,
teamId: teamId,
projectId: context.projectId,
creatorId: user.id,
assetId: req.fileId,
taskId: taskId,
})
const context = await assetService.getAssetContext(req.fileId)
await auditLogService.logAction({
action: AuditAction.file_create,
teamId: teamId,
+6 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/core",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
@@ -33,6 +33,8 @@
"@shumai/db": "workspace:*",
"@shumai/dtos": "workspace:*",
"@sinclair/typebox": "0.34.52",
"@temporalio/activity": "1.24.0",
"@temporalio/workflow": "1.24.0",
"adm-zip": "0.6.0",
"ai": "7.0.84",
"better-auth": "1.6.11",
@@ -40,9 +42,11 @@
"date-fns": "4.4.0",
"dotenv": "17.4.2",
"dotenv-expand": "13.0.0",
"exiftool-vendored": "38.1.0",
"extract-zip": "2.0.1",
"hono": "4.13.5",
"jittered-fractional-indexing": "1.0.1",
"nodemailer": "10.0.10",
"pdfkit": "0.20.1",
"pino": "10.3.1",
"sharp": "0.35.4",
@@ -56,6 +60,7 @@
"@modelcontextprotocol/server": "2.0.0",
"@types/adm-zip": "0.5.8",
"@types/extract-zip": "2.0.3",
"@types/nodemailer": "8.0.2",
"@types/pdfkit": "0.17.6"
}
}
+138
View File
@@ -16,6 +16,7 @@ vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: {
presign: vi.fn().mockResolvedValue('http://mock-s3-url'),
putObject: vi.fn().mockResolvedValue(undefined),
getObject: vi.fn().mockResolvedValue({ buffer: Buffer.from('') }),
deleteObject: vi.fn().mockResolvedValue(1),
deletePrefix: vi.fn().mockResolvedValue(1),
copyObject: vi.fn().mockResolvedValue(undefined),
@@ -1930,6 +1931,36 @@ describe('AssetService', () => {
expect(info.preview?.duration).toBeUndefined()
})
it('toPreviewInfo handles 3d asset with proxyType 3d and omits duration', async () => {
const { project, user } = await setupBasicAssets()
const model = await prisma.asset.create({
data: {
name: 'model.glb',
type: AssetType.file,
projectId: project.id,
creatorId: user.id,
sizeByte: 8000,
mediaType: 'model/gltf-binary',
status: 'processed',
media: {
proxyType: '3d',
poster: { key: 'poster-key' },
sprite: { key: 'sprite-key', frames: 100, tileX: 10, tileY: 10 },
metadata: { originalWidth: 1080, originalHeight: 1080, duration: 4 },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
},
})
const info = await assetService.getAsset({ assetId: model.id })
expect(info.preview).toBeDefined()
expect(info.preview?.proxyType).toBe('3d')
expect(info.preview?.duration).toBeUndefined()
expect(info.preview?.spriteUrl).toBeDefined()
})
it('converts webp thumbnail to jpeg on demand when hasJpegPreview is false', async () => {
vi.mocked(ensureJpegInStorage).mockClear()
const { project, user } = await setupBasicAssets()
@@ -5251,4 +5282,111 @@ describe('AssetService — natural sort by name', () => {
expect(restored?.status).toBe(AssetStatus.processed)
})
})
describe('HLS playlists', () => {
const setupHlsAssets = async () => {
const team = await prisma.team.create({ data: { name: 'hls-team-' + Date.now() } })
const project = await prisma.project.create({
data: { name: 'hls-proj-' + Date.now(), teamId: team.id },
})
const rootFolder = await prisma.asset.create({
data: {
name: 'root',
type: AssetType.folder,
projectId: project.id,
status: AssetStatus.processed,
},
})
return { team, project, rootFolder }
}
it('getHlsMasterPlaylist throws 404 if asset is not HLS', async () => {
const { project, rootFolder } = await setupHlsAssets()
const file = await prisma.asset.create({
data: {
name: 'regular.mp4',
type: AssetType.file,
projectId: project.id,
parentId: rootFolder.id,
status: AssetStatus.processed,
media: {
isHls: false,
} as PrismaJson.MediaInfo,
},
})
await expect(assetService.getHlsMasterPlaylist({ assetId: file.id })).rejects.toThrow(
'HLS playlist not found',
)
})
it('getHlsMasterPlaylist returns playlist string when asset is HLS', async () => {
const { project, rootFolder } = await setupHlsAssets()
const file = await prisma.asset.create({
data: {
name: 'hls-video.mp4',
type: AssetType.file,
projectId: project.id,
parentId: rootFolder.id,
status: AssetStatus.processed,
media: {
isHls: true,
hls: {
key: 'files/asset/hls/master.m3u8',
resolutions: [
{ resolution: '1080p', width: 1920, height: 1080 },
{ resolution: '720p', width: 1280, height: 720 },
],
},
} as PrismaJson.MediaInfo,
},
})
const masterContent = '#EXTM3U\n#EXT-X-STREAM-INF:BANDWIDTH=4628000\n1080p/index.m3u8\n'
vi.mocked(s3Service.getObject).mockResolvedValueOnce({
buffer: Buffer.from(masterContent),
} as unknown as Awaited<ReturnType<typeof s3Service.getObject>>)
const res = await assetService.getHlsMasterPlaylist({ assetId: file.id })
expect(res).toBe(masterContent)
expect(s3Service.getObject).toHaveBeenCalledWith(
expect.any(String),
'files/asset/hls/master.m3u8',
)
})
it('getHlsVariantPlaylist fetches and rewrites segment URLs', async () => {
const { project, rootFolder } = await setupHlsAssets()
const file = await prisma.asset.create({
data: {
name: 'hls-video.mp4',
type: AssetType.file,
projectId: project.id,
parentId: rootFolder.id,
status: AssetStatus.processed,
media: {
isHls: true,
hls: {
key: 'files/asset/hls/master.m3u8',
resolutions: [{ resolution: '1080p', width: 1920, height: 1080 }],
},
} as PrismaJson.MediaInfo,
},
})
const sampleVariant = '#EXTM3U\n#EXT-X-MAP:URI="init.mp4"\nsegment_000.m4s\n'
vi.mocked(s3Service.getObject).mockResolvedValueOnce({
buffer: Buffer.from(sampleVariant),
} as unknown as Awaited<ReturnType<typeof s3Service.getObject>>)
vi.mocked(s3Service.presign).mockResolvedValue('http://mock-s3-url')
const variant = await assetService.getHlsVariantPlaylist({
assetId: file.id,
resolution: '1080p',
})
expect(variant).toBeDefined()
expect(variant).toContain('#EXT-X-MAP:URI="http://mock-s3-url"')
expect(variant).toContain('http://mock-s3-url')
})
})
})
+108 -3
View File
@@ -57,6 +57,7 @@ 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'
import { rewriteM3u8WithPresignedUrls } from '@shumai/core/src/transcode/transcode'
export const assetInclude = {
creator: true,
@@ -2386,6 +2387,9 @@ export class AssetService {
'GET',
)
}
if (media && media.isHls && media.hls?.key) {
media.hls.url = `/api/files/${latestVersion.id}/m3u8/master.m3u8`
}
const key = latestVersion.storageKey?.key
if (key) {
@@ -2403,7 +2407,13 @@ export class AssetService {
}
}
const proxyType = (media?.proxyType || null) as 'image' | 'video' | 'audio' | 'pdf' | null
const proxyType = (media?.proxyType || null) as
| 'image'
| 'video'
| 'audio'
| 'pdf'
| '3d'
| null
result.push({
id: a.id,
@@ -2769,7 +2779,13 @@ export class AssetService {
): Promise<PreviewInfo | null> {
if (!asset.media) return null
const proxyType = (asset.media?.proxyType || null) as 'image' | 'video' | 'audio' | 'pdf' | null
const proxyType = (asset.media?.proxyType || null) as
| 'image'
| 'video'
| 'audio'
| 'pdf'
| '3d'
| null
let rawThumbKey: string | undefined
if (proxyType === 'image' && asset.media.thumbnail?.key) {
@@ -2822,7 +2838,7 @@ export class AssetService {
originalHeight: asset.media.metadata?.originalHeight,
originalWidth: asset.media.metadata?.originalWidth,
spriteUrl,
duration: asset.media.metadata?.duration,
duration: proxyType === '3d' ? undefined : asset.media.metadata?.duration,
pageCount: asset.media.metadata?.totalFrames,
}
}
@@ -3196,6 +3212,95 @@ export class AssetService {
req,
)
}
async getHlsMasterPlaylist(params: {
assetId: string
watermarkConfigId?: string | null
}): Promise<string> {
const bucket = process.env.S3_BUCKET || 'shumai'
const targetAssetId = await this.resolveLatestVersionId(params.assetId)
if (params.watermarkConfigId) {
const wf = await this.prismaClient.watermarkFile.findUnique({
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention
assetId_watermarkConfigId: {
assetId: targetAssetId,
watermarkConfigId: params.watermarkConfigId,
},
},
})
const media = wf?.media as PrismaJson.MediaInfo | null
if (!media?.isHls || !media.hls?.key) {
throw new HTTPException(404, { message: 'HLS playlist not found' })
}
const obj = await s3Service.getObject(bucket, media.hls.key)
return obj.buffer.toString('utf-8')
}
const asset = await this.prismaClient.asset.findUnique({
where: { id: targetAssetId },
})
if (!asset) {
throw new HTTPException(404, { message: 'Asset not found' })
}
const media = asset.media as PrismaJson.MediaInfo | null
if (!media?.isHls || !media.hls?.key) {
throw new HTTPException(404, { message: 'HLS playlist not found' })
}
const obj = await s3Service.getObject(bucket, media.hls.key)
return obj.buffer.toString('utf-8')
}
async getHlsVariantPlaylist(params: {
assetId: string
resolution: string
watermarkConfigId?: string | null
}): Promise<string> {
const bucket = process.env.S3_BUCKET || 'shumai'
if (!/^\d+p$/.test(params.resolution)) {
throw new HTTPException(400, { message: 'Invalid resolution format' })
}
const targetAssetId = await this.resolveLatestVersionId(params.assetId)
let media: PrismaJson.MediaInfo | null
if (params.watermarkConfigId) {
const wf = await this.prismaClient.watermarkFile.findUnique({
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention
assetId_watermarkConfigId: {
assetId: targetAssetId,
watermarkConfigId: params.watermarkConfigId,
},
},
})
media = (wf?.media as PrismaJson.MediaInfo | null) ?? null
} else {
const asset = await this.prismaClient.asset.findUnique({
where: { id: targetAssetId },
})
if (!asset) {
throw new HTTPException(404, { message: 'Asset not found' })
}
media = (asset.media as PrismaJson.MediaInfo | null) ?? null
}
if (!media?.isHls || !media.hls?.key) {
throw new HTTPException(404, { message: 'HLS playlist not found' })
}
const matchedRes = media.hls.resolutions?.find((r) => r.resolution === params.resolution)
const variantKey =
matchedRes?.key ||
path.posix.join(path.posix.dirname(media.hls.key), params.resolution, 'index.m3u8')
const obj = await s3Service.getObject(bucket, variantKey)
const rawM3u8 = obj.buffer.toString('utf-8')
const s3Prefix = path.posix.dirname(variantKey)
return await rewriteM3u8WithPresignedUrls(rawM3u8, s3Prefix, bucket)
}
}
export const assetService = new AssetService()
@@ -2,9 +2,12 @@ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { GotenbergService } from './gotenberg'
describe('GotenbergService', () => {
setupTestDbHooks()
const originalEnv = process.env
let tmpDir: string
let testFilePath: string
@@ -216,4 +219,148 @@ describe('GotenbergService', () => {
expect(indexHtmlText).toContain('{{ toHTML "file.md" }}')
})
})
describe('team settings & fallback', () => {
it('resolves config from team settings when env is not set', async () => {
delete process.env.GOTENBERG_URL
const team = await prisma.team.create({
data: {
name: 'Gotenberg Team',
settings: {
gotenberg: {
url: 'http://custom-gotenberg:4000',
username: 'team-user',
password: 'team-password',
},
},
},
})
const service = new GotenbergService()
const config = await service.resolveConfig(team.id)
expect(config).toEqual({
url: 'http://custom-gotenberg:4000',
username: 'team-user',
password: 'team-password',
isEnv: false,
})
})
it('prioritizes environment variables over team settings', async () => {
process.env.GOTENBERG_URL = 'http://env-gotenberg:3000'
const team = await prisma.team.create({
data: {
name: 'Gotenberg Team',
settings: {
gotenberg: {
url: 'http://custom-gotenberg:4000',
},
},
},
})
const service = new GotenbergService()
const config = await service.resolveConfig(team.id)
expect(config.url).toBe('http://env-gotenberg:3000')
expect(config.isEnv).toBe(true)
})
it('getSettings returns masked settings response', async () => {
delete process.env.GOTENBERG_URL
const team = await prisma.team.create({
data: {
name: 'Gotenberg Team',
settings: {
gotenberg: {
url: 'http://custom-gotenberg:4000',
username: 'team-user',
password: 'team-password',
},
},
},
})
const service = new GotenbergService()
const settings = await service.getSettings(team.id)
expect(settings).toEqual({
url: 'http://custom-gotenberg:4000',
username: 'team-user',
hasPassword: true,
isEnvConfigured: false,
})
})
it('updateSettings updates team settings and rejects edits when env is set', async () => {
delete process.env.GOTENBERG_URL
const team = await prisma.team.create({
data: { name: 'Gotenberg Team' },
})
const service = new GotenbergService()
const updated = await service.updateSettings(team.id, {
url: 'http://new-gotenberg:3000',
username: 'admin',
password: 'secret-password',
})
expect(updated.url).toBe('http://new-gotenberg:3000')
expect(updated.username).toBe('admin')
expect(updated.hasPassword).toBe(true)
// When env is set, reject update
process.env.GOTENBERG_URL = 'http://env-gotenberg:3000'
await expect(service.updateSettings(team.id, { url: 'http://another:3000' })).rejects.toThrow(
'Gotenberg settings are configured via environment variables and cannot be edited',
)
})
})
describe('testConnection', () => {
it('returns error when url is empty and no team settings exist', async () => {
delete process.env.GOTENBERG_URL
const service = new GotenbergService()
const result = await service.testConnection({})
expect(result.ok).toBe(false)
expect(result.error).toBe('URL is required')
})
it('successfully connects to /health and enriches with /version', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockImplementation(async (url) => {
const urlStr = String(url)
if (urlStr.endsWith('/health')) {
return { ok: true, status: 200 } as Response
}
if (urlStr.endsWith('/version')) {
return {
ok: true,
status: 200,
json: async () => ({ version: '8.3.0' }),
} as Response
}
return { ok: false, status: 404 } as Response
})
const service = new GotenbergService()
const result = await service.testConnection({
url: 'http://gotenberg.local:3000',
username: 'test-user',
password: 'test-pass',
})
expect(result.ok).toBe(true)
expect(result.version).toBe('8.3.0')
expect(fetchSpy).toHaveBeenCalledWith(
'http://gotenberg.local:3000/health',
expect.objectContaining({
method: 'GET',
headers: expect.objectContaining({
Authorization: expect.stringMatching(/^Basic /),
}),
}),
)
})
})
})
+126 -29
View File
@@ -1,40 +1,135 @@
import * as fs from 'fs'
import type { GotenbergSettingsResponse, UpdateGotenbergSettingsRequest } from '@shumai/dtos'
import {
IntegrationDefinition,
resolveIntegrationConfig,
getIntegrationSettings,
updateIntegrationSettings,
resolveTestConnectionConfig,
getIntegrationBasicAuthHeader,
ResolvedIntegrationConfig,
} from '@shumai/core/src/integrations/helper'
export const GOTENBERG_INTEGRATION_DEF: IntegrationDefinition<'gotenberg'> = {
name: 'Gotenberg',
settingsKey: 'gotenberg',
envKeys: {
url: ['GOTENBERG_URL'],
username: ['GOTENBERG_BASIC_AUTH_USERNAME'],
password: ['GOTENBERG_BASIC_AUTH_PASSWORD'],
},
}
export interface GotenbergConvertOptions {
landscape?: boolean
teamId?: string
}
export class GotenbergService {
private getUrl(): string | undefined {
const url = process.env.GOTENBERG_URL?.trim()
return url ? url.replace(/\/+$/, '') : undefined
async resolveConfig(teamId?: string): Promise<ResolvedIntegrationConfig> {
return resolveIntegrationConfig(GOTENBERG_INTEGRATION_DEF, teamId)
}
private getAuthHeader(): string | undefined {
const username = process.env.GOTENBERG_BASIC_AUTH_USERNAME
const password = process.env.GOTENBERG_BASIC_AUTH_PASSWORD
private getAuthHeader(config: { username?: string; password?: string }): string | undefined {
return getIntegrationBasicAuthHeader(config)
}
if (username && password) {
const credentials = Buffer.from(`${username}:${password}`).toString('base64')
return `Basic ${credentials}`
async getSettings(teamId: string): Promise<GotenbergSettingsResponse> {
return getIntegrationSettings(GOTENBERG_INTEGRATION_DEF, teamId)
}
async updateSettings(
teamId: string,
req: UpdateGotenbergSettingsRequest,
): Promise<GotenbergSettingsResponse> {
return updateIntegrationSettings(GOTENBERG_INTEGRATION_DEF, teamId, req)
}
async testConnection(
config?: UpdateGotenbergSettingsRequest,
teamId?: string,
): Promise<{ ok: boolean; version?: string; error?: string }> {
const target = await resolveTestConnectionConfig(GOTENBERG_INTEGRATION_DEF, config, teamId)
if (!target.resolvedUrl) {
return { ok: false, error: 'URL is required' }
}
const cleanUrl = target.resolvedUrl.replace(/\/+$/, '')
try {
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader({
username: target.resolvedUsername,
password: target.resolvedPassword,
})
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${cleanUrl}/health`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(5000),
})
if (!response.ok) {
const errText = await response.text().catch(() => '')
return {
ok: false,
error: `Health check returned status ${response.status}: ${errText || response.statusText}`,
}
}
// Optionally try /version to obtain version string
let version: string | undefined
try {
const versionRes = await fetch(`${cleanUrl}/version`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(2000),
})
if (versionRes.ok) {
const vData = (await versionRes.json().catch(() => null)) as
| { version?: string }
| string
| null
if (vData && typeof vData === 'object' && 'version' in vData) {
version = String(vData.version)
} else if (typeof vData === 'string') {
version = vData
}
}
} catch {
// Version endpoint is optional in some Gotenberg versions
}
return {
ok: true,
version,
}
} catch (err) {
const msg = err instanceof Error ? err.message : String(err)
return {
ok: false,
error: msg,
}
}
return undefined
}
async isAvailable(): Promise<boolean> {
const baseUrl = this.getUrl()
if (!baseUrl) {
async isAvailable(teamId?: string): Promise<boolean> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
return false
}
try {
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader()
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${baseUrl}/health`, {
const response = await fetch(`${config.url}/health`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(3000),
@@ -50,9 +145,11 @@ export class GotenbergService {
filePath: string,
filename: string,
options: GotenbergConvertOptions = {},
teamId?: string,
): Promise<Buffer> {
const baseUrl = this.getUrl()
if (!baseUrl) {
const effectiveTeamId = teamId ?? options.teamId
const config = await this.resolveConfig(effectiveTeamId)
if (!config.url) {
throw new Error('Gotenberg URL is not configured.')
}
@@ -65,12 +162,12 @@ export class GotenbergService {
}
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader()
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${baseUrl}/forms/libreoffice/convert`, {
const response = await fetch(`${config.url}/forms/libreoffice/convert`, {
method: 'POST',
headers,
body: formData,
@@ -88,9 +185,9 @@ export class GotenbergService {
return Buffer.from(arrayBuffer)
}
async convertHtmlToPdf(filePath: string, filename: string): Promise<Buffer> {
const baseUrl = this.getUrl()
if (!baseUrl) {
async convertHtmlToPdf(filePath: string, filename: string, teamId?: string): Promise<Buffer> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
throw new Error('Gotenberg URL is not configured.')
}
@@ -103,12 +200,12 @@ export class GotenbergService {
formData.append('files', new Blob([fileBytes]), targetFilename)
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader()
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${baseUrl}/forms/chromium/convert/html`, {
const response = await fetch(`${config.url}/forms/chromium/convert/html`, {
method: 'POST',
headers,
body: formData,
@@ -126,9 +223,9 @@ export class GotenbergService {
return Buffer.from(arrayBuffer)
}
async convertMarkdownToPdf(filePath: string, filename: string): Promise<Buffer> {
const baseUrl = this.getUrl()
if (!baseUrl) {
async convertMarkdownToPdf(filePath: string, filename: string, teamId?: string): Promise<Buffer> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
throw new Error('Gotenberg URL is not configured.')
}
@@ -151,12 +248,12 @@ export class GotenbergService {
formData.append('files', new Blob([fileBytes]), mdFilename)
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader()
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${baseUrl}/forms/chromium/convert/markdown`, {
const response = await fetch(`${config.url}/forms/chromium/convert/markdown`, {
method: 'POST',
headers,
body: formData,
+4 -1
View File
@@ -5,7 +5,7 @@ export * from './authz/authz'
export * from './collection/collection'
export * from './invite/invite'
export * from './metadata/metadata'
export * from './notification/notification'
export * from './notification/index'
export * from './project/project'
export * from './provider/provider'
export * from './s3/s3'
@@ -31,3 +31,6 @@ export * from './kanban/kanban'
export * from './media-generation/media-generation'
export * from './sandbox'
export * from './asset/comments-export'
export * from './turntable/turntable'
export * from './utils/model3d'
export * from './integrations/helper'
@@ -0,0 +1,271 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import {
IntegrationDefinition,
resolveIntegrationConfig,
getIntegrationSettings,
updateIntegrationSettings,
resolveTestConnectionConfig,
getIntegrationBasicAuthHeader,
} from './helper'
const TEST_INTEGRATION_DEF: IntegrationDefinition<'turntable'> = {
name: 'TestIntegration',
settingsKey: 'turntable',
envKeys: {
url: ['TEST_INTEGRATION_URL', 'FALLBACK_INTEGRATION_URL'],
username: ['TEST_INTEGRATION_USERNAME'],
password: ['TEST_INTEGRATION_PASSWORD'],
},
}
describe('Integration Config Helper', () => {
setupTestDbHooks()
const originalEnv = process.env
beforeEach(() => {
process.env = { ...originalEnv }
delete process.env.TEST_INTEGRATION_URL
delete process.env.FALLBACK_INTEGRATION_URL
delete process.env.TEST_INTEGRATION_USERNAME
delete process.env.TEST_INTEGRATION_PASSWORD
})
afterEach(() => {
process.env = originalEnv
})
describe('resolveIntegrationConfig', () => {
it('prioritizes environment variables over database settings', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
turntable: {
url: 'http://db-server:1234',
username: 'db-user',
password: 'db-password',
},
},
},
})
process.env.TEST_INTEGRATION_URL = 'http://env-server:5678/'
process.env.TEST_INTEGRATION_USERNAME = 'env-user'
process.env.TEST_INTEGRATION_PASSWORD = 'env-pass'
const config = await resolveIntegrationConfig(TEST_INTEGRATION_DEF, team.id)
expect(config).toEqual({
url: 'http://env-server:5678',
username: 'env-user',
password: 'env-pass',
isEnv: true,
})
})
it('falls back to second env key if first is missing', async () => {
process.env.FALLBACK_INTEGRATION_URL = 'http://fallback-server:8080'
const config = await resolveIntegrationConfig(TEST_INTEGRATION_DEF)
expect(config.url).toBe('http://fallback-server:8080')
expect(config.isEnv).toBe(true)
})
it('reads from team settings when environment variables are not set', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
turntable: {
url: 'http://db-server:1234/',
username: 'db-user',
password: 'db-password',
},
},
},
})
const config = await resolveIntegrationConfig(TEST_INTEGRATION_DEF, team.id)
expect(config).toEqual({
url: 'http://db-server:1234',
username: 'db-user',
password: 'db-password',
isEnv: false,
})
})
it('returns isEnv: false and undefined fields when neither env nor DB are set', async () => {
const team = await prisma.team.create({
data: { name: 'Empty Team' },
})
const config = await resolveIntegrationConfig(TEST_INTEGRATION_DEF, team.id)
expect(config).toEqual({
isEnv: false,
})
})
})
describe('getIntegrationSettings', () => {
it('returns safe response masking password', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
turntable: {
url: 'http://db-server:1234',
username: 'db-user',
password: 'db-password',
},
},
},
})
const res = await getIntegrationSettings(TEST_INTEGRATION_DEF, team.id)
expect(res).toEqual({
url: 'http://db-server:1234',
username: 'db-user',
hasPassword: true,
isEnvConfigured: false,
})
})
})
describe('updateIntegrationSettings', () => {
it('throws error when environment variable is configured', async () => {
const team = await prisma.team.create({
data: { name: 'Test Team' },
})
process.env.TEST_INTEGRATION_URL = 'http://env-server:5678'
await expect(
updateIntegrationSettings(TEST_INTEGRATION_DEF, team.id, {
url: 'http://new-url:1234',
}),
).rejects.toThrow(
'TestIntegration settings are configured via environment variables and cannot be edited',
)
})
it('updates settings and preserves existing password when not supplied', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
turntable: {
url: 'http://original:1234',
username: 'original-user',
password: 'secret-password',
},
},
},
})
const res = await updateIntegrationSettings(TEST_INTEGRATION_DEF, team.id, {
url: 'http://updated:5678/',
username: 'new-user',
})
expect(res).toEqual({
url: 'http://updated:5678',
username: 'new-user',
hasPassword: true,
isEnvConfigured: false,
})
const config = await resolveIntegrationConfig(TEST_INTEGRATION_DEF, team.id)
expect(config.password).toBe('secret-password')
})
it('clears settings in database when URL is empty or whitespace', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
turntable: {
url: 'http://to-be-cleared:1234',
username: 'user',
password: 'pwd',
},
},
},
})
const res = await updateIntegrationSettings(TEST_INTEGRATION_DEF, team.id, {
url: ' ',
})
expect(res).toEqual({
url: undefined,
username: undefined,
hasPassword: false,
isEnvConfigured: false,
})
const updatedTeam = await prisma.team.findUnique({
where: { id: team.id },
})
// Check that turntable is removed from team settings
expect((updatedTeam?.settings as Record<string, unknown>)?.turntable).toBeUndefined()
})
})
describe('resolveTestConnectionConfig', () => {
it('uses provided credentials directly when supplied', async () => {
const target = await resolveTestConnectionConfig(TEST_INTEGRATION_DEF, {
url: 'http://direct:1234',
username: 'direct-user',
password: 'direct-password',
})
expect(target).toEqual({
resolvedUrl: 'http://direct:1234',
resolvedUsername: 'direct-user',
resolvedPassword: 'direct-password',
})
})
it('falls back to saved database settings when testing with partial inputs', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
turntable: {
url: 'http://db:1234',
username: 'db-user',
password: 'db-password',
},
},
},
})
const target = await resolveTestConnectionConfig(
TEST_INTEGRATION_DEF,
{ url: 'http://new-url:9999' },
team.id,
)
expect(target).toEqual({
resolvedUrl: 'http://new-url:9999',
resolvedUsername: 'db-user',
resolvedPassword: 'db-password',
})
})
})
describe('getIntegrationBasicAuthHeader', () => {
it('generates base64 basic auth header when username and password are provided', () => {
const header = getIntegrationBasicAuthHeader({ username: 'admin', password: 'secret' })
expect(header).toBe(`Basic ${Buffer.from('admin:secret').toString('base64')}`)
})
it('returns undefined when username or password is missing', () => {
expect(getIntegrationBasicAuthHeader({ username: 'admin' })).toBeUndefined()
expect(getIntegrationBasicAuthHeader({ password: 'secret' })).toBeUndefined()
expect(getIntegrationBasicAuthHeader({})).toBeUndefined()
})
})
})
+188
View File
@@ -0,0 +1,188 @@
import { prisma } from '@shumai/db'
import '@shumai/db/src/prisma-json-types'
import { logger } from '@shumai/core/src/logger'
export interface IntegrationEnvKeys {
url: string[]
username?: string[]
password?: string[]
}
export interface IntegrationDefinition<TKey extends keyof PrismaJson.Settings> {
name: string
settingsKey: TKey
envKeys: IntegrationEnvKeys
}
export interface ResolvedIntegrationConfig {
url?: string
username?: string
password?: string
isEnv: boolean
}
export interface IntegrationSettingsResponse {
url?: string
username?: string
hasPassword: boolean
isEnvConfigured: boolean
}
export interface UpdateIntegrationSettingsRequest {
url?: string
username?: string
password?: string
}
function getFirstEnvValue(keys?: string[]): string | undefined {
if (!keys) return undefined
for (const key of keys) {
const val = process.env[key]?.trim()
if (val) return val
}
return undefined
}
export async function resolveIntegrationConfig<TKey extends keyof PrismaJson.Settings>(
def: IntegrationDefinition<TKey>,
teamId?: string,
): Promise<ResolvedIntegrationConfig> {
const envUrl = getFirstEnvValue(def.envKeys.url)
const envUsername = getFirstEnvValue(def.envKeys.username)
const envPassword = getFirstEnvValue(def.envKeys.password)
if (envUrl) {
return {
url: envUrl.replace(/\/+$/, ''),
username: envUsername || undefined,
password: envPassword || undefined,
isEnv: true,
}
}
if (teamId) {
try {
const team = await prisma.team.findUnique({
where: { id: teamId },
select: { settings: true },
})
const teamSettings = team?.settings as PrismaJson.Settings | null
const serviceSettings = teamSettings?.[def.settingsKey] as
| { url?: string; username?: string; password?: string }
| undefined
if (serviceSettings?.url?.trim()) {
return {
url: serviceSettings.url.trim().replace(/\/+$/, ''),
username: serviceSettings.username?.trim() || undefined,
password: serviceSettings.password?.trim() || undefined,
isEnv: false,
}
}
} catch (err) {
logger.error({ err, teamId }, `Failed to load team ${def.name} settings`)
}
}
return {
isEnv: false,
}
}
export async function getIntegrationSettings<TKey extends keyof PrismaJson.Settings>(
def: IntegrationDefinition<TKey>,
teamId: string,
): Promise<IntegrationSettingsResponse> {
const config = await resolveIntegrationConfig(def, teamId)
return {
url: config.url,
username: config.username,
hasPassword: Boolean(config.password),
isEnvConfigured: config.isEnv,
}
}
export async function updateIntegrationSettings<TKey extends keyof PrismaJson.Settings>(
def: IntegrationDefinition<TKey>,
teamId: string,
req: UpdateIntegrationSettingsRequest,
): Promise<IntegrationSettingsResponse> {
const currentConfig = await resolveIntegrationConfig(def, teamId)
if (currentConfig.isEnv) {
throw new Error(
`${def.name} settings are configured via environment variables and cannot be edited`,
)
}
const team = await prisma.team.findUnique({
where: { id: teamId },
select: { settings: true },
})
const settings = { ...((team?.settings || {}) as PrismaJson.Settings) }
const prevSettings = (settings[def.settingsKey] || {}) as {
url?: string
username?: string
password?: string
}
const trimmedUrl = req.url?.trim()
if (!trimmedUrl) {
// If URL is empty/unset, clear the integration settings
delete settings[def.settingsKey]
} else {
const updatedServiceSettings: { url: string; username?: string; password?: string } = {
url: trimmedUrl.replace(/\/+$/, ''),
username:
req.username !== undefined ? req.username.trim() || undefined : prevSettings.username,
password: req.password !== undefined ? req.password : prevSettings.password,
}
settings[def.settingsKey] = updatedServiceSettings as unknown as PrismaJson.Settings[TKey]
}
await prisma.team.update({
where: { id: teamId },
data: { settings },
})
return getIntegrationSettings(def, teamId)
}
export async function resolveTestConnectionConfig<TKey extends keyof PrismaJson.Settings>(
def: IntegrationDefinition<TKey>,
config?: UpdateIntegrationSettingsRequest,
teamId?: string,
): Promise<{ resolvedUrl?: string; resolvedUsername?: string; resolvedPassword?: string }> {
let resolvedUrl = config?.url?.trim()
let resolvedUsername = config?.username?.trim()
let resolvedPassword = config?.password
if (teamId && (!resolvedUrl || resolvedPassword === undefined)) {
const savedConfig = await resolveIntegrationConfig(def, teamId)
if (!resolvedUrl) {
resolvedUrl = savedConfig.url
}
if (!resolvedUsername && savedConfig.username) {
resolvedUsername = savedConfig.username
}
if (resolvedPassword === undefined) {
resolvedPassword = savedConfig.password
}
}
return {
resolvedUrl,
resolvedUsername,
resolvedPassword,
}
}
export function getIntegrationBasicAuthHeader(config: {
username?: string
password?: string
}): string | undefined {
if (config.username && config.password) {
const credentials = Buffer.from(`${config.username}:${config.password}`).toString('base64')
return `Basic ${credentials}`
}
return undefined
}
@@ -0,0 +1,700 @@
import { describe, expect, it, vi, beforeEach } from 'vitest'
import nodemailer from 'nodemailer'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { NotificationType } from '@shumai/db'
import { emailService, DEFAULT_EMAIL_SETTINGS } from './email'
const mockSendMail = vi.fn().mockResolvedValue({ messageId: '<mock-msg-id@shumai.test>' })
const mockVerify = vi.fn().mockResolvedValue(true)
const mockClose = vi.fn()
vi.mock('nodemailer', () => ({
default: {
createTransport: vi.fn(() => ({
sendMail: mockSendMail,
verify: mockVerify,
close: mockClose,
})),
},
}))
describe('EmailService', () => {
setupTestDbHooks()
beforeEach(() => {
vi.clearAllMocks()
mockSendMail.mockResolvedValue({ messageId: '<mock-msg-id@shumai.test>' })
mockVerify.mockResolvedValue(true)
})
describe('getEmailSettings', () => {
it('returns default settings when team settings are not set', async () => {
const team = await prisma.team.create({ data: { name: 'Team Alpha' } })
const settings = await emailService.getEmailSettings(team.id)
expect(settings).toEqual(DEFAULT_EMAIL_SETTINGS)
expect(settings.enabled).toBe(false)
expect(settings.port).toBe(587)
})
it('returns saved email settings when configured', async () => {
const team = await prisma.team.create({
data: {
name: 'Team Beta',
settings: {
emailNotification: {
enabled: true,
host: 'smtp.beta.test',
port: 465,
username: 'beta_user',
password: 'secret_password',
smtps: true,
ignoreCert: false,
from: 'beta@shumai.test',
replyTo: 'reply@shumai.test',
},
},
},
})
const settings = await emailService.getEmailSettings(team.id)
expect(settings.enabled).toBe(true)
expect(settings.host).toBe('smtp.beta.test')
expect(settings.port).toBe(465)
expect(settings.password).toBe('secret_password')
})
it('throws 404 if team does not exist', async () => {
await expect(emailService.getEmailSettings('non-existent-team-id')).rejects.toThrow()
})
})
describe('updateEmailSettings', () => {
it('updates email settings and saves to team.settings', async () => {
const team = await prisma.team.create({ data: { name: 'Team Gamma' } })
const updated = await emailService.updateEmailSettings(team.id, {
enabled: true,
host: 'smtp.gamma.test',
port: 587,
username: 'gamma',
password: 'gamma_password',
smtps: false,
ignoreCert: true,
from: 'gamma@shumai.test',
replyTo: '',
})
expect(updated.enabled).toBe(true)
expect(updated.host).toBe('smtp.gamma.test')
expect(updated.password).toBe('gamma_password')
expect(updated.ignoreCert).toBe(true)
const reloaded = await prisma.team.findUnique({ where: { id: team.id } })
expect(reloaded?.settings?.emailNotification?.host).toBe('smtp.gamma.test')
})
it('preserves existing password if empty string or undefined is provided in update', async () => {
const team = await prisma.team.create({
data: {
name: 'Team Delta',
settings: {
emailNotification: {
enabled: true,
host: 'smtp.delta.test',
port: 587,
username: 'delta',
password: 'original_super_secret',
smtps: false,
ignoreCert: false,
from: 'delta@shumai.test',
replyTo: '',
},
},
},
})
const updated = await emailService.updateEmailSettings(team.id, {
enabled: true,
host: 'smtp.delta-updated.test',
port: 587,
username: 'delta_new',
password: '', // Empty password should retain existing
smtps: true,
ignoreCert: false,
from: 'delta@shumai.test',
})
expect(updated.host).toBe('smtp.delta-updated.test')
expect(updated.password).toBe('original_super_secret')
const reloaded = await prisma.team.findUnique({ where: { id: team.id } })
expect(reloaded?.settings?.emailNotification?.password).toBe('original_super_secret')
})
})
describe('sendMail and verifySmtp', () => {
it('verifySmtp calls transport.verify and closes transport', async () => {
const config = { ...DEFAULT_EMAIL_SETTINGS, host: 'smtp.test' }
const ok = await emailService.verifySmtp(config)
expect(ok).toBe(true)
expect(mockVerify).toHaveBeenCalled()
expect(mockClose).toHaveBeenCalled()
})
it('sendMail sends email using nodemailer transport', async () => {
const config = { ...DEFAULT_EMAIL_SETTINGS, host: 'smtp.test', from: 'shumai@test.com' }
const res = await emailService.sendMail(config, {
to: 'user@test.com',
subject: 'Hello',
html: '<p>Hello World</p>',
text: 'Hello World',
})
expect(res.messageId).toBe('<mock-msg-id@shumai.test>')
expect(mockSendMail).toHaveBeenCalledWith(
expect.objectContaining({
from: 'shumai@test.com',
to: 'user@test.com',
subject: 'Hello',
}),
)
expect(mockClose).toHaveBeenCalled()
})
it('sendMail forwards attachments to nodemailer transport', async () => {
const config = { ...DEFAULT_EMAIL_SETTINGS, host: 'smtp.test', from: 'shumai@test.com' }
const attachments = [
{
filename: 'avatar.png',
content: Buffer.from('image-data'),
cid: 'avatar-123@shumai.internal',
contentType: 'image/png',
},
]
await emailService.sendMail(config, {
to: 'user@test.com',
subject: 'Hello',
html: '<img src="cid:avatar-123@shumai.internal" />',
text: 'Hello',
attachments,
})
expect(mockSendMail).toHaveBeenCalledWith(
expect.objectContaining({
attachments,
}),
)
})
})
describe('sendTestEmail', () => {
it('sends test email to the current admin user', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team',
settings: {
emailNotification: {
enabled: true,
host: 'smtp.test.com',
port: 587,
username: 'user',
password: 'pw',
smtps: false,
ignoreCert: false,
from: 'sender@test.com',
replyTo: '',
},
},
},
})
const currentUser = { id: 'admin1', email: 'admin@shumai.test', name: 'Admin' }
const result = await emailService.sendTestEmail(team.id, currentUser)
expect(result.success).toBe(true)
expect(result.messageId).toBe('<mock-msg-id@shumai.test>')
expect(mockVerify).toHaveBeenCalled()
expect(mockSendMail).toHaveBeenCalledWith(
expect.objectContaining({
to: 'admin@shumai.test',
subject: 'Test email from Shumai',
}),
)
})
it('allows overriding settings with input draft', async () => {
const team = await prisma.team.create({ data: { name: 'Test Team 2' } })
const currentUser = { id: 'admin2', email: 'admin2@shumai.test', name: 'Admin 2' }
const result = await emailService.sendTestEmail(team.id, currentUser, {
host: 'smtp.draft.com',
from: 'draft@test.com',
password: 'draft-password',
})
expect(result.success).toBe(true)
expect(nodemailer.createTransport).toHaveBeenCalledWith(
expect.objectContaining({
host: 'smtp.draft.com',
}),
)
expect(mockSendMail).toHaveBeenCalledWith(
expect.objectContaining({
from: 'draft@test.com',
to: 'admin2@shumai.test',
}),
)
})
it('throws error when host is missing', async () => {
const team = await prisma.team.create({ data: { name: 'Empty Host Team' } })
const currentUser = { id: 'admin3', email: 'admin3@shumai.test', name: 'Admin 3' }
await expect(
emailService.sendTestEmail(team.id, currentUser, { host: '', from: 'a@b.com' }),
).rejects.toThrow('SMTP host is required')
})
it('throws error when from address is missing', async () => {
const team = await prisma.team.create({ data: { name: 'Empty From Team' } })
const currentUser = { id: 'admin4', email: 'admin4@shumai.test', name: 'Admin 4' }
await expect(
emailService.sendTestEmail(team.id, currentUser, { host: 'smtp.test', from: '' }),
).rejects.toThrow('From address is required')
})
it('throws 400 when verify fails', async () => {
const team = await prisma.team.create({ data: { name: 'Failing Team' } })
const currentUser = { id: 'admin5', email: 'admin5@shumai.test', name: 'Admin 5' }
mockVerify.mockRejectedValueOnce(new Error('Connection refused'))
await expect(
emailService.sendTestEmail(team.id, currentUser, {
host: 'smtp.down.com',
from: 'admin@down.com',
}),
).rejects.toThrow('SMTP verification failed: Connection refused')
})
})
describe('renderNotificationEmail', () => {
it('renders comment notification', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.comment_created,
creatorName: 'Alice',
teamName: 'Designers',
teamId: 'team-1',
projectId: 'proj-1',
assetId: 'asset-1',
assetName: 'logo.png',
commentMessage: 'Please make it bigger',
})
expect(rendered.subject).toContain('Alice commented on "logo.png"')
expect(rendered.html).toContain('Please make it bigger')
expect(rendered.html).toContain('logo.png')
expect(rendered.text).toContain('Alice commented on "logo.png"')
})
it('renders mention notification', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.mention,
creatorName: 'Bob',
teamName: 'Developers',
teamId: 'team-2',
projectId: 'proj-2',
assetId: 'asset-2',
assetName: 'architecture.pdf',
commentMessage: 'Take a look at this',
})
expect(rendered.subject).toContain('Bob mentioned you')
expect(rendered.html).toContain('Bob mentioned you')
expect(rendered.html).toContain('Take a look at this')
})
it('replaces user mentions with user names instead of user ID in comment emails', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.comment_created,
creatorName: 'Bob',
teamName: 'Designers',
teamId: 'team-1',
projectId: 'proj-1',
assetId: 'asset-1',
assetName: 'logo.png',
commentMessage: '<@kUFrm1W4fKLCaLpw2XQP1OPe0gKACJpy> nice',
mentionedUserNames: {
// eslint-disable-next-line @typescript-eslint/naming-convention
kUFrm1W4fKLCaLpw2XQP1OPe0gKACJpy: 'Alice',
},
})
expect(rendered.html).toContain('@Alice nice')
expect(rendered.html).not.toContain('<@kUFrm1W4fKLCaLpw2XQP1OPe0gKACJpy>')
expect(rendered.text).toContain('@Alice nice')
expect(rendered.text).not.toContain('<@kUFrm1W4fKLCaLpw2XQP1OPe0gKACJpy>')
})
it('renders asset upload notification with project name, creator profile image, and upload time', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.successful_file_uploaded,
creatorName: 'Charlie',
creatorAvatarUrl: 'https://example.com/avatar.jpg',
teamName: 'Media',
teamId: 'team-3',
projectName: 'Marketing Campaign',
projectId: 'proj-3',
assetId: 'asset-3',
assetName: 'video.mp4',
fileCount: 1,
uploadTime: new Date('2026-09-27T15:20:00Z'),
})
expect(rendered.subject).toContain('Charlie uploaded "video.mp4" to Marketing Campaign')
expect(rendered.html).toContain('Marketing Campaign')
expect(rendered.html).toContain('https://example.com/avatar.jpg')
expect(rendered.html).toContain('Sep 27, 2026')
expect(rendered.text).toContain('Marketing Campaign')
expect(rendered.text).toContain('Sep 27, 2026')
})
it('renders single file uploaded notification', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.successful_file_uploaded,
creatorName: 'Charlie',
teamName: 'Media',
teamId: 'team-3',
projectId: 'proj-3',
assetId: 'asset-3',
assetName: 'video.mp4',
fileCount: 1,
})
expect(rendered.subject).toContain('Charlie uploaded "video.mp4"')
expect(rendered.html).toContain('video.mp4')
})
it('renders consolidated batch file upload notification', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.successful_file_uploaded,
creatorName: 'Charlie',
teamName: 'Media',
teamId: 'team-3',
projectName: 'Videos',
projectId: 'proj-3',
fileCount: 5,
fileNames: ['img1.png', 'img2.png', 'img3.png', 'img4.png', 'img5.png'],
})
expect(rendered.subject).toContain('Charlie uploaded 5 files to Videos')
expect(rendered.html).toContain('img1.png')
expect(rendered.html).toContain('and 2 more')
})
it('renders user joined team notification', () => {
const rendered = emailService.renderNotificationEmail({
type: NotificationType.new_user_join_team,
creatorName: 'Dave',
teamName: 'Acme Corp',
teamId: 'team-4',
})
expect(rendered.subject).toContain('Dave joined Acme Corp')
expect(rendered.html).toContain('Dave is now a member of Acme Corp')
})
it('renders kanban task notifications', () => {
const created = emailService.renderNotificationEmail({
type: NotificationType.kanban_task_created,
creatorName: 'Eva',
teamName: 'Engineering',
teamId: 'team-5',
kanbanTaskId: 'kt-1',
kanbanTaskTitle: 'Fix login bug',
})
expect(created.subject).toContain('Eva created task "Fix login bug"')
const assigned = emailService.renderNotificationEmail({
type: NotificationType.kanban_task_assigned,
creatorName: 'Frank',
teamName: 'Engineering',
teamId: 'team-5',
kanbanTaskId: 'kt-2',
kanbanTaskTitle: 'Design DB schema',
})
expect(assigned.subject).toContain('Frank assigned you to task "Design DB schema"')
const status = emailService.renderNotificationEmail({
type: NotificationType.kanban_task_status_updated,
creatorName: 'Grace',
teamName: 'Engineering',
teamId: 'team-5',
kanbanTaskId: 'kt-3',
kanbanTaskTitle: 'Refactor auth',
commentMessage: 'Moved to In Progress',
})
expect(status.subject).toContain('Grace updated status of task "Refactor auth"')
expect(status.html).toContain('Moved to In Progress')
})
it('generates correct action links without team id for project and asset URLs', () => {
const baseUrl = emailService.getBaseUrl()
// Project link
const projectEmail = emailService.renderNotificationEmail({
type: NotificationType.new_user_join_project,
creatorName: 'Alice',
teamName: 'Designers',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
projectName: 'Project Alpha',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
})
expect(projectEmail.html).toContain(`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ"`)
expect(projectEmail.html).not.toContain(
'/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ',
)
// Asset link
const assetEmail = emailService.renderNotificationEmail({
type: NotificationType.comment_created,
creatorName: 'Alice',
teamName: 'Designers',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
projectName: 'Project Alpha',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
assetId: '01KY2ASSET1234567890ABCDEF',
assetName: 'logo.png',
commentMessage: 'Looks good',
})
expect(assetEmail.html).toContain(
`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ/files/01KY2ASSET1234567890ABCDEF"`,
)
expect(assetEmail.html).not.toContain('/teams/')
})
})
describe('renderBatchedNotificationEmail', () => {
it('renders single notification with specific subject and detailed row', () => {
const rendered = emailService.renderBatchedNotificationEmail({
teamId: 'team-1',
teamName: 'Designers',
recipientName: 'Bob',
items: [
{
id: 'n-1',
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
creatorAvatarUrl: 'https://example.com/alice.png',
teamId: 'team-1',
teamName: 'Designers',
projectId: 'p-1',
projectName: 'Website Redesign',
assetId: 'a-1',
assetName: 'hero.png',
assetThumbnailUrl: 'https://example.com/hero-thumb.png',
createdAt: new Date('2026-09-27T10:00:00Z'),
},
],
})
expect(rendered.subject).toBe('[Shumai] Alice uploaded "hero.png" to Website Redesign')
expect(rendered.html).toContain('Alice')
expect(rendered.html).toContain('Uploaded &quot;hero.png&quot; to Website Redesign')
expect(rendered.html).toContain('https://example.com/hero-thumb.png')
expect(rendered.html).toContain('https://example.com/alice.png')
expect(rendered.text).toContain('Alice: Uploaded "hero.png" to Website Redesign')
})
it('renders detailed rows with thumbnail when event count <= 3', () => {
const rendered = emailService.renderBatchedNotificationEmail({
teamId: 'team-1',
teamName: 'Designers',
recipientName: 'Bob',
items: [
{
id: 'n-1',
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
teamId: 'team-1',
teamName: 'Designers',
projectId: 'p-1',
projectName: 'Website Redesign',
assetId: 'a-1',
assetName: 'img1.png',
assetThumbnailUrl: 'https://example.com/img1.png',
createdAt: new Date('2026-09-27T10:00:00Z'),
},
{
id: 'n-2',
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
teamId: 'team-1',
teamName: 'Designers',
projectId: 'p-1',
projectName: 'Website Redesign',
assetId: 'a-2',
assetName: 'img2.png',
createdAt: new Date('2026-09-27T10:01:00Z'),
},
],
})
expect(rendered.subject).toBe('[Shumai] 2 new notifications')
expect(rendered.html).toContain('You have 2 new updates:')
expect(rendered.html).not.toContain('in <strong>Designers</strong>')
expect(rendered.html).toContain('Open Shumai')
expect(rendered.html).not.toContain('Open Designers')
expect(rendered.html).not.toContain('Team: Designers')
expect(rendered.text).toContain('You have 2 new update(s):')
expect(rendered.text).toContain('Open Shumai:')
expect(rendered.text).not.toContain('Team: Designers')
expect(rendered.html).toContain('img1.png')
expect(rendered.html).toContain('img2.png')
// img1 has thumbnail, img2 does not
expect(rendered.html).toContain('https://example.com/img1.png')
expect(rendered.text).toContain('img1.png')
expect(rendered.text).toContain('img2.png')
})
it('collapses events into one summary row and omits thumbnails when count > 3', () => {
const items = Array.from({ length: 5 }, (_, i) => ({
id: `n-${i}`,
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
creatorAvatarUrl: 'https://example.com/alice.png',
teamId: 'team-1',
teamName: 'Designers',
projectId: 'p-1',
projectName: 'Website Redesign',
assetId: `a-${i}`,
assetName: `photo_${i}.png`,
assetThumbnailUrl: `https://example.com/thumb_${i}.png`,
createdAt: new Date(`2026-09-27T10:0${i}:00Z`),
}))
const rendered = emailService.renderBatchedNotificationEmail({
teamId: 'team-1',
teamName: 'Designers',
recipientName: 'Bob',
items,
})
expect(rendered.subject).toBe('[Shumai] 5 new notifications')
expect(rendered.html).toContain('Alice uploaded 5 assets to Website Redesign')
// Thumbnails must be omitted for collapsed groups (> 3)
expect(rendered.html).not.toContain('https://example.com/thumb_')
expect(rendered.text).toContain('Alice uploaded 5 assets to Website Redesign')
})
it('batches mixed events in 1 email, collapsing groups > 3 while showing <= 3 in detail', () => {
// 4 comments by UserB in Project Alpha (> 3)
const commentItems = Array.from({ length: 4 }, (_, i) => ({
id: `c-${i}`,
type: NotificationType.comment_created,
creatorName: 'UserB',
teamId: 'team-1',
teamName: 'Designers',
projectId: 'p-1',
projectName: 'Project Alpha',
assetId: `a-${i}`,
assetName: `asset_${i}`,
commentMessage: `Comment number ${i}`,
createdAt: new Date(`2026-09-27T11:0${i}:00Z`),
}))
// 1 upload by UserC in Project Alpha (<= 3)
const uploadItem = {
id: 'u-1',
type: NotificationType.successful_file_uploaded,
creatorName: 'UserC',
teamId: 'team-1',
teamName: 'Designers',
projectId: 'p-1',
projectName: 'Project Alpha',
assetId: 'a-upload',
assetName: 'diagram.png',
assetThumbnailUrl: 'https://example.com/diagram.png',
createdAt: new Date('2026-09-27T11:05:00Z'),
}
const rendered = emailService.renderBatchedNotificationEmail({
teamId: 'team-1',
teamName: 'Designers',
recipientName: 'Alice',
items: [...commentItems, uploadItem],
})
expect(rendered.subject).toBe('[Shumai] 5 new notifications')
// Collapsed comment group
expect(rendered.html).toContain('UserB left 4 comments in Project Alpha')
// Detailed upload item with thumbnail
expect(rendered.html).toContain('UserC')
expect(rendered.html).toContain('diagram.png')
expect(rendered.html).toContain('https://example.com/diagram.png')
})
it('generates correct project action links in batched notification emails', () => {
const baseUrl = emailService.getBaseUrl()
const rendered = emailService.renderBatchedNotificationEmail({
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
recipientName: 'Bob',
items: [
{
id: 'n-1',
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
projectName: 'Project Alpha',
assetId: '01KY2ASSET1234567890ABCDEF',
assetName: 'hero.png',
createdAt: new Date('2026-09-27T10:00:00Z'),
},
],
})
expect(rendered.html).toContain(
`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ/files/01KY2ASSET1234567890ABCDEF"`,
)
expect(rendered.html).not.toContain(
'/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ',
)
// Test collapsed group (>3 items)
const collapsedItems = Array.from({ length: 4 }, (_, i) => ({
id: `n-${i}`,
type: NotificationType.successful_file_uploaded,
creatorName: 'Alice',
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
projectId: '01KY2ANCA1SXGSPR63NVVD07EJ',
projectName: 'Project Alpha',
assetId: `asset-${i}`,
assetName: `file_${i}.png`,
createdAt: new Date('2026-09-27T10:00:00Z'),
}))
const renderedCollapsed = emailService.renderBatchedNotificationEmail({
teamId: '01KY2A7DRK2N0MECBDHTGAVV84',
teamName: 'Designers',
recipientName: 'Bob',
items: collapsedItems,
})
expect(renderedCollapsed.html).toContain(
`href="${baseUrl}/projects/01KY2ANCA1SXGSPR63NVVD07EJ"`,
)
expect(renderedCollapsed.html).not.toContain(
'/teams/01KY2A7DRK2N0MECBDHTGAVV84/projects/01KY2ANCA1SXGSPR63NVVD07EJ',
)
})
})
})
+912
View File
@@ -0,0 +1,912 @@
import nodemailer, { type Transporter } from 'nodemailer'
import { HTTPException } from 'hono/http-exception'
import { prisma, NotificationType } from '@shumai/db'
import type { EmailNotificationSettings, UpdateEmailNotificationSettings } from '@shumai/dtos'
import { logger } from '@shumai/core/src/logger'
export interface EmailAttachment {
filename: string
content?: Buffer | string
path?: string
cid?: string
contentType?: string
}
export interface SendMailOptions {
to: string
subject: string
html: string
text: string
attachments?: EmailAttachment[]
}
export interface NotificationEmailContext {
type: NotificationType
creatorName: string
creatorAvatarUrl?: string
teamName: string
teamId: string
projectName?: string
projectId?: string
assetName?: string
assetId?: string
kanbanTaskTitle?: string
kanbanTaskId?: string
commentMessage?: string
mentionedUserNames?: Record<string, string>
fileCount?: number
fileNames?: string[]
uploadTime?: string | Date
}
export interface BatchedNotificationItem {
id: string
type: NotificationType
creatorName: string
creatorAvatarUrl?: string
teamId: string
teamName: string
projectId?: string
projectName?: string
assetId?: string
assetName?: string
assetThumbnailUrl?: string
kanbanTaskId?: string
kanbanTaskTitle?: string
commentMessage?: string
mentionedUserNames?: Record<string, string>
uploadTime?: string | Date
createdAt: Date
}
export interface BatchedEmailContext {
teamId: string
teamName: string
recipientName: string
items: BatchedNotificationItem[]
}
export function getNotificationBatchGroupKey(item: BatchedNotificationItem): string {
return `${item.type}_${item.creatorName || ''}_${item.projectId || ''}_${item.teamId}`
}
export const DEFAULT_EMAIL_SETTINGS: EmailNotificationSettings = {
enabled: false,
host: '',
port: 587,
username: '',
password: '',
smtps: false,
ignoreCert: false,
from: '',
replyTo: '',
}
export class EmailService {
getBaseUrl(): string {
const raw =
process.env.APP_URL ||
process.env.BETTER_AUTH_URL ||
`http://localhost:${process.env.SHUMAI_SERVER_PORT || '3000'}`
return raw.replace(/\/+$/, '')
}
createTransport(config: EmailNotificationSettings): Transporter {
return nodemailer.createTransport({
host: config.host,
port: config.port,
secure: config.smtps,
tls: {
rejectUnauthorized: !config.ignoreCert,
},
auth:
config.username || config.password
? {
user: config.username,
pass: config.password,
}
: undefined,
connectionTimeout: 10000,
})
}
async verifySmtp(config: EmailNotificationSettings): Promise<boolean> {
const transport = this.createTransport(config)
try {
await transport.verify()
return true
} finally {
transport.close()
}
}
async sendMail(
config: EmailNotificationSettings,
options: SendMailOptions,
): Promise<{ messageId: string }> {
const transport = this.createTransport(config)
try {
logger.debug(
{ to: options.to, from: config.from, subject: options.subject },
'Sending email via nodemailer',
)
const info = await transport.sendMail({
from: config.from,
replyTo: config.replyTo || config.from,
to: options.to,
subject: options.subject,
html: options.html,
text: options.text,
attachments: options.attachments,
})
logger.info({ messageId: info.messageId, to: options.to }, 'Email sent successfully')
return { messageId: info.messageId }
} finally {
transport.close()
}
}
async getEmailSettings(teamId: string): Promise<EmailNotificationSettings> {
const team = await prisma.team.findUnique({
where: { id: teamId },
select: { settings: true },
})
if (!team) {
throw new HTTPException(404, { message: 'Team not found' })
}
const saved = team.settings?.emailNotification
return {
enabled: saved?.enabled ?? DEFAULT_EMAIL_SETTINGS.enabled,
host: saved?.host ?? DEFAULT_EMAIL_SETTINGS.host,
port: saved?.port ?? DEFAULT_EMAIL_SETTINGS.port,
username: saved?.username ?? DEFAULT_EMAIL_SETTINGS.username,
password: saved?.password ?? DEFAULT_EMAIL_SETTINGS.password,
smtps: saved?.smtps ?? DEFAULT_EMAIL_SETTINGS.smtps,
ignoreCert: saved?.ignoreCert ?? DEFAULT_EMAIL_SETTINGS.ignoreCert,
from: saved?.from ?? DEFAULT_EMAIL_SETTINGS.from,
replyTo: saved?.replyTo ?? DEFAULT_EMAIL_SETTINGS.replyTo,
}
}
async updateEmailSettings(
teamId: string,
input: UpdateEmailNotificationSettings,
): Promise<EmailNotificationSettings> {
const team = await prisma.team.findUnique({
where: { id: teamId },
select: { settings: true },
})
if (!team) {
throw new HTTPException(404, { message: 'Team not found' })
}
const currentSettings = (team.settings || {}) as PrismaJson.Settings
const existingEmailConfig = currentSettings.emailNotification
// If password is not provided or empty, retain existing password
const password =
input.password !== undefined && input.password !== ''
? input.password
: existingEmailConfig?.password || ''
const updatedEmailConfig: PrismaJson.EmailNotificationSettings = {
enabled: input.enabled,
host: input.host,
port: input.port,
username: input.username || '',
password,
smtps: input.smtps,
ignoreCert: input.ignoreCert,
from: input.from,
replyTo: input.replyTo || '',
}
currentSettings.emailNotification = updatedEmailConfig
const updatedTeam = await prisma.team.update({
where: { id: teamId },
data: { settings: currentSettings as PrismaJson.Settings },
select: { settings: true },
})
return updatedTeam.settings?.emailNotification as EmailNotificationSettings
}
async sendTestEmail(
teamId: string,
currentUser: { id: string; email: string; name: string },
overrides?: Partial<EmailNotificationSettings>,
): Promise<{ success: boolean; messageId: string }> {
const saved = await this.getEmailSettings(teamId)
const effectiveConfig: EmailNotificationSettings = {
...saved,
...overrides,
// If override password is empty, fall back to saved
password:
overrides?.password !== undefined && overrides.password !== ''
? overrides.password
: saved.password,
}
if (!effectiveConfig.host) {
throw new HTTPException(400, { message: 'SMTP host is required' })
}
if (!effectiveConfig.from) {
throw new HTTPException(400, { message: 'From address is required' })
}
try {
await this.verifySmtp(effectiveConfig)
} catch (err) {
const errMsg = err instanceof Error ? err.message : String(err)
logger.warn({ teamId, err: errMsg }, 'SMTP verification failed during test email')
throw new HTTPException(400, { message: `SMTP verification failed: ${errMsg}` })
}
const baseUrl = this.getBaseUrl()
const subject = 'Test email from Shumai'
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Email from Shumai</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f9fafb; margin: 0; padding: 24px; color: #111827; }
.container { max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 8px; border: 1px solid #e5e7eb; padding: 32px; }
.header { font-size: 20px; font-weight: 700; margin-bottom: 16px; color: #111827; }
.content { font-size: 14px; line-height: 1.6; color: #4b5563; margin-bottom: 24px; }
.badge { display: inline-block; background-color: #ecfdf5; color: #065f46; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 9999px; margin-bottom: 16px; }
.footer { font-size: 12px; color: #9ca3af; border-top: 1px solid #f3f4f6; padding-top: 16px; margin-top: 24px; }
</style>
</head>
<body>
<div class="container">
<div class="header">Shumai Notification System</div>
<div class="badge">SMTP Verified</div>
<div class="content">
<p>Hello ${escapeHtml(currentUser.name || 'Admin')},</p>
<p>This is a test email confirming that your SMTP server settings are correctly configured for team notifications in Shumai.</p>
<p>Notifications for new comments, mentions, uploads, and Kanban tasks will now be delivered via this email service.</p>
</div>
<div class="footer">
Sent from Shumai at <a href="${baseUrl}" style="color: #6366f1; text-decoration: none;">${baseUrl}</a>
</div>
</div>
</body>
</html>
`.trim()
const text = `
Shumai Notification System - Test Email
Hello ${currentUser.name || 'Admin'},
This is a test email confirming that your SMTP server settings are correctly configured for team notifications in Shumai.
Sent from Shumai at ${baseUrl}
`.trim()
try {
const res = await this.sendMail(effectiveConfig, {
to: currentUser.email,
subject,
html,
text,
})
return { success: true, messageId: res.messageId }
} catch (err) {
const errMsg = err instanceof Error ? err.message : String(err)
logger.error({ teamId, err: errMsg }, 'Failed to send test email')
throw new HTTPException(400, { message: `Failed to send test email: ${errMsg}` })
}
}
renderNotificationEmail(ctx: NotificationEmailContext): {
subject: string
html: string
text: string
} {
const baseUrl = this.getBaseUrl()
let actionUrl = baseUrl
let actionText = 'View in Shumai'
if (ctx.projectId && ctx.assetId) {
actionUrl = `${baseUrl}/projects/${ctx.projectId}/files/${ctx.assetId}`
actionText = 'View Asset'
} else if (ctx.projectId) {
actionUrl = `${baseUrl}/projects/${ctx.projectId}`
actionText = 'View Project'
} else if (ctx.teamId && ctx.kanbanTaskId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}/kanban?taskId=${ctx.kanbanTaskId}`
actionText = 'View Task'
} else if (ctx.teamId) {
actionUrl = `${baseUrl}/teams/${ctx.teamId}`
actionText = 'Open Shumai'
}
let subject = '[Shumai] Notification'
let headline = 'You have a new notification'
let detail = ''
const actor = ctx.creatorName || 'Someone'
const actorInitial = (actor.trim()[0] || 'U').toUpperCase()
const formattedUploadTime = formatUploadTime(ctx.uploadTime)
let commentMessage = ctx.commentMessage
if (commentMessage) {
commentMessage = commentMessage.replace(/<@([^>]+)>/g, (match, uid) => {
const name = ctx.mentionedUserNames?.[uid]
return name ? `@${name}` : `@${uid}`
})
}
switch (ctx.type) {
case NotificationType.comment_created: {
const target = ctx.assetName ? `"${ctx.assetName}"` : 'an asset'
subject = `[Shumai] ${actor} commented on ${target}`
headline = `${actor} left a comment`
detail = commentMessage ? `"${commentMessage}"` : `New comment on ${target}`
break
}
case NotificationType.reply_created: {
const target = ctx.assetName ? `"${ctx.assetName}"` : 'an asset'
subject = `[Shumai] ${actor} replied to your comment on ${target}`
headline = `${actor} replied to your comment`
detail = commentMessage ? `"${commentMessage}"` : `Reply on ${target}`
break
}
case NotificationType.mention: {
subject = `[Shumai] ${actor} mentioned you`
headline = `${actor} mentioned you`
detail = commentMessage ? `"${commentMessage}"` : 'You were mentioned in a comment'
break
}
case NotificationType.successful_file_uploaded: {
const target = ctx.assetName ? `"${ctx.assetName}"` : 'a file'
const projectInfo = ctx.projectName ? ` to ${ctx.projectName}` : ''
if (ctx.fileCount && ctx.fileCount > 1) {
subject = `[Shumai] ${actor} uploaded ${ctx.fileCount} files${projectInfo}`
headline = `${actor} uploaded ${ctx.fileCount} new files${projectInfo}`
let filesSummary: string
if (ctx.fileNames && ctx.fileNames.length > 0) {
const previewList = ctx.fileNames.slice(0, 3).join(', ')
const remaining = ctx.fileNames.length - 3
filesSummary = remaining > 0 ? `${previewList}, and ${remaining} more` : previewList
} else {
filesSummary = `${ctx.fileCount} new files were uploaded`
}
const details: string[] = []
if (ctx.projectName) details.push(`Project: ${ctx.projectName}`)
if (formattedUploadTime) details.push(`Uploaded at: ${formattedUploadTime}`)
details.push(`Files: ${filesSummary}`)
detail = details.join('\n')
} else {
subject = `[Shumai] ${actor} uploaded ${target}${projectInfo}`
headline = `${actor} uploaded ${target}${projectInfo}`
const details: string[] = []
if (ctx.assetName) details.push(`Asset: ${ctx.assetName}`)
if (ctx.projectName) details.push(`Project: ${ctx.projectName}`)
if (formattedUploadTime) details.push(`Uploaded at: ${formattedUploadTime}`)
detail = details.join('\n')
}
break
}
case NotificationType.metadata_field_updated_status: {
const target = ctx.assetName ? `"${ctx.assetName}"` : 'an asset'
subject = `[Shumai] ${actor} updated status of ${target}`
headline = `${actor} updated status of ${target}`
detail = `Status update on ${target}`
break
}
case NotificationType.new_user_join_team: {
subject = `[Shumai] ${actor} joined ${ctx.teamName}`
headline = `${actor} joined the team`
detail = `${actor} is now a member of ${ctx.teamName}`
break
}
case NotificationType.new_user_join_project: {
const project = ctx.projectName || 'a project'
subject = `[Shumai] ${actor} joined project ${project}`
headline = `${actor} joined project ${project}`
detail = `${actor} is now a member of ${project}`
break
}
case NotificationType.kanban_task_created: {
const task = ctx.kanbanTaskTitle ? `"${ctx.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} created task ${task}`
headline = `${actor} created task ${task}`
detail = commentMessage || `Task ${task} was created`
break
}
case NotificationType.kanban_task_assigned: {
const task = ctx.kanbanTaskTitle ? `"${ctx.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} assigned you to task ${task}`
headline = `${actor} assigned you to task ${task}`
detail = `You have been assigned to ${task}`
break
}
case NotificationType.kanban_task_status_updated: {
const task = ctx.kanbanTaskTitle ? `"${ctx.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} updated status of task ${task}`
headline = `${actor} updated status of ${task}`
detail = commentMessage || `Status changed for ${task}`
break
}
case NotificationType.kanban_task_updated: {
const task = ctx.kanbanTaskTitle ? `"${ctx.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} updated task ${task}`
headline = `${actor} updated task ${task}`
detail = commentMessage || `Task ${task} was updated`
break
}
case NotificationType.kanban_task_deleted: {
const task = ctx.kanbanTaskTitle ? `"${ctx.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} deleted task ${task}`
headline = `${actor} deleted task ${task}`
detail = `Task ${task} was deleted`
break
}
case NotificationType.kanban_task_comment_created: {
const task = ctx.kanbanTaskTitle ? `"${ctx.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} commented on task ${task}`
headline = `${actor} commented on task ${task}`
detail = commentMessage ? `"${commentMessage}"` : `New comment on ${task}`
break
}
}
const avatarHtml = ctx.creatorAvatarUrl
? `<img src="${escapeHtml(ctx.creatorAvatarUrl)}" alt="${escapeHtml(actor)}" width="36" height="36" style="width: 36px; height: 36px; border-radius: 50%; object-fit: cover; display: block; border: 1px solid #e5e7eb;" />`
: `<table cellpadding="0" cellspacing="0" border="0" style="width: 36px; height: 36px; border-radius: 50%; background-color: #4f46e5; text-align: center;"><tr><td style="color: #ffffff; font-weight: 600; font-size: 14px; text-align: center; vertical-align: middle;">${escapeHtml(actorInitial)}</td></tr></table>`
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>${escapeHtml(subject)}</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f9fafb; margin: 0; padding: 24px; color: #111827; }
.container { max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 8px; border: 1px solid #e5e7eb; padding: 32px; }
.header { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: #111827; }
.content { font-size: 14px; line-height: 1.6; color: #374151; margin-bottom: 24px; }
.detail-box { background-color: #f3f4f6; border-left: 4px solid #4f46e5; padding: 12px 16px; border-radius: 4px; margin: 16px 0; font-size: 14px; color: #1f2937; white-space: pre-wrap; }
.btn { display: inline-block; background-color: #4f46e5; color: #ffffff !important; padding: 10px 20px; border-radius: 6px; text-decoration: none; font-size: 14px; font-weight: 500; margin-top: 12px; }
.footer { font-size: 12px; color: #9ca3af; border-top: 1px solid #f3f4f6; padding-top: 16px; margin-top: 24px; }
</style>
</head>
<body>
<div class="container">
<table cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 16px;">
<tr>
<td style="vertical-align: middle; padding-right: 12px; width: 36px;">
${avatarHtml}
</td>
<td style="vertical-align: middle;">
<div style="font-weight: 600; font-size: 15px; color: #111827; line-height: 1.2;">${escapeHtml(actor)}</div>
${formattedUploadTime ? `<div style="font-size: 12px; color: #6b7280; margin-top: 2px;">Uploaded at ${escapeHtml(formattedUploadTime)}</div>` : ''}
</td>
</tr>
</table>
<div class="header">${escapeHtml(headline)}</div>
<div class="content">
${detail ? `<div class="detail-box">${escapeHtml(detail)}</div>` : ''}
<a href="${actionUrl}" class="btn">${escapeHtml(actionText)}</a>
</div>
<div class="footer">
Sent from <a href="${baseUrl}" style="color: #6366f1; text-decoration: none;">Shumai</a>
</div>
</div>
</body>
</html>
`.trim()
const text = `
${subject}
${headline}
${formattedUploadTime ? `Uploaded at: ${formattedUploadTime}\n` : ''}${detail ? `\n${detail}\n` : ''}
${actionText}: ${actionUrl}
Sent from Shumai at ${baseUrl}
`.trim()
return { subject, html, text }
}
renderBatchedNotificationEmail(ctx: BatchedEmailContext): {
subject: string
html: string
text: string
} {
const baseUrl = this.getBaseUrl()
const teamUrl = `${baseUrl}/teams/${ctx.teamId}`
if (ctx.items.length === 0) {
return {
subject: `[Shumai] Notifications`,
html: `<p>No new notifications.</p>`,
text: `No new notifications.`,
}
}
// Determine subject
let subject = `[Shumai] ${ctx.items.length} new notifications`
if (ctx.items.length === 1) {
const single = ctx.items[0]
const actor = single.creatorName || 'Someone'
const target = single.assetName ? `"${single.assetName}"` : 'a file'
const projectInfo = single.projectName ? ` to ${single.projectName}` : ''
switch (single.type) {
case NotificationType.successful_file_uploaded:
subject = `[Shumai] ${actor} uploaded ${target}${projectInfo}`
break
case NotificationType.comment_created:
subject = `[Shumai] ${actor} commented on ${target}`
break
case NotificationType.reply_created:
subject = `[Shumai] ${actor} replied to your comment on ${target}`
break
case NotificationType.mention:
subject = `[Shumai] ${actor} mentioned you`
break
case NotificationType.kanban_task_assigned: {
const task = single.kanbanTaskTitle ? `"${single.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} assigned you to task ${task}`
break
}
case NotificationType.kanban_task_created: {
const task = single.kanbanTaskTitle ? `"${single.kanbanTaskTitle}"` : 'a task'
subject = `[Shumai] ${actor} created task ${task}`
break
}
default:
subject = `[Shumai] 1 new notification`
break
}
}
// Group items: same type + actor + project
const groups = new Map<string, BatchedNotificationItem[]>()
for (const item of ctx.items) {
const key = getNotificationBatchGroupKey(item)
const list = groups.get(key)
if (list) {
list.push(item)
} else {
groups.set(key, [item])
}
}
const htmlRows: string[] = []
const textRows: string[] = []
for (const [, cluster] of groups) {
const first = cluster[0]
const actor = first.creatorName || 'Someone'
const avatarHtml = renderAvatarHtml(actor, first.creatorAvatarUrl)
if (cluster.length <= 3) {
// Render detailed individual rows
for (const item of cluster) {
const action = getItemAction(baseUrl, item)
const timeStr = formatUploadTime(item.uploadTime || item.createdAt)
const detail = getNotificationItemDetail(item)
const thumbHtml = item.assetThumbnailUrl
? `<div style="margin-top: 8px;"><img src="${escapeHtml(item.assetThumbnailUrl)}" alt="${escapeHtml(item.assetName || 'Thumbnail')}" width="140" style="max-width: 140px; max-height: 90px; border-radius: 6px; border: 1px solid #e5e7eb; object-fit: cover; display: block;" /></div>`
: ''
htmlRows.push(
`
<div style="padding: 16px 0; border-bottom: 1px solid #f3f4f6;">
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
<tr>
<td style="vertical-align: top; width: 44px; padding-right: 12px;">
${avatarHtml}
</td>
<td style="vertical-align: top;">
<div style="font-weight: 600; font-size: 14px; color: #111827;">${escapeHtml(actor)}</div>
<div style="font-size: 13px; color: #374151; margin-top: 2px;">${escapeHtml(detail.headline)}</div>
${timeStr ? `<div style="font-size: 12px; color: #6b7280; margin-top: 2px;">${escapeHtml(timeStr)}</div>` : ''}
${detail.message ? `<div style="background-color: #f9fafb; border-left: 3px solid #6366f1; padding: 8px 12px; border-radius: 4px; font-size: 13px; color: #4b5563; margin-top: 6px; white-space: pre-wrap;">${escapeHtml(detail.message)}</div>` : ''}
${thumbHtml}
<div style="margin-top: 8px;">
<a href="${action.url}" style="display: inline-block; font-size: 12px; font-weight: 500; color: #4f46e5; text-decoration: none;">${escapeHtml(action.text)} &rarr;</a>
</div>
</td>
</tr>
</table>
</div>
`.trim(),
)
textRows.push(
`- ${actor}: ${detail.headline}${timeStr ? ` (${timeStr})` : ''}${detail.message ? `\n "${detail.message}"` : ''}\n Link: ${action.url}`,
)
}
} else {
// Grouped summary row (count > 3, NO thumbnails)
const count = cluster.length
let summaryHeadline = `${actor} triggered ${count} updates`
const projectName = first.projectName
switch (first.type) {
case NotificationType.successful_file_uploaded:
summaryHeadline = `${actor} uploaded ${count} assets${projectName ? ` to ${projectName}` : ''}`
break
case NotificationType.comment_created:
summaryHeadline = `${actor} left ${count} comments${projectName ? ` in ${projectName}` : ''}`
break
case NotificationType.reply_created:
summaryHeadline = `${actor} replied ${count} times to your comments`
break
case NotificationType.mention:
summaryHeadline = `${actor} mentioned you ${count} times`
break
case NotificationType.metadata_field_updated_status:
summaryHeadline = `${actor} updated status of ${count} assets`
break
case NotificationType.kanban_task_created:
summaryHeadline = `${actor} created ${count} tasks${projectName ? ` in ${projectName}` : ''}`
break
case NotificationType.kanban_task_assigned:
summaryHeadline = `${actor} assigned you to ${count} tasks`
break
case NotificationType.kanban_task_status_updated:
summaryHeadline = `${actor} updated status of ${count} tasks`
break
case NotificationType.kanban_task_updated:
summaryHeadline = `${actor} updated ${count} tasks`
break
case NotificationType.kanban_task_comment_created:
summaryHeadline = `${actor} commented on ${count} tasks`
break
}
const latestTime = cluster.reduce((latest, it) => {
const t = new Date(it.uploadTime || it.createdAt).getTime()
return t > latest ? t : latest
}, 0)
const timeStr = latestTime > 0 ? formatUploadTime(new Date(latestTime)) : undefined
const targetUrl = first.projectId ? `${baseUrl}/projects/${first.projectId}` : teamUrl
htmlRows.push(
`
<div style="padding: 16px 0; border-bottom: 1px solid #f3f4f6;">
<table cellpadding="0" cellspacing="0" border="0" style="width: 100%;">
<tr>
<td style="vertical-align: top; width: 44px; padding-right: 12px;">
${avatarHtml}
</td>
<td style="vertical-align: top;">
<div style="font-weight: 600; font-size: 14px; color: #111827;">${escapeHtml(summaryHeadline)}</div>
${timeStr ? `<div style="font-size: 12px; color: #6b7280; margin-top: 2px;">Latest activity: ${escapeHtml(timeStr)}</div>` : ''}
<div style="margin-top: 8px;">
<a href="${targetUrl}" style="display: inline-block; font-size: 12px; font-weight: 500; color: #4f46e5; text-decoration: none;">View Project &rarr;</a>
</div>
</td>
</tr>
</table>
</div>
`.trim(),
)
textRows.push(
`- ${summaryHeadline}${timeStr ? ` (Latest: ${timeStr})` : ''}\n Link: ${targetUrl}`,
)
}
}
const html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>${escapeHtml(subject)}</title>
<style>
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background-color: #f9fafb; margin: 0; padding: 24px; color: #111827; }
.container { max-width: 600px; margin: 0 auto; background: #ffffff; border-radius: 8px; border: 1px solid #e5e7eb; padding: 32px; }
.header { font-size: 18px; font-weight: 700; color: #111827; }
.subtitle { font-size: 14px; color: #6b7280; margin-top: 4px; margin-bottom: 20px; }
.btn { display: inline-block; background-color: #4f46e5; color: #ffffff !important; padding: 10px 20px; border-radius: 6px; text-decoration: none; font-size: 14px; font-weight: 500; margin-top: 20px; }
.footer { font-size: 12px; color: #9ca3af; border-top: 1px solid #f3f4f6; padding-top: 16px; margin-top: 24px; }
</style>
</head>
<body>
<div class="container">
<div class="header">Shumai Notifications</div>
<div class="subtitle">You have ${ctx.items.length} new update${ctx.items.length > 1 ? 's' : ''}:</div>
<div>
${htmlRows.join('\n')}
</div>
<div style="text-align: center; margin-top: 20px;">
<a href="${teamUrl}" class="btn">Open Shumai</a>
</div>
<div class="footer">
Sent from <a href="${baseUrl}" style="color: #6366f1; text-decoration: none;">Shumai</a>
</div>
</div>
</body>
</html>
`.trim()
const text = `
Shumai Notifications
You have ${ctx.items.length} new update(s):
${textRows.join('\n\n')}
Open Shumai: ${teamUrl}
Sent from Shumai at ${baseUrl}
`.trim()
return { subject, html, text }
}
}
function getNotificationItemDetail(item: BatchedNotificationItem): {
headline: string
message?: string
} {
const actor = item.creatorName || 'Someone'
const asset = item.assetName ? `"${item.assetName}"` : 'an asset'
const task = item.kanbanTaskTitle ? `"${item.kanbanTaskTitle}"` : 'a task'
const project = item.projectName ? ` in ${item.projectName}` : ''
let commentMessage = item.commentMessage
if (commentMessage && item.mentionedUserNames) {
commentMessage = commentMessage.replace(/<@([^>]+)>/g, (match, uid) => {
const name = item.mentionedUserNames?.[uid]
return name ? `@${name}` : `@${uid}`
})
}
switch (item.type) {
case NotificationType.successful_file_uploaded:
return {
headline: `Uploaded ${asset}${item.projectName ? ` to ${item.projectName}` : ''}`,
}
case NotificationType.comment_created:
return {
headline: `Commented on ${asset}${project}`,
message: commentMessage,
}
case NotificationType.reply_created:
return {
headline: `Replied to your comment on ${asset}${project}`,
message: commentMessage,
}
case NotificationType.mention:
return {
headline: `Mentioned you on ${item.kanbanTaskTitle ? `task ${task}` : asset}${project}`,
message: commentMessage,
}
case NotificationType.metadata_field_updated_status:
return {
headline: `Updated status of ${asset}${project}`,
}
case NotificationType.kanban_task_created:
return {
headline: `Created task ${task}${project}`,
message: commentMessage,
}
case NotificationType.kanban_task_assigned:
return {
headline: `Assigned you to task ${task}${project}`,
}
case NotificationType.kanban_task_status_updated:
return {
headline: `Updated status of task ${task}${project}`,
message: commentMessage,
}
case NotificationType.kanban_task_updated:
return {
headline: `Updated task ${task}${project}`,
message: commentMessage,
}
case NotificationType.kanban_task_deleted:
return {
headline: `Deleted task ${task}${project}`,
}
case NotificationType.kanban_task_comment_created:
return {
headline: `Commented on task ${task}${project}`,
message: commentMessage,
}
case NotificationType.new_user_join_team:
return {
headline: `Joined the team ${item.teamName}`,
}
case NotificationType.new_user_join_project:
return {
headline: `Joined project ${item.projectName || 'a project'}`,
}
default:
return {
headline: `New activity from ${actor}`,
}
}
}
function getItemAction(
baseUrl: string,
item: BatchedNotificationItem,
): { url: string; text: string } {
if (item.projectId && item.assetId) {
return {
url: `${baseUrl}/projects/${item.projectId}/files/${item.assetId}`,
text: 'View Asset',
}
} else if (item.projectId) {
return {
url: `${baseUrl}/projects/${item.projectId}`,
text: 'View Project',
}
} else if (item.teamId && item.kanbanTaskId) {
return {
url: `${baseUrl}/teams/${item.teamId}/kanban?taskId=${item.kanbanTaskId}`,
text: 'View Task',
}
} else if (item.teamId) {
return {
url: `${baseUrl}/teams/${item.teamId}`,
text: 'Open Shumai',
}
}
return { url: baseUrl, text: 'Open Shumai' }
}
function renderAvatarHtml(actor: string, avatarUrl?: string): string {
const actorInitial = (actor.trim()[0] || 'U').toUpperCase()
if (avatarUrl) {
return `<img src="${escapeHtml(avatarUrl)}" alt="${escapeHtml(actor)}" width="36" height="36" style="width: 36px; height: 36px; border-radius: 50%; object-fit: cover; display: block; border: 1px solid #e5e7eb;" />`
}
return `<table cellpadding="0" cellspacing="0" border="0" style="width: 36px; height: 36px; border-radius: 50%; background-color: #4f46e5; text-align: center;"><tr><td style="color: #ffffff; font-weight: 600; font-size: 14px; text-align: center; vertical-align: middle;">${escapeHtml(actorInitial)}</td></tr></table>`
}
function formatUploadTime(time: string | Date | undefined): string | undefined {
if (!time) return undefined
if (time instanceof Date) {
if (isNaN(time.getTime())) return undefined
return (
new Intl.DateTimeFormat('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'UTC',
}).format(time) + ' UTC'
)
}
const parsed = new Date(time)
if (!isNaN(parsed.getTime())) {
return (
new Intl.DateTimeFormat('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
timeZone: 'UTC',
}).format(parsed) + ' UTC'
)
}
return time
}
function escapeHtml(str: string): string {
return str
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
}
export const emailService = new EmailService()
+3
View File
@@ -0,0 +1,3 @@
export * from './notification'
export * from './email'
export * from './notification-job'
@@ -0,0 +1,576 @@
import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'
import { prisma, NotificationType, NotificationEmailStatus } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { emailService, type EmailAttachment } from './email'
import { notificationJobService } from './notification-job'
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
import { s3Service } from '@shumai/core/src/s3/s3'
import '@shumai/db/src/prisma-json-types'
describe('NotificationJobService', () => {
setupTestDbHooks()
let sendMailSpy: ReturnType<typeof vi.spyOn>
beforeEach(() => {
sendMailSpy = vi
.spyOn(emailService, 'sendMail')
.mockResolvedValue({ messageId: '<mock-id@shumai.test>' })
})
afterEach(() => {
sendMailSpy.mockRestore()
notificationJobService.stop()
})
async function createTeamWithEmail(name = 'Email Team') {
return prisma.team.create({
data: {
name,
settings: {
emailNotification: {
enabled: true,
host: 'smtp.test.com',
port: 587,
username: 'user',
password: 'pw',
smtps: false,
ignoreCert: false,
from: 'noreply@test.com',
},
},
},
})
}
it('picks up pending notifications, sends batched email, and marks them processed', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: { name: 'Alice', email: 'alice@test.com', password: 'p' },
})
const recipient = await prisma.user.create({
data: { name: 'Bob', email: 'bob@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: recipient.id, role: 'editor' },
})
const project = await prisma.project.create({
data: { name: 'Alpha Project', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'design.png',
type: 'file',
status: 'uploaded',
project: { connect: { id: project.id } },
},
})
// Create 2 pending notifications
const n1 = await prisma.notification.create({
data: {
type: NotificationType.successful_file_uploaded,
teamId: team.id,
projectId: project.id,
assetId: asset.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
const n2 = await prisma.notification.create({
data: {
type: NotificationType.comment_created,
teamId: team.id,
projectId: project.id,
assetId: asset.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
const processedCount = await notificationJobService.processPendingNotifications(500)
expect(processedCount).toBe(2)
// Verify Bob received exactly 1 batched email containing both items
expect(sendMailSpy).toHaveBeenCalledTimes(1)
expect(sendMailSpy).toHaveBeenCalledWith(
expect.objectContaining({ host: 'smtp.test.com' }),
expect.objectContaining({
to: 'bob@test.com',
subject: '[Shumai] 2 new notifications',
}),
)
// Verify notifications are marked processed in DB
const updated1 = await prisma.notification.findUnique({ where: { id: n1.id } })
const updated2 = await prisma.notification.findUnique({ where: { id: n2.id } })
expect(updated1?.emailStatus).toBe(NotificationEmailStatus.processed)
expect(updated2?.emailStatus).toBe(NotificationEmailStatus.processed)
})
it('skips already processed notifications', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: { name: 'Alice', email: 'alice2@test.com', password: 'p' },
})
await prisma.notification.create({
data: {
type: NotificationType.comment_created,
teamId: team.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.processed,
},
})
const processedCount = await notificationJobService.processPendingNotifications(500)
expect(processedCount).toBe(0)
expect(sendMailSpy).not.toHaveBeenCalled()
})
it('marks notifications processed without sending email if team SMTP is disabled', async () => {
// Team without emailNotification configured
const team = await prisma.team.create({
data: { name: 'No Email Team' },
})
const sender = await prisma.user.create({
data: { name: 'Alice', email: 'alice3@test.com', password: 'p' },
})
const notif = await prisma.notification.create({
data: {
type: NotificationType.new_user_join_team,
teamId: team.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
const processedCount = await notificationJobService.processPendingNotifications(500)
expect(processedCount).toBe(1)
expect(sendMailSpy).not.toHaveBeenCalled()
const updated = await prisma.notification.findUnique({ where: { id: notif.id } })
expect(updated?.emailStatus).toBe(NotificationEmailStatus.processed)
})
it('excludes the actor from receiving notification about their own action', async () => {
const team = await createTeamWithEmail()
const alice = await prisma.user.create({
data: { name: 'Alice', email: 'alice-self@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: alice.id, role: 'editor' },
})
// Alice is the creator and only member
await prisma.notification.create({
data: {
type: NotificationType.comment_created,
teamId: team.id,
creatorId: alice.id,
emailStatus: NotificationEmailStatus.pending,
},
})
await notificationJobService.processPendingNotifications(500)
// Alice should not receive an email for her own comment
expect(sendMailSpy).not.toHaveBeenCalled()
})
it('excludes AI agent users from receiving email notifications', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: { name: 'Alice', email: 'alice-agent-test@test.com', password: 'p' },
})
const agentUser = await prisma.user.create({
data: {
name: 'AutoAgent',
email: 'agent-bot@shumai.ai',
password: 'p',
type: 'agent',
},
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: agentUser.id, role: 'editor' },
})
await prisma.notification.create({
data: {
type: NotificationType.new_user_join_team,
teamId: team.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
await notificationJobService.processPendingNotifications(500)
expect(sendMailSpy).not.toHaveBeenCalled()
})
it('respects user notification preferences', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: { name: 'Alice', email: 'alice-pref@test.com', password: 'p' },
})
const bob = await prisma.user.create({
data: { name: 'Bob', email: 'bob-pref@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: bob.id, role: 'editor' },
})
// Bob disabled comments in his notification settings
await userMetadataService.upsertMetadata(bob.id, team.id, 'notification_settings', {
comments: false,
replies: true,
mentions: true,
yourUploads: false,
otherUploads: true,
statusUpdates: true,
kanbanTasks: true,
kanbanComments: true,
})
await prisma.notification.create({
data: {
type: NotificationType.comment_created,
teamId: team.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
await notificationJobService.processPendingNotifications(500)
expect(sendMailSpy).not.toHaveBeenCalled()
})
it('filters notifications by project scope for project-scoped members', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: { name: 'Alice', email: 'alice-scope@test.com', password: 'p' },
})
const project1 = await prisma.project.create({
data: { name: 'Project 1', teamId: team.id },
})
const project2 = await prisma.project.create({
data: { name: 'Project 2', teamId: team.id },
})
const bob = await prisma.user.create({
data: { name: 'Bob', email: 'bob-scope@test.com', password: 'p' },
})
const bobMember = await prisma.teamMember.create({
data: { teamId: team.id, userId: bob.id, role: 'editor', scope: 'project' },
})
// Bob only belongs to Project 1
await prisma.projectMember.create({
data: { projectId: project1.id, teamMemberId: bobMember.id, role: 'editor' },
})
// Notification in Project 2
await prisma.notification.create({
data: {
type: NotificationType.successful_file_uploaded,
teamId: team.id,
projectId: project2.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
await notificationJobService.processPendingNotifications(500)
// Bob should not receive notification for Project 2
expect(sendMailSpy).not.toHaveBeenCalled()
})
it('batches 5 uploads and 1 comment into 1 email with collapsed upload summary', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: { name: 'UserB', email: 'userb@test.com', password: 'p' },
})
const recipient = await prisma.user.create({
data: { name: 'Recipient', email: 'recip@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: recipient.id, role: 'editor' },
})
const project = await prisma.project.create({
data: { name: 'Project Alpha', teamId: team.id },
})
// 5 uploads by UserB in Project Alpha
for (let i = 0; i < 5; i++) {
const asset = await prisma.asset.create({
data: {
name: `img_${i}.png`,
type: 'file',
status: 'uploaded',
project: { connect: { id: project.id } },
},
})
await prisma.notification.create({
data: {
type: NotificationType.successful_file_uploaded,
teamId: team.id,
projectId: project.id,
assetId: asset.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
}
// 1 comment by UserB
await prisma.notification.create({
data: {
type: NotificationType.comment_created,
teamId: team.id,
projectId: project.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
const count = await notificationJobService.processPendingNotifications(500)
expect(count).toBe(6)
// Recipient receives exactly 1 email containing all 6 events
expect(sendMailSpy).toHaveBeenCalledTimes(1)
const call = sendMailSpy.mock.calls[0]
expect(call[1].to).toBe('recip@test.com')
expect(call[1].subject).toBe('[Shumai] 6 new notifications')
// Uploads collapsed into 1 row because count > 3
expect(call[1].html).toContain('UserB uploaded 5 assets to Project Alpha')
// Comment rendered as individual row
expect(call[1].html).toContain('Commented on')
})
it('embeds creator avatar and asset thumbnail as inline cid attachments', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: {
name: 'Alice Artist',
email: 'alice.artist@test.com',
password: 'p',
image: 'avatars/alice.png',
},
})
const recipient = await prisma.user.create({
data: { name: 'Bob Reviewer', email: 'bob.reviewer@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: recipient.id, role: 'editor' },
})
const project = await prisma.project.create({
data: { name: 'Artwork Project', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'poster.png',
type: 'file',
status: 'uploaded',
project: { connect: { id: project.id } },
media: {
thumbnail: { key: 'thumbnails/poster.jpg' },
} as unknown as PrismaJson.MediaInfo,
},
})
await prisma.notification.create({
data: {
type: NotificationType.successful_file_uploaded,
teamId: team.id,
projectId: project.id,
assetId: asset.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
const getObjectSpy = vi
.spyOn(s3Service, 'getObject')
.mockImplementation(async (_bucket, key) => {
if (key === 'avatars/alice.png') {
return { buffer: Buffer.from('alice-avatar-bytes'), contentType: 'image/png' }
}
if (key === 'thumbnails/poster.jpg') {
return { buffer: Buffer.from('poster-thumb-bytes'), contentType: 'image/jpeg' }
}
throw new Error('Not found')
})
try {
const count = await notificationJobService.processPendingNotifications(500)
expect(count).toBe(1)
expect(sendMailSpy).toHaveBeenCalledTimes(1)
const call = sendMailSpy.mock.calls[0]
const options = call[1]
expect(options.to).toBe('bob.reviewer@test.com')
// Check attachments
expect(options.attachments).toHaveLength(2)
const avatarAtt = options.attachments.find((a: EmailAttachment) =>
a.cid?.startsWith('avatar-'),
)
const thumbAtt = options.attachments.find((a: EmailAttachment) => a.cid?.startsWith('thumb-'))
expect(avatarAtt).toBeDefined()
expect(avatarAtt.content).toEqual(Buffer.from('alice-avatar-bytes'))
expect(avatarAtt.cid).toBe(`avatar-${sender.id}@shumai.internal`)
expect(thumbAtt).toBeDefined()
expect(thumbAtt.content).toEqual(Buffer.from('poster-thumb-bytes'))
expect(thumbAtt.cid).toBe(`thumb-${asset.id}@shumai.internal`)
// Check HTML references the exact cid
expect(options.html).toContain(`src="cid:${avatarAtt.cid}"`)
expect(options.html).toContain(`src="cid:${thumbAtt.cid}"`)
} finally {
getObjectSpy.mockRestore()
}
})
it('omits thumbnail attachments when cluster has count > 3', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: {
name: 'Bulk Uploader',
email: 'bulk@test.com',
password: 'p',
image: 'avatars/bulk.png',
},
})
const recipient = await prisma.user.create({
data: { name: 'Recipient', email: 'bulk-recip@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: recipient.id, role: 'editor' },
})
const project = await prisma.project.create({
data: { name: 'Bulk Project', teamId: team.id },
})
for (let i = 0; i < 4; i++) {
const asset = await prisma.asset.create({
data: {
name: `bulk_${i}.png`,
type: 'file',
status: 'uploaded',
project: { connect: { id: project.id } },
media: {
thumbnail: { key: `thumbnails/bulk_${i}.jpg` },
} as unknown as PrismaJson.MediaInfo,
},
})
await prisma.notification.create({
data: {
type: NotificationType.successful_file_uploaded,
teamId: team.id,
projectId: project.id,
assetId: asset.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
}
const getObjectSpy = vi
.spyOn(s3Service, 'getObject')
.mockImplementation(async (_bucket, key) => {
if (key === 'avatars/bulk.png') {
return { buffer: Buffer.from('bulk-avatar-bytes'), contentType: 'image/png' }
}
return { buffer: Buffer.from('thumb-bytes'), contentType: 'image/jpeg' }
})
try {
const count = await notificationJobService.processPendingNotifications(500)
expect(count).toBe(4)
expect(sendMailSpy).toHaveBeenCalledTimes(1)
const options = sendMailSpy.mock.calls[0][1]
// Count > 3, so only avatar attachment is included, NO thumbnail attachments!
expect(options.attachments).toHaveLength(1)
expect(options.attachments[0].cid).toBe(`avatar-${sender.id}@shumai.internal`)
expect(options.html).toContain(`src="cid:avatar-${sender.id}@shumai.internal"`)
expect(options.html).not.toContain('src="cid:thumb-')
} finally {
getObjectSpy.mockRestore()
}
})
it('gracefully handles missing images or S3 failure with fallback badge', async () => {
const team = await createTeamWithEmail()
const sender = await prisma.user.create({
data: {
name: 'Broken Image User',
email: 'broken@test.com',
password: 'p',
image: 'avatars/non-existent.png',
},
})
const recipient = await prisma.user.create({
data: { name: 'Recipient', email: 'broken-recip@test.com', password: 'p' },
})
await prisma.teamMember.create({
data: { teamId: team.id, userId: recipient.id, role: 'editor' },
})
const project = await prisma.project.create({
data: { name: 'Project', teamId: team.id },
})
const asset = await prisma.asset.create({
data: {
name: 'broken.png',
type: 'file',
status: 'uploaded',
project: { connect: { id: project.id } },
media: {
thumbnail: { key: 'thumbnails/missing.jpg' },
} as unknown as PrismaJson.MediaInfo,
},
})
await prisma.notification.create({
data: {
type: NotificationType.successful_file_uploaded,
teamId: team.id,
projectId: project.id,
assetId: asset.id,
creatorId: sender.id,
emailStatus: NotificationEmailStatus.pending,
},
})
const getObjectSpy = vi.spyOn(s3Service, 'getObject').mockRejectedValue(new Error('S3 error'))
try {
const count = await notificationJobService.processPendingNotifications(500)
expect(count).toBe(1)
expect(sendMailSpy).toHaveBeenCalledTimes(1)
const options = sendMailSpy.mock.calls[0][1]
// No attachments because both avatar and thumb failed to load
expect(options.attachments).toBeUndefined()
// HTML falls back to letter badge "B" for "Broken Image User"
expect(options.html).toContain('>B</td>')
expect(options.html).not.toContain('<img')
} finally {
getObjectSpy.mockRestore()
}
})
it('starts and stops gracefully', () => {
expect(() => {
notificationJobService.start(100000, 100000)
notificationJobService.stop()
}).not.toThrow()
})
})
@@ -0,0 +1,496 @@
import { prisma, NotificationType, NotificationEmailStatus } from '@shumai/db'
import { emailService, getNotificationBatchGroupKey } from '@shumai/core/src/notification/email'
import type { BatchedNotificationItem, EmailAttachment } from '@shumai/core/src/notification/email'
import { userMetadataService } from '@shumai/core/src/user-metadata/user-metadata'
import { s3Service } from '@shumai/core/src/s3/s3'
import { logger } from '@shumai/core/src/logger'
import type { NotificationSettings } from '@shumai/dtos'
import '@shumai/db/src/prisma-json-types'
function getExtensionFromMime(mime?: string): string {
if (!mime) return 'jpg'
if (mime.includes('png')) return 'png'
if (mime.includes('webp')) return 'webp'
if (mime.includes('gif')) return 'gif'
if (mime.includes('svg')) return 'svg'
return 'jpg'
}
export class NotificationJobService {
private isRunning = false
private timer: NodeJS.Timeout | null = null
private isProcessing = false
start(initialDelayMs = 5000, intervalMs = 3 * 60 * 1000): void {
if (this.isRunning) return
this.isRunning = true
logger.info('Starting notification email background job')
const run = async () => {
if (!this.isRunning) return
try {
await this.processPendingNotifications()
} catch (err) {
logger.error(
{ err: err instanceof Error ? err.message : String(err) },
'Error in notification email background job',
)
}
if (this.isRunning) {
this.timer = setTimeout(run, intervalMs)
}
}
this.timer = setTimeout(run, initialDelayMs)
}
stop(): void {
this.isRunning = false
if (this.timer) {
clearTimeout(this.timer)
this.timer = null
}
logger.info('Stopped notification email background job')
}
async processPendingNotifications(limit = 500): Promise<number> {
if (this.isProcessing) {
logger.debug('Notification job turn already in progress, skipping')
return 0
}
this.isProcessing = true
let batchIds: string[] = []
try {
// 1. Concurrency control: atomically lock up to limit pending notifications
const locked = await prisma.$queryRaw<{ id: string }[]>`
WITH candidates AS (
SELECT id
FROM notifications
WHERE email_status = 'pending'::"NotificationEmailStatus"
ORDER BY id ASC
LIMIT ${limit}
FOR UPDATE SKIP LOCKED
)
UPDATE notifications
SET email_status = 'processing'::"NotificationEmailStatus", updated_at = NOW()
FROM candidates
WHERE notifications.id = candidates.id
RETURNING notifications.id;
`
if (!locked || locked.length === 0) {
return 0
}
batchIds = locked.map((r) => r.id)
logger.info({ count: batchIds.length }, 'Picked up pending notifications for processing')
// 2. Fetch full records with relations
const notifications = await prisma.notification.findMany({
where: { id: { in: batchIds } },
include: {
creator: { select: { id: true, name: true, image: true, type: true } },
team: { select: { id: true, name: true } },
project: { select: { id: true, name: true } },
asset: {
select: {
id: true,
name: true,
media: true,
projectId: true,
createdAt: true,
project: { select: { id: true, name: true } },
},
},
user: { select: { id: true, name: true, email: true, type: true } },
kanbanTask: { select: { id: true, title: true, projectId: true } },
},
orderBy: { id: 'asc' },
})
// 3. Group notifications by teamId
const byTeam = new Map<string, typeof notifications>()
for (const n of notifications) {
const list = byTeam.get(n.teamId)
if (list) {
list.push(n)
} else {
byTeam.set(n.teamId, [n])
}
}
// 4. Process each team
for (const [teamId, teamNotifs] of byTeam) {
const emailSettings = await emailService.getEmailSettings(teamId)
if (!emailSettings.enabled || !emailSettings.host || !emailSettings.from) {
logger.debug(
{ teamId },
'Team email notifications disabled or unconfigured, skipping delivery',
)
continue
}
// Fetch team members excluding AI agents
const members = await prisma.teamMember.findMany({
where: {
teamId,
user: {
type: { not: 'agent' },
agent: null,
},
},
include: {
user: { select: { id: true, name: true, email: true, type: true } },
projectMembers: { select: { projectId: true } },
},
})
const avatarCache = new Map<
string,
{ cidUrl: string; attachment: EmailAttachment } | null
>()
const thumbCache = new Map<string, { cidUrl: string; attachment: EmailAttachment } | null>()
const cidAttachmentMap = new Map<string, EmailAttachment>()
const resolveAvatar = async (
creatorId?: string | null,
image?: string | null,
): Promise<string | undefined> => {
if (!image) return undefined
if (creatorId && avatarCache.has(creatorId)) {
const cached = avatarCache.get(creatorId)
return cached ? cached.cidUrl : undefined
}
const cid = `avatar-${creatorId || Math.random().toString(36).slice(2)}@shumai.internal`
const cidUrl = `cid:${cid}`
try {
if (image.startsWith('http://') || image.startsWith('https://')) {
const res = await fetch(image, { signal: AbortSignal.timeout(5000) })
if (res.ok) {
const arrayBuffer = await res.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
const contentType = res.headers.get('content-type') || 'image/jpeg'
const ext = getExtensionFromMime(contentType)
const resolved = {
cidUrl,
attachment: {
filename: `avatar-${creatorId || 'user'}.${ext}`,
content: buffer,
cid,
contentType,
},
}
if (creatorId) avatarCache.set(creatorId, resolved)
cidAttachmentMap.set(cidUrl, resolved.attachment)
return cidUrl
}
} else {
const bucket = process.env.S3_BUCKET || 'shumai'
const obj = await s3Service.getObject(bucket, image)
if (obj && obj.buffer && obj.buffer.length > 0) {
const contentType = obj.contentType || 'image/jpeg'
const ext = getExtensionFromMime(contentType)
const resolved = {
cidUrl,
attachment: {
filename: `avatar-${creatorId || 'user'}.${ext}`,
content: obj.buffer,
cid,
contentType,
},
}
if (creatorId) avatarCache.set(creatorId, resolved)
cidAttachmentMap.set(cidUrl, resolved.attachment)
return cidUrl
}
}
} catch (err) {
logger.debug(
{ err: err instanceof Error ? err.message : String(err), image, creatorId },
'Failed to resolve avatar image for inline email attachment',
)
}
if (creatorId) avatarCache.set(creatorId, null)
return undefined
}
const resolveThumbnail = async (
assetId?: string | null,
media?: unknown,
): Promise<string | undefined> => {
if (!assetId || !media) return undefined
if (thumbCache.has(assetId)) {
const cached = thumbCache.get(assetId)
return cached ? cached.cidUrl : undefined
}
const m = media as PrismaJson.MediaInfo | null
const key = m?.thumbnail?.key || m?.poster?.key
if (!key) return undefined
const cid = `thumb-${assetId}@shumai.internal`
const cidUrl = `cid:${cid}`
try {
const bucket = process.env.S3_BUCKET || 'shumai'
const obj = await s3Service.getObject(bucket, key)
if (obj && obj.buffer && obj.buffer.length > 0) {
const contentType = obj.contentType || 'image/jpeg'
const ext = getExtensionFromMime(contentType)
const resolved = {
cidUrl,
attachment: {
filename: `thumb-${assetId}.${ext}`,
content: obj.buffer,
cid,
contentType,
},
}
thumbCache.set(assetId, resolved)
cidAttachmentMap.set(cidUrl, resolved.attachment)
return cidUrl
}
} catch (err) {
logger.debug(
{ err: err instanceof Error ? err.message : String(err), assetId, key },
'Failed to resolve thumbnail image for inline email attachment',
)
}
thumbCache.set(assetId, null)
return undefined
}
const userItemsMap = new Map<
string,
{ user: (typeof members)[0]['user']; items: BatchedNotificationItem[] }
>()
for (const member of members) {
if (!member.user.email) continue
if (
member.user.type === 'agent' ||
member.user.email.endsWith('@shumai.ai') ||
member.user.email.startsWith('agent-')
) {
continue
}
const settingsMeta = await userMetadataService.getMetadata(
member.userId,
teamId,
'notification_settings',
)
const settings: NotificationSettings = settingsMeta
? (settingsMeta.value as NotificationSettings)
: {
comments: true,
replies: true,
mentions: true,
yourUploads: false,
otherUploads: true,
statusUpdates: true,
kanbanTasks: true,
kanbanComments: true,
}
for (const n of teamNotifs) {
// Actor check (do not notify self unless it's their upload and yourUploads is enabled)
if (n.creatorId === member.userId) {
if (n.type !== NotificationType.successful_file_uploaded || !settings.yourUploads) {
continue
}
}
// Targeted notification check
if (n.userId && n.userId !== member.userId) {
continue
}
// Project scope check
if (member.scope === 'project' && n.projectId) {
if (n.type !== NotificationType.mention && n.userId !== member.userId) {
const inProject = member.projectMembers.some((pm) => pm.projectId === n.projectId)
if (!inProject) continue
}
}
// Settings preference check
let allowed = false
switch (n.type) {
case NotificationType.comment_created:
allowed = settings.comments ?? true
break
case NotificationType.reply_created:
allowed = settings.replies ?? true
break
case NotificationType.mention:
allowed = settings.mentions ?? true
break
case NotificationType.successful_file_uploaded:
allowed =
member.userId === n.creatorId
? (settings.yourUploads ?? false)
: (settings.otherUploads ?? true)
break
case NotificationType.metadata_field_updated_status:
allowed = settings.statusUpdates ?? true
break
case NotificationType.kanban_task_created:
case NotificationType.kanban_task_assigned:
case NotificationType.kanban_task_status_updated:
case NotificationType.kanban_task_updated:
case NotificationType.kanban_task_deleted:
allowed = settings.kanbanTasks ?? true
break
case NotificationType.kanban_task_comment_created:
allowed = settings.kanbanComments ?? true
break
case NotificationType.new_user_join_team:
case NotificationType.new_user_join_project:
allowed = true
break
default:
allowed = true
break
}
if (!allowed) continue
const creatorAvatarUrl = await resolveAvatar(n.creatorId, n.creator?.image)
const assetThumbnailUrl = await resolveThumbnail(n.assetId, n.asset?.media)
const item: BatchedNotificationItem = {
id: n.id,
type: n.type || NotificationType.successful_file_uploaded,
creatorName: n.creator?.name || 'Someone',
creatorAvatarUrl,
teamId: n.teamId,
teamName: n.team?.name || 'Team',
projectId: n.projectId || n.asset?.projectId || undefined,
projectName: n.project?.name || n.asset?.project?.name || undefined,
assetId: n.assetId || undefined,
assetName: n.asset?.name || undefined,
assetThumbnailUrl,
kanbanTaskId: n.kanbanTaskId || undefined,
kanbanTaskTitle: n.kanbanTask?.title || undefined,
uploadTime: n.asset?.createdAt || n.createdAt,
createdAt: n.createdAt,
}
let entry = userItemsMap.get(member.userId)
if (!entry) {
entry = { user: member.user, items: [] }
userItemsMap.set(member.userId, entry)
}
entry.items.push(item)
}
}
// Deliver batched email to each user with pending items
for (const [userId, { user, items }] of userItemsMap) {
if (items.length === 0 || !user.email) continue
try {
const rendered = emailService.renderBatchedNotificationEmail({
teamId,
teamName: teamNotifs[0].team?.name || 'Team',
recipientName: user.name || 'Member',
items,
})
// Collect attachments for this email based on rendered items
const attachmentsMap = new Map<string, EmailAttachment>()
// Group items exactly as renderBatchedNotificationEmail does
const groups = new Map<string, BatchedNotificationItem[]>()
for (const item of items) {
const key = getNotificationBatchGroupKey(item)
const list = groups.get(key)
if (list) {
list.push(item)
} else {
groups.set(key, [item])
}
}
for (const [, cluster] of groups) {
const first = cluster[0]
if (first.creatorAvatarUrl) {
const att = cidAttachmentMap.get(first.creatorAvatarUrl)
if (att?.cid) attachmentsMap.set(att.cid, att)
}
if (cluster.length <= 3) {
// Detailed rows: individual avatars and thumbnails are rendered
for (const item of cluster) {
if (item.creatorAvatarUrl) {
const att = cidAttachmentMap.get(item.creatorAvatarUrl)
if (att?.cid) attachmentsMap.set(att.cid, att)
}
if (item.assetThumbnailUrl) {
const att = cidAttachmentMap.get(item.assetThumbnailUrl)
if (att?.cid) attachmentsMap.set(att.cid, att)
}
}
}
// If cluster.length > 3, thumbnails are not rendered, so we do not attach them
}
const attachments = Array.from(attachmentsMap.values())
await emailService.sendMail(emailSettings, {
to: user.email,
subject: rendered.subject,
html: rendered.html,
text: rendered.text,
attachments: attachments.length > 0 ? attachments : undefined,
})
} catch (err) {
logger.error(
{
userId,
email: user.email,
err: err instanceof Error ? err.message : String(err),
},
'Failed to deliver batched notification email to user',
)
}
}
}
// 5. Update batch status to processed
await prisma.notification.updateMany({
where: { id: { in: batchIds } },
data: { emailStatus: NotificationEmailStatus.processed },
})
return batchIds.length
} catch (err) {
logger.error(
{ err: err instanceof Error ? err.message : String(err), batchCount: batchIds.length },
'Unexpected failure in processPendingNotifications',
)
if (batchIds.length > 0) {
// Mark as processed so subsequent turns aren't permanently blocked
await prisma.notification
.updateMany({
where: { id: { in: batchIds } },
data: { emailStatus: NotificationEmailStatus.processed },
})
.catch((cleanErr) =>
logger.error({ cleanErr }, 'Failed to mark notifications processed on error'),
)
}
throw err
} finally {
this.isProcessing = false
}
}
}
export const notificationJobService = new NotificationJobService()
+104 -3
View File
@@ -365,7 +365,30 @@ describe('TeamService', () => {
})
const settings = await teamService.getSettings(team.id)
expect(settings).toEqual({ semanticSearchEnabled: false, appearance: { hideAgent: false } })
expect(settings).toEqual({
semanticSearchEnabled: false,
transcode: {
videoStrategy: 'best_match',
videoResolutions: ['480p', '720p', '1080p', '1440p', '2160p'],
hardwareAcceleration: 'off',
threads: 0,
hlsEnabled: false,
hlsResolutions: ['480p', '720p', '1080p'],
},
turntable: {
hasPassword: false,
isEnvConfigured: false,
url: undefined,
username: undefined,
},
gotenberg: {
hasPassword: false,
isEnvConfigured: false,
url: undefined,
username: undefined,
},
appearance: { hideAgent: false },
})
await teamService.updateSettings(team.id, 'theme', 'dark')
@@ -373,18 +396,64 @@ describe('TeamService', () => {
expect(newSettings).toEqual({
theme: 'dark',
semanticSearchEnabled: false,
transcode: {
videoStrategy: 'best_match',
videoResolutions: ['480p', '720p', '1080p', '1440p', '2160p'],
hardwareAcceleration: 'off',
threads: 0,
hlsEnabled: false,
hlsResolutions: ['480p', '720p', '1080p'],
},
turntable: {
hasPassword: false,
isEnvConfigured: false,
url: undefined,
username: undefined,
},
gotenberg: {
hasPassword: false,
isEnvConfigured: false,
url: undefined,
username: undefined,
},
appearance: { hideAgent: false },
})
await teamService.updateSettings(team.id, 'transcode.videoStrategy', 'all')
await teamService.updateSettings(team.id, 'transcode.videoStrategy', 'multi')
await teamService.updateSettings(team.id, 'transcode.videoResolutions', ['720p', '1080p'])
await teamService.updateSettings(team.id, 'transcode.hardwareAcceleration', 'auto')
await teamService.updateSettings(team.id, 'transcode.threads', 4)
await teamService.updateSettings(team.id, 'transcode.hlsEnabled', true)
await teamService.updateSettings(team.id, 'transcode.hlsResolutions', [
'720p',
'1080p',
'2160p',
])
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', threads: 4 },
transcode: {
videoStrategy: 'multi',
videoResolutions: ['720p', '1080p'],
hardwareAcceleration: 'auto',
threads: 4,
hlsEnabled: true,
hlsResolutions: ['720p', '1080p', '2160p'],
},
turntable: {
hasPassword: false,
isEnvConfigured: false,
url: undefined,
username: undefined,
},
gotenberg: {
hasPassword: false,
isEnvConfigured: false,
url: undefined,
username: undefined,
},
appearance: { hideAgent: true },
semanticSearchEnabled: false,
})
@@ -504,4 +573,36 @@ describe('TeamService', () => {
expect(result).toBe(false)
})
})
it('should not leak emailNotification or credentials in getSettings', async () => {
const team = await prisma.team.create({
data: {
name: 'Team With Credentials',
settings: {
transcode: {
videoStrategy: 'best_match',
hardwareAcceleration: 'off',
threads: 4,
},
appearance: {
hideAgent: true,
},
emailNotification: {
enabled: true,
host: 'smtp.secret.com',
port: 587,
password: 'super-secret-smtp-password',
from: 'noreply@secret.com',
},
},
},
})
const settings = await teamService.getSettings(team.id)
expect(settings).toBeDefined()
expect(settings.transcode?.threads).toBe(4)
expect(settings.appearance?.hideAgent).toBe(true)
expect((settings as Record<string, unknown>).emailNotification).toBeUndefined()
})
})
+75 -5
View File
@@ -7,6 +7,8 @@ import { getAvatarUrl } from '@shumai/core/src/user/avatar'
import { HTTPException } from 'hono/http-exception'
import { getAllowedAgentRoles } from '@shumai/core/src/agent/permissions'
import { sandboxService } from '@shumai/core/src/sandbox/sandbox-service'
import { turntableService } from '@shumai/core/src/turntable/turntable'
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
import {
ServiceCreateTeamRequest,
ServiceGetUserTeamsRequest,
@@ -33,7 +35,12 @@ export class TeamService {
data: {
name: 'Default Team',
settings: {
transcode: { videoStrategy: 'best_match', hardwareAcceleration: 'off', threads: 0 },
transcode: {
videoStrategy: 'best_match',
videoResolutions: ['480p', '720p', '1080p', '1440p', '2160p'],
hardwareAcceleration: 'off',
threads: 0,
},
},
sandbox: { create: {} },
},
@@ -294,19 +301,53 @@ export class TeamService {
where: { id: teamId },
})
if (!team) throw new HTTPException(404, { message: 'team not found' })
const settings = (team.settings || {}) as TeamSettingsResponse
const rawSettings = { ...(team.settings || {}) } as PrismaJson.Settings & {
[key: string]: unknown
}
delete rawSettings.emailNotification
const settings = rawSettings as TeamSettingsResponse
const embeddingAgent = await prisma.agent.findFirst({
where: { teamId, type: 'embedding', enabled: true },
})
settings.semanticSearchEnabled = !!embeddingAgent
if (!settings.transcode) {
settings.transcode = {
videoStrategy: 'best_match',
videoResolutions: ['480p', '720p', '1080p', '1440p', '2160p'],
hardwareAcceleration: 'off',
threads: 0,
hlsEnabled: false,
hlsResolutions: ['480p', '720p', '1080p'],
}
} else {
const strategyStr = settings.transcode.videoStrategy as string | undefined
if (strategyStr === 'single' || strategyStr === 'disable') {
settings.transcode.videoStrategy = 'best_match'
} else if (strategyStr === 'full' || strategyStr === 'all') {
settings.transcode.videoStrategy = 'multi'
}
if (!settings.transcode.videoResolutions) {
settings.transcode.videoResolutions = ['480p', '720p', '1080p', '1440p', '2160p']
}
if (settings.transcode.hlsEnabled === undefined) {
settings.transcode.hlsEnabled = false
}
if (!settings.transcode.hlsResolutions) {
settings.transcode.hlsResolutions = ['480p', '720p', '1080p']
}
}
if (!settings.appearance) {
settings.appearance = { hideAgent: false }
} else if (settings.appearance.hideAgent === undefined) {
settings.appearance.hideAgent = false
}
settings.turntable = await turntableService.getSettings(teamId)
settings.gotenberg = await gotenbergService.getSettings(teamId)
return settings
}
@@ -320,10 +361,25 @@ export class TeamService {
if (!settings.transcode) {
settings.transcode = {}
}
settings.transcode.videoStrategy = value as NonNullable<
const rawStrategy = value as string
let strategy = rawStrategy
if (rawStrategy === 'single' || rawStrategy === 'disable') {
strategy = 'best_match'
} else if (rawStrategy === 'full' || rawStrategy === 'all') {
strategy = 'multi'
}
settings.transcode.videoStrategy = strategy as NonNullable<
TeamSettingsResponse['transcode']
>['videoStrategy']
delete settings['transcode.videoStrategy']
} else if (key === 'transcode.videoResolutions') {
if (!settings.transcode) {
settings.transcode = {}
}
settings.transcode.videoResolutions = value as NonNullable<
TeamSettingsResponse['transcode']
>['videoResolutions']
delete settings['transcode.videoResolutions']
} else if (key === 'transcode.hardwareAcceleration') {
if (!settings.transcode) {
settings.transcode = {}
@@ -338,6 +394,20 @@ export class TeamService {
}
settings.transcode.threads = Number(value)
delete settings['transcode.threads']
} else if (key === 'transcode.hlsEnabled') {
if (!settings.transcode) {
settings.transcode = {}
}
settings.transcode.hlsEnabled = Boolean(value)
delete settings['transcode.hlsEnabled']
} else if (key === 'transcode.hlsResolutions') {
if (!settings.transcode) {
settings.transcode = {}
}
settings.transcode.hlsResolutions = value as NonNullable<
TeamSettingsResponse['transcode']
>['hlsResolutions']
delete settings['transcode.hlsResolutions']
} else if (key === 'appearance.hideAgent') {
if (!settings.appearance) {
settings.appearance = {}
@@ -348,12 +418,12 @@ export class TeamService {
settings[key] = value
}
const updated = await prisma.team.update({
await prisma.team.update({
where: { id: teamId },
data: { settings: settings as unknown as PrismaJson.Settings },
})
return (updated.settings || {}) as TeamSettingsResponse
return this.getSettings(teamId)
}
async getSandboxSettings(teamId: string): Promise<SandboxSettings> {
@@ -0,0 +1,737 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import * as fs from 'fs'
import {
extractEmbeddedJpeg,
validateExtractedJpeg,
validateExtractedImage,
decodeRawWithDcraw,
extractAndValidateRawPreview,
EXIF_ORIENTATION_TO_ROTATION,
withTimeout,
} from './raw-extract'
// Mock exiftool-vendored
vi.mock('exiftool-vendored', () => ({
exiftool: {
extractBinaryTag: vi.fn(),
read: vi.fn(),
},
}))
// Mock sharp
vi.mock('sharp', () => {
const mockMetadata = vi.fn()
const mockSharp = vi.fn(() => ({
metadata: mockMetadata,
}))
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(mockSharp as any)._mockMetadata = mockMetadata
return { default: mockSharp }
})
// Mock child_process
vi.mock('child_process', () => ({
execFile: vi.fn(),
}))
import { exiftool } from 'exiftool-vendored'
import sharp from 'sharp'
import { execFile } from 'child_process'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockMetadata = (sharp as any)._mockMetadata as ReturnType<typeof vi.fn>
const mockExtractBinaryTag = vi.mocked(exiftool.extractBinaryTag)
const mockRead = vi.mocked(exiftool.read)
const mockExecFile = vi.mocked(execFile)
describe('extractEmbeddedJpeg', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('extracts from JpgFromRaw2 first to a temporary file', async () => {
mockExtractBinaryTag.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'jpeg-data')
})
mockRead.mockResolvedValueOnce({ Orientation: 1 } as never)
const result = await extractEmbeddedJpeg('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(fs.existsSync(result!.previewPath)).toBe(true)
expect(result!.orientation).toBe(1)
expect(mockExtractBinaryTag).toHaveBeenCalledWith(
'JpgFromRaw2',
'/path/to/photo.cr2',
expect.stringContaining('preview-JpgFromRaw2'),
)
// Test cleanup
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('falls back to JpgFromRaw when JpgFromRaw2 fails', async () => {
mockExtractBinaryTag
.mockRejectedValueOnce(new Error('0 output files created'))
.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'jpeg-data')
})
mockRead.mockResolvedValueOnce({ Orientation: 6 } as never)
const result = await extractEmbeddedJpeg('/path/to/photo.nef')
expect(result).not.toBeNull()
expect(fs.existsSync(result!.previewPath)).toBe(true)
expect(result!.orientation).toBe(6)
expect(mockExtractBinaryTag).toHaveBeenCalledTimes(2)
expect(mockExtractBinaryTag).toHaveBeenNthCalledWith(
2,
'JpgFromRaw',
'/path/to/photo.nef',
expect.stringContaining('preview-JpgFromRaw'),
)
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('falls back to PreviewImage when JpgFromRaw2 and JpgFromRaw fail', async () => {
mockExtractBinaryTag
.mockRejectedValueOnce(new Error('0 output files created'))
.mockRejectedValueOnce(new Error('0 output files created'))
.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'preview-data')
})
mockRead.mockResolvedValueOnce({ Orientation: 3 } as never)
const result = await extractEmbeddedJpeg('/path/to/photo.arw')
expect(result).not.toBeNull()
expect(fs.existsSync(result!.previewPath)).toBe(true)
expect(result!.orientation).toBe(3)
expect(mockExtractBinaryTag).toHaveBeenCalledTimes(3)
expect(mockExtractBinaryTag).toHaveBeenNthCalledWith(
3,
'PreviewImage',
'/path/to/photo.arw',
expect.stringContaining('preview-PreviewImage'),
)
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('returns null and cleans up when all tags fail', async () => {
mockExtractBinaryTag
.mockRejectedValueOnce(new Error('0 output files created'))
.mockRejectedValueOnce(new Error('0 output files created'))
.mockRejectedValueOnce(new Error('0 output files created'))
const result = await extractEmbeddedJpeg('/path/to/photo.cr2')
expect(result).toBeNull()
expect(mockExtractBinaryTag).toHaveBeenCalledTimes(3)
})
it('returns undefined orientation when EXIF read fails', async () => {
mockExtractBinaryTag.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'jpeg-data')
})
mockRead.mockRejectedValueOnce(new Error('EXIF read failed'))
const result = await extractEmbeddedJpeg('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(result!.orientation).toBeUndefined()
result!.cleanup()
})
it('returns undefined orientation when orientation value is out of range', async () => {
mockExtractBinaryTag.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'jpeg-data')
})
mockRead.mockResolvedValueOnce({ Orientation: 9 } as never)
const result = await extractEmbeddedJpeg('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(result!.orientation).toBeUndefined()
result!.cleanup()
})
it('returns undefined orientation when orientation is not a number', async () => {
mockExtractBinaryTag.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'jpeg-data')
})
mockRead.mockResolvedValueOnce({ Orientation: 'Horizontal' } as never)
const result = await extractEmbeddedJpeg('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(result!.orientation).toBeUndefined()
result!.cleanup()
})
it('skips remaining tags and aborts early when extraction times out', async () => {
const origEnv = process.env.EXIFTOOL_TIMEOUT_MS
try {
process.env.EXIFTOOL_TIMEOUT_MS = '20'
// Hang on first tag
mockExtractBinaryTag.mockImplementationOnce(
() => new Promise((resolve) => setTimeout(resolve, 300)),
)
const result = await extractEmbeddedJpeg('/path/to/photo.cr2')
expect(result).toBeNull()
// Crucial: should break immediately after the first timeout instead of trying remaining 2 tags
expect(mockExtractBinaryTag).toHaveBeenCalledTimes(1)
} finally {
if (origEnv !== undefined) {
process.env.EXIFTOOL_TIMEOUT_MS = origEnv
} else {
delete process.env.EXIFTOOL_TIMEOUT_MS
}
}
})
})
describe('validateExtractedJpeg', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('returns dimensions for a valid JPEG file', async () => {
mockMetadata.mockResolvedValueOnce({ width: 6000, height: 4000 })
const result = await validateExtractedJpeg('/tmp/valid-jpeg.jpg')
expect(result).toEqual({ width: 6000, height: 4000 })
})
it('returns null when metadata has zero width', async () => {
mockMetadata.mockResolvedValueOnce({ width: 0, height: 4000 })
const result = await validateExtractedJpeg('/tmp/bad-jpeg.jpg')
expect(result).toBeNull()
})
it('returns null when metadata has no dimensions', async () => {
mockMetadata.mockResolvedValueOnce({})
const result = await validateExtractedJpeg('/tmp/bad-jpeg.jpg')
expect(result).toBeNull()
})
it('returns null when sharp throws', async () => {
mockMetadata.mockRejectedValueOnce(new Error('Invalid image'))
const result = await validateExtractedJpeg('/tmp/corrupt-jpeg.jpg')
expect(result).toBeNull()
})
})
describe('validateExtractedImage', () => {
it('is an alias for validateExtractedJpeg', () => {
expect(validateExtractedImage).toBe(validateExtractedJpeg)
})
})
describe('decodeRawWithDcraw', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('decodes RAW using camera white balance, sRGB, and TIFF output without -h when longest dimension <= 8192', async () => {
mockRead.mockResolvedValueOnce({
ImageWidth: 6000,
ImageHeight: 4000,
Orientation: 1,
} as never)
let executedArgs: string[] = []
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
executedArgs = args as string[]
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(fs.existsSync(result!.previewPath)).toBe(true)
expect(result!.orientation).toBeUndefined()
expect(result!.rawWidth).toBe(6000)
expect(result!.rawHeight).toBe(4000)
expect(executedArgs).toContain('-w')
expect(executedArgs).toContain('-o')
expect(executedArgs).toContain('1')
expect(executedArgs).toContain('-T')
expect(executedArgs).toContain('-Z')
expect(executedArgs).not.toContain('-h')
expect(executedArgs[executedArgs.length - 1]).toBe('/path/to/photo.cr2')
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('enables half-size (-h) when longest dimension > 8192px and computes upright raw dimensions', async () => {
mockRead.mockResolvedValueOnce({
ImageWidth: 9504,
ImageHeight: 6336,
Orientation: 6,
} as never)
let executedArgs: string[] = []
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
executedArgs = args as string[]
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.arw')
expect(result).not.toBeNull()
expect(executedArgs).toContain('-h')
expect(result!.orientation).toBeUndefined()
// For orientation 6 (90 CW), upright raw dimensions are swapped
expect(result!.rawWidth).toBe(6336)
expect(result!.rawHeight).toBe(9504)
result!.cleanup()
})
it('omits -h when longest dimension is exactly 8192px', async () => {
mockRead.mockResolvedValueOnce({
ImageWidth: 8192,
ImageHeight: 5464,
Orientation: 1,
} as never)
let executedArgs: string[] = []
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
executedArgs = args as string[]
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.nef')
expect(result).not.toBeNull()
expect(executedArgs).not.toContain('-h')
result!.cleanup()
})
it('defaults to full size without -h when EXIF metadata cannot be read', async () => {
mockRead.mockRejectedValueOnce(new Error('Exif read failure'))
let executedArgs: string[] = []
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
executedArgs = args as string[]
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.dng')
expect(result).not.toBeNull()
expect(executedArgs).not.toContain('-h')
result!.cleanup()
})
it('defaults to full size without -h when EXIF metadata read times out', async () => {
const origEnv = process.env.EXIFTOOL_TIMEOUT_MS
try {
process.env.EXIFTOOL_TIMEOUT_MS = '20'
mockRead.mockImplementationOnce(() => new Promise((resolve) => setTimeout(resolve, 300)))
let executedArgs: string[] = []
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
executedArgs = args as string[]
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.dng')
expect(result).not.toBeNull()
expect(executedArgs).not.toContain('-h')
result!.cleanup()
} finally {
if (origEnv !== undefined) {
process.env.EXIFTOOL_TIMEOUT_MS = origEnv
} else {
delete process.env.EXIFTOOL_TIMEOUT_MS
}
}
})
it('returns null and cleans up when dcraw_emu exits with non-zero code', async () => {
mockRead.mockResolvedValueOnce({ ImageWidth: 6000, ImageHeight: 4000 } as never)
mockExecFile.mockImplementationOnce((_bin, _args, _opts, cb) => {
const callback = typeof _opts === 'function' ? _opts : cb
const err = new Error('Command failed: dcraw_emu')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(err as any).code = 1
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(err)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.cr2')
expect(result).toBeNull()
})
it('returns null and cleans up when dcraw_emu times out', async () => {
mockRead.mockResolvedValueOnce({ ImageWidth: 6000, ImageHeight: 4000 } as never)
mockExecFile.mockImplementationOnce((_bin, _args, _opts, cb) => {
const callback = typeof _opts === 'function' ? _opts : cb
const err = new Error('Process timed out')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(err as any).code = 'ETIMEDOUT'
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(err)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.cr2')
expect(result).toBeNull()
})
it('returns null and cleans up when dcraw_emu is not found (ENOENT)', async () => {
mockRead.mockResolvedValueOnce({ ImageWidth: 6000, ImageHeight: 4000 } as never)
mockExecFile.mockImplementationOnce((_bin, _args, _opts, cb) => {
const callback = typeof _opts === 'function' ? _opts : cb
const err = new Error('spawn dcraw_emu ENOENT')
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(err as any).code = 'ENOENT'
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(err)
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.cr2')
expect(result).toBeNull()
})
it('returns null and cleans up when output TIFF is missing or empty', async () => {
mockRead.mockResolvedValueOnce({ ImageWidth: 6000, ImageHeight: 4000 } as never)
mockExecFile.mockImplementationOnce((_bin, _args, _opts, cb) => {
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await decodeRawWithDcraw('/path/to/photo.cr2')
expect(result).toBeNull()
})
})
describe('extractAndValidateRawPreview', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('returns previewPath, dimensions, orientation, and cleanup for valid RAW using embedded JPEG first', async () => {
mockExtractBinaryTag.mockImplementationOnce(async (_tag, _src, dest) => {
fs.writeFileSync(dest, 'jpeg-data')
})
mockRead.mockResolvedValueOnce({ Orientation: 6, ImageWidth: 4000, ImageHeight: 3000 } as never)
mockMetadata.mockResolvedValueOnce({ width: 4000, height: 3000 })
const result = await extractAndValidateRawPreview('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(fs.existsSync(result!.previewPath)).toBe(true)
expect(result!.width).toBe(4000)
expect(result!.height).toBe(3000)
expect(result!.orientation).toBe(6)
expect(mockExecFile).not.toHaveBeenCalled()
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('falls back to dcraw_emu when embedded preview extraction fails', async () => {
mockExtractBinaryTag
.mockRejectedValueOnce(new Error('fail'))
.mockRejectedValueOnce(new Error('fail'))
.mockRejectedValueOnce(new Error('fail'))
mockRead.mockResolvedValueOnce({
ImageWidth: 6000,
ImageHeight: 4000,
Orientation: 1,
} as never)
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
mockMetadata.mockResolvedValueOnce({ width: 6000, height: 4000 })
const result = await extractAndValidateRawPreview('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(mockExecFile).toHaveBeenCalled()
expect(result!.width).toBe(6000)
expect(result!.height).toBe(4000)
expect(result!.rawWidth).toBe(6000)
expect(result!.rawHeight).toBe(4000)
expect(result!.orientation).toBeUndefined()
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('falls back to dcraw_emu when extracted embedded JPEG is corrupt', async () => {
let createdJpegPath = ''
mockExtractBinaryTag.mockImplementationOnce(async (_tag, _src, dest) => {
createdJpegPath = dest
fs.writeFileSync(dest, 'corrupt-jpeg')
})
mockRead.mockResolvedValueOnce({ Orientation: 1 } as never)
mockMetadata.mockRejectedValueOnce(new Error('Not a valid image'))
// Fallback dcraw_emu
mockRead.mockResolvedValueOnce({ ImageWidth: 6000, ImageHeight: 4000 } as never)
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
mockMetadata.mockResolvedValueOnce({ width: 6000, height: 4000 })
const result = await extractAndValidateRawPreview('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(fs.existsSync(createdJpegPath)).toBe(false) // Embedded jpeg was cleaned up
expect(fs.existsSync(result!.previewPath)).toBe(true)
result!.cleanup()
expect(fs.existsSync(result!.previewPath)).toBe(false)
})
it('returns null when both embedded extraction and dcraw_emu fail', async () => {
mockExtractBinaryTag
.mockRejectedValueOnce(new Error('fail'))
.mockRejectedValueOnce(new Error('fail'))
.mockRejectedValueOnce(new Error('fail'))
mockRead.mockRejectedValueOnce(new Error('fail'))
mockExecFile.mockImplementationOnce((_bin, _args, _opts, cb) => {
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(new Error('dcraw failed'))
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
const result = await extractAndValidateRawPreview('/path/to/photo.cr2')
expect(result).toBeNull()
})
it('returns null and cleans up when decoded TIFF is corrupt', async () => {
mockExtractBinaryTag
.mockRejectedValueOnce(new Error('fail'))
.mockRejectedValueOnce(new Error('fail'))
.mockRejectedValueOnce(new Error('fail'))
let createdTiff = ''
mockRead.mockResolvedValueOnce({ ImageWidth: 6000, ImageHeight: 4000 } as never)
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
createdTiff = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(createdTiff, 'corrupt-tiff')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
mockMetadata.mockRejectedValueOnce(new Error('Invalid TIFF'))
const result = await extractAndValidateRawPreview('/path/to/photo.cr2')
expect(result).toBeNull()
expect(fs.existsSync(createdTiff)).toBe(false)
})
it('falls back to dcraw_emu when embedded preview extraction times out', async () => {
const origEnv = process.env.EXIFTOOL_TIMEOUT_MS
try {
process.env.EXIFTOOL_TIMEOUT_MS = '20'
// Hang on extractBinaryTag
mockExtractBinaryTag.mockImplementationOnce(
() => new Promise((resolve) => setTimeout(resolve, 300)),
)
mockRead.mockResolvedValueOnce({
ImageWidth: 6000,
ImageHeight: 4000,
Orientation: 1,
} as never)
mockExecFile.mockImplementationOnce((_bin, args, _opts, cb) => {
const tiffDest = (args as string[])[(args as string[]).indexOf('-Z') + 1]
fs.writeFileSync(tiffDest, 'tiff-data')
const callback = typeof _opts === 'function' ? _opts : cb
if (callback) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
;(callback as any)(null, { stdout: '', stderr: '' })
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return {} as any
})
mockMetadata.mockResolvedValueOnce({ width: 6000, height: 4000 })
const result = await extractAndValidateRawPreview('/path/to/photo.cr2')
expect(result).not.toBeNull()
expect(mockExecFile).toHaveBeenCalled()
expect(result!.width).toBe(6000)
expect(result!.height).toBe(4000)
result!.cleanup()
} finally {
if (origEnv !== undefined) {
process.env.EXIFTOOL_TIMEOUT_MS = origEnv
} else {
delete process.env.EXIFTOOL_TIMEOUT_MS
}
}
})
})
describe('withTimeout', () => {
it('resolves when promise settles before timeout', async () => {
const result = await withTimeout(Promise.resolve('ok'), 1000)
expect(result).toBe('ok')
})
it('rejects with timeout error when promise exceeds timeout', async () => {
const hanging = new Promise((resolve) => setTimeout(resolve, 500))
await expect(withTimeout(hanging, 20, 'TestTask')).rejects.toThrow(
'TestTask timed out after 20ms',
)
})
it('propagates underlying promise rejection before timeout', async () => {
const failing = Promise.reject(new Error('fail fast'))
await expect(withTimeout(failing, 1000, 'TestTask')).rejects.toThrow('fail fast')
})
it('prevents unhandled rejection if promise rejects after timeout', async () => {
const delayedReject = new Promise((_, reject) =>
setTimeout(() => reject(new Error('late error')), 40),
)
await expect(withTimeout(delayedReject, 10, 'TestTask')).rejects.toThrow(
'TestTask timed out after 10ms',
)
await new Promise((resolve) => setTimeout(resolve, 60))
})
})
describe('EXIF_ORIENTATION_TO_ROTATION', () => {
it('maps all 8 EXIF orientations', () => {
expect(Object.keys(EXIF_ORIENTATION_TO_ROTATION)).toHaveLength(8)
for (let i = 1; i <= 8; i++) {
expect(EXIF_ORIENTATION_TO_ROTATION[i]).toBeDefined()
}
})
it('has correct rotation for landscape (1)', () => {
expect(EXIF_ORIENTATION_TO_ROTATION[1]).toEqual({})
})
it('has correct rotation for 90° CW (6)', () => {
expect(EXIF_ORIENTATION_TO_ROTATION[6]).toEqual({ angle: 90 })
})
it('has correct rotation for 180° (3)', () => {
expect(EXIF_ORIENTATION_TO_ROTATION[3]).toEqual({ angle: 180 })
})
it('has correct rotation for 270° CW (8)', () => {
expect(EXIF_ORIENTATION_TO_ROTATION[8]).toEqual({ angle: 270 })
})
it('has correct rotation for mirror horizontal (2)', () => {
expect(EXIF_ORIENTATION_TO_ROTATION[2]).toEqual({ flop: true })
})
})
+395
View File
@@ -0,0 +1,395 @@
import { execFile } from 'child_process'
import { exiftool } from 'exiftool-vendored'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
import sharp from 'sharp'
import { promisify } from 'util'
import { logger } from '@shumai/core/src/logger'
const execFileAsync = promisify(execFile)
export interface RawExtractResult {
previewPath: string
cleanup: () => void
/** EXIF orientation from the RAW container (1–8), or undefined if absent or already applied. */
orientation?: number
/** Original unoriented or oriented image dimensions from EXIF if available */
rawWidth?: number
rawHeight?: number
}
export interface RawPreviewResult {
previewPath: string
cleanup: () => void
width: number
height: number
orientation?: number
/**
* True when the file is already upright (dcraw_emu output), so downstream sharp must not
* auto-orient it even though `orientation` is undefined.
*/
orientationApplied?: boolean
rawWidth?: number
rawHeight?: number
}
export interface DecodeRawOptions {
timeoutMs?: number
signal?: AbortSignal
}
/**
* Maps EXIF orientation values (1–8) to Sharp rotation operations.
* Follows the same mapping as Immich's ORIENTATION_TO_SHARP_ROTATION.
*/
export const EXIF_ORIENTATION_TO_ROTATION: Record<
number,
{ angle?: number; flip?: boolean; flop?: boolean }
> = {
1: {}, // Horizontal (normal)
2: { flop: true }, // Mirror horizontal
3: { angle: 180 }, // Rotate 180°
4: { angle: 180, flop: true }, // Mirror vertical
5: { angle: 270, flip: true }, // Mirror horizontal + rotate 270° CW
6: { angle: 90 }, // Rotate 90° CW
7: { angle: 90, flip: true }, // Mirror horizontal + rotate 90° CW
8: { angle: 270 }, // Rotate 270° CW
}
const DEFAULT_EXIFTOOL_TIMEOUT_MS = 15_000
function getExifToolTimeoutMs(): number {
const envVal = process.env.EXIFTOOL_TIMEOUT_MS
if (envVal) {
const parsed = parseInt(envVal, 10)
if (!isNaN(parsed) && parsed > 0) {
return parsed
}
}
return DEFAULT_EXIFTOOL_TIMEOUT_MS
}
/**
* Wraps a promise with a timeout. If the timeout triggers first,
* the returned promise rejects with a timeout error and attaches a no-op handler
* to the underlying promise to prevent unhandled rejections.
*/
export function withTimeout<T>(
promise: Promise<T>,
timeoutMs: number,
operationName = 'Operation',
): Promise<T> {
let timer: ReturnType<typeof setTimeout> | undefined
const timeoutPromise = new Promise<never>((_, reject) => {
timer = setTimeout(() => {
reject(new Error(`${operationName} timed out after ${timeoutMs}ms`))
}, timeoutMs)
})
promise.catch(() => {})
return Promise.race([promise, timeoutPromise]).finally(() => {
if (timer) clearTimeout(timer)
})
}
/**
* Attempt to extract an embedded JPEG preview from a camera RAW file to a temporary file.
*
* Tries tags in priority order (matching Immich, skipping PreviewJXL):
* 1. JpgFromRaw2 — secondary full-resolution JPEG (newer Sony/Canon/Nikon)
* 2. JpgFromRaw — primary full-size embedded JPEG
* 3. PreviewImage — smaller embedded preview fallback
*
* Also reads the EXIF orientation from the RAW container so callers can
* apply it to the extracted buffer/file (which often lacks its own orientation tag).
*
* Returns null if no usable embedded JPEG exists.
*/
export async function extractEmbeddedJpeg(
rawFilePath: string,
targetDir?: string,
): Promise<RawExtractResult | null> {
const tags = ['JpgFromRaw2', 'JpgFromRaw', 'PreviewImage'] as const
const ownTempDir = !targetDir
const workDir = targetDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'raw-extract-'))
const cleanup = () => {
try {
if (ownTempDir && fs.existsSync(workDir)) {
fs.rmSync(workDir, { recursive: true, force: true })
}
} catch (err) {
logger.warn({ workDir, err }, 'Failed to clean up raw extraction temporary directory')
}
}
const exiftoolTimeoutMs = getExifToolTimeoutMs()
for (const tag of tags) {
const candidatePath = path.join(workDir, `preview-${tag}-${Date.now()}.jpg`)
try {
await withTimeout(
exiftool.extractBinaryTag(tag, rawFilePath, candidatePath),
exiftoolTimeoutMs,
`exiftool.extractBinaryTag(${tag})`,
)
if (fs.existsSync(candidatePath) && fs.statSync(candidatePath).size > 0) {
logger.debug({ tag, rawFilePath, candidatePath }, 'Extracted embedded JPEG from RAW')
// Read orientation and container dimensions from the RAW container's EXIF metadata.
let orientation: number | undefined
let rawWidth: number | undefined
let rawHeight: number | undefined
try {
const exif = await withTimeout(
exiftool.read(rawFilePath),
exiftoolTimeoutMs,
'exiftool.read',
)
const rawOrientation = exif.Orientation
if (typeof rawOrientation === 'number' && rawOrientation >= 1 && rawOrientation <= 8) {
orientation = rawOrientation
}
const w =
typeof exif.ImageWidth === 'number'
? exif.ImageWidth
: typeof exif.ExifImageWidth === 'number'
? exif.ExifImageWidth
: undefined
const h =
typeof exif.ImageHeight === 'number'
? exif.ImageHeight
: typeof exif.ExifImageHeight === 'number'
? exif.ExifImageHeight
: undefined
if (w && h && w > 0 && h > 0) {
rawWidth = w
rawHeight = h
}
} catch {
logger.debug({ rawFilePath }, 'Could not read EXIF orientation from RAW container')
}
return { previewPath: candidatePath, cleanup, orientation, rawWidth, rawHeight }
}
} catch (err) {
const isTimeout = err instanceof Error && err.message.includes('timed out')
logger.debug({ tag, rawFilePath, err, isTimeout }, `Could not extract ${tag} from RAW file`)
try {
if (fs.existsSync(candidatePath)) {
fs.rmSync(candidatePath, { force: true })
}
} catch {
// ignore
}
if (isTimeout) {
logger.warn(
{ rawFilePath, tag, timeoutMs: exiftoolTimeoutMs },
'ExifTool extraction timed out; skipping remaining tags to avoid further delays',
)
break
}
}
}
cleanup()
logger.info({ rawFilePath }, 'No usable embedded JPEG found in RAW file')
return null
}
/**
* Fallback RAW decoder using dcraw_emu (from LibRaw).
*
* Used when no usable embedded JPEG preview exists in the RAW file.
*
* Decoding options:
* - Camera white balance and sRGB output (-w -o 1)
* - Output temporary TIFF (-T -Z <tempPath>)
* - Half-size processing (-h) enabled only when longest dimension > 8192px
*
* LibRaw auto-rotates the output image to upright orientation based on camera EXIF,
* so the returned orientation is undefined to avoid double-rotation in downstream Sharp.
*/
export async function decodeRawWithDcraw(
rawFilePath: string,
targetDir?: string,
options?: DecodeRawOptions,
): Promise<RawExtractResult | null> {
const ownTempDir = !targetDir
const workDir = targetDir ?? fs.mkdtempSync(path.join(os.tmpdir(), 'raw-decode-'))
const tempTiffPath = path.join(
workDir,
`decoded-${Date.now()}-${Math.random().toString(36).slice(2, 8)}.tiff`,
)
const cleanup = () => {
try {
if (ownTempDir && fs.existsSync(workDir)) {
fs.rmSync(workDir, { recursive: true, force: true })
} else if (fs.existsSync(tempTiffPath)) {
fs.rmSync(tempTiffPath, { force: true })
}
} catch (err) {
logger.warn({ workDir, tempTiffPath, err }, 'Failed to clean up dcraw temporary files')
}
}
// 1. Probe RAW dimensions and orientation via ExifTool to check for 8192px threshold
let useHalfSize = false
let rawWidth: number | undefined
let rawHeight: number | undefined
try {
const exiftoolTimeoutMs = getExifToolTimeoutMs()
const exif = await withTimeout(exiftool.read(rawFilePath), exiftoolTimeoutMs, 'exiftool.read')
const w =
typeof exif.ImageWidth === 'number'
? exif.ImageWidth
: typeof exif.ExifImageWidth === 'number'
? exif.ExifImageWidth
: undefined
const h =
typeof exif.ImageHeight === 'number'
? exif.ImageHeight
: typeof exif.ExifImageHeight === 'number'
? exif.ExifImageHeight
: undefined
if (w && h && w > 0 && h > 0) {
const longest = Math.max(w, h)
if (longest > 8192) {
useHalfSize = true
}
// Compute upright raw dimensions matching dcraw_emu's auto-rotation
const rawOrientation = exif.Orientation
const isSwapped =
typeof rawOrientation === 'number' && rawOrientation >= 5 && rawOrientation <= 8
rawWidth = isSwapped ? h : w
rawHeight = isSwapped ? w : h
}
} catch (err) {
logger.debug({ rawFilePath, err }, 'Could not read EXIF metadata for RAW dimension check')
}
// 2. Build dcraw_emu arguments
const args = ['-w', '-o', '1']
if (useHalfSize) {
args.push('-h')
}
args.push('-T', '-Z', tempTiffPath, rawFilePath)
const dcrawBin = process.env.DCRAW_EMU_PATH || 'dcraw_emu'
const envTimeout = process.env.DCRAW_EMU_TIMEOUT_MS
? parseInt(process.env.DCRAW_EMU_TIMEOUT_MS, 10)
: undefined
const timeoutMs = options?.timeoutMs ?? (envTimeout && !isNaN(envTimeout) ? envTimeout : 60_000)
try {
logger.debug({ dcrawBin, args, rawFilePath }, 'Executing dcraw_emu fallback')
await execFileAsync(dcrawBin, args, {
timeout: timeoutMs,
signal: options?.signal,
})
if (!fs.existsSync(tempTiffPath) || fs.statSync(tempTiffPath).size === 0) {
logger.warn({ rawFilePath, tempTiffPath }, 'dcraw_emu did not produce a valid output TIFF')
cleanup()
return null
}
return {
previewPath: tempTiffPath,
cleanup,
orientation: undefined, // dcraw_emu already auto-rotates upright based on camera EXIF
rawWidth,
rawHeight,
}
} catch (err) {
logger.warn({ rawFilePath, err }, 'dcraw_emu failed to decode RAW file')
cleanup()
return null
}
}
/**
* Validate that an extracted or decoded image file (JPEG, TIFF, etc.) is decodable.
* Returns dimensions if valid, null if corrupt/unusable.
*/
export async function validateExtractedImage(
filePath: string,
): Promise<{ width: number; height: number } | null> {
try {
const metadata = await sharp(filePath).metadata()
if (metadata.width && metadata.height && metadata.width > 0 && metadata.height > 0) {
return { width: metadata.width, height: metadata.height }
}
return null
} catch {
return null
}
}
/** Backward compatibility alias */
export const validateExtractedJpeg = validateExtractedImage
/**
* Extract and validate a preview from a RAW file to a temporary file.
*
* 1. Attempts ExifTool embedded JPEG extraction first.
* 2. If no embedded preview is available or extraction fails, falls back to dcraw_emu decoding.
*
* Returns a validated file path + dimensions + orientation + cleanup function, or null.
*/
export async function extractAndValidateRawPreview(
rawFilePath: string,
targetDir?: string,
): Promise<RawPreviewResult | null> {
// 1. Try ExifTool embedded JPEG extraction first
const extracted = await extractEmbeddedJpeg(rawFilePath, targetDir)
if (extracted) {
const dims = await validateExtractedImage(extracted.previewPath)
if (dims) {
return {
previewPath: extracted.previewPath,
cleanup: extracted.cleanup,
orientation: extracted.orientation,
rawWidth: extracted.rawWidth,
rawHeight: extracted.rawHeight,
...dims,
}
}
logger.warn(
{ rawFilePath },
'Extracted JPEG from RAW is not decodable, falling back to dcraw_emu',
)
extracted.cleanup()
} else {
logger.info(
{ rawFilePath },
'No usable embedded JPEG found in RAW file, falling back to dcraw_emu',
)
}
// 2. Fallback to dcraw_emu
const decoded = await decodeRawWithDcraw(rawFilePath, targetDir)
if (!decoded) {
return null
}
const dims = await validateExtractedImage(decoded.previewPath)
if (!dims) {
logger.warn({ rawFilePath }, 'Decoded TIFF from dcraw_emu is not decodable, skipping preview')
decoded.cleanup()
return null
}
return {
previewPath: decoded.previewPath,
cleanup: decoded.cleanup,
orientation: decoded.orientation,
orientationApplied: true,
rawWidth: decoded.rawWidth,
rawHeight: decoded.rawHeight,
...dims,
}
}
@@ -0,0 +1,252 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import * as fs from 'fs'
import * as path from 'path'
import sharp from 'sharp'
import { transcodeService } from './transcode'
// Only the storage layer is mocked: these tests run the real sharp pipeline end to end.
vi.mock('@shumai/core/src/s3/s3', () => ({
s3Service: {
downloadToFile: vi.fn(),
putObject: vi.fn(),
resolveInput: vi.fn(),
presign: vi.fn(),
},
}))
// Only the RAW preview extraction is replaced, so the RAW branch of transcodeImage can be driven
// with a prepared file (the dcraw_emu fallback result) without ExifTool or dcraw_emu installed.
const extractRawMock = vi.hoisted(() => vi.fn())
vi.mock('./raw-extract', async (importOriginal) => ({
...(await importOriginal<typeof import('./raw-extract')>()),
extractAndValidateRawPreview: extractRawMock,
}))
// Windows keeps cached files open, which would make the temp dir cleanup fail with EBUSY.
sharp.cache(false)
type Corner = 'TL' | 'TR' | 'BL' | 'BR'
// Stored (sensor) pixels are landscape. Each quadrant has its own color so the direction of the
// rotation or flip can be read back from the corners of the output.
const STORED_WIDTH = 64
const STORED_HEIGHT = 48
const QUADRANT_COLORS: Record<Corner, [number, number, number]> = {
TL: [220, 30, 30], // red
TR: [30, 200, 30], // green
BL: [30, 30, 220], // blue
BR: [230, 230, 30], // yellow
}
/**
* For each EXIF orientation: the displayed size and which stored corner ends up at the displayed
* top-left and bottom-right. Orientations 5 to 8 swap width and height.
*/
const ORIENTATIONS: Array<{
orientation: number
name: string
swapped: boolean
topLeftIs: Corner
bottomRightIs: Corner
}> = [
{ orientation: 1, name: 'normal', swapped: false, topLeftIs: 'TL', bottomRightIs: 'BR' },
{
orientation: 2,
name: 'mirror horizontal',
swapped: false,
topLeftIs: 'TR',
bottomRightIs: 'BL',
},
{ orientation: 3, name: 'rotate 180', swapped: false, topLeftIs: 'BR', bottomRightIs: 'TL' },
{ orientation: 4, name: 'mirror vertical', swapped: false, topLeftIs: 'BL', bottomRightIs: 'TR' },
{ orientation: 5, name: 'transpose', swapped: true, topLeftIs: 'TL', bottomRightIs: 'BR' },
{ orientation: 6, name: 'rotate 90 CW', swapped: true, topLeftIs: 'BL', bottomRightIs: 'TR' },
{ orientation: 7, name: 'transverse', swapped: true, topLeftIs: 'BR', bottomRightIs: 'TL' },
{ orientation: 8, name: 'rotate 270 CW', swapped: true, topLeftIs: 'TR', bottomRightIs: 'BL' },
]
async function makeJpeg(orientation: number): Promise<Buffer> {
const halfW = STORED_WIDTH / 2
const halfH = STORED_HEIGHT / 2
const block = (corner: Corner) => ({
create: {
width: halfW,
height: halfH,
channels: 3 as const,
background: {
r: QUADRANT_COLORS[corner][0],
g: QUADRANT_COLORS[corner][1],
b: QUADRANT_COLORS[corner][2],
},
},
})
const tile = async (corner: Corner) => sharp(block(corner)).png().toBuffer()
return sharp({
create: {
width: STORED_WIDTH,
height: STORED_HEIGHT,
channels: 3,
background: { r: 0, g: 0, b: 0 },
},
})
.composite([
{ input: await tile('TL'), left: 0, top: 0 },
{ input: await tile('TR'), left: halfW, top: 0 },
{ input: await tile('BL'), left: 0, top: halfH },
{ input: await tile('BR'), left: halfW, top: halfH },
])
.jpeg({ quality: 100, chromaSubsampling: '4:4:4' })
.withMetadata({ orientation })
.toBuffer()
}
/** Which quadrant color is nearest to the pixel a few pixels inside the given output corner. */
async function cornerColor(file: string, where: 'TL' | 'BR'): Promise<Corner> {
const { data, info } = await sharp(fs.readFileSync(file))
.removeAlpha()
.raw()
.toBuffer({ resolveWithObject: true })
const inset = 3
const x = where === 'TL' ? inset : info.width - 1 - inset
const y = where === 'TL' ? inset : info.height - 1 - inset
const offset = (y * info.width + x) * info.channels
const pixel = [data[offset], data[offset + 1], data[offset + 2]]
let best: Corner = 'TL'
let bestDistance = Infinity
for (const corner of Object.keys(QUADRANT_COLORS) as Corner[]) {
const distance = QUADRANT_COLORS[corner].reduce(
(sum, channel, i) => sum + (channel - pixel[i]) ** 2,
0,
)
if (distance < bestDistance) {
best = corner
bestDistance = distance
}
}
return best
}
describe('EXIF orientation (real sharp)', () => {
let tempDir: string
beforeEach(() => {
tempDir = transcodeService.createTempDir('orientation-test-')
})
afterEach(() => {
transcodeService.removeDir(tempDir)
})
const expectedSize = (swapped: boolean) =>
swapped
? { width: STORED_HEIGHT, height: STORED_WIDTH }
: { width: STORED_WIDTH, height: STORED_HEIGHT }
it.each(ORIENTATIONS)(
'getImageInfo reports the displayed size for orientation $orientation ($name)',
async ({ orientation, swapped }) => {
const inputPath = path.join(tempDir, `in-${orientation}.jpg`)
fs.writeFileSync(inputPath, await makeJpeg(orientation))
const info = await transcodeService.getImageInfo(inputPath)
const expected = expectedSize(swapped)
expect(info.originalWidth).toBe(expected.width)
expect(info.originalHeight).toBe(expected.height)
},
)
it.each(ORIENTATIONS)(
'transcodeImage outputs an upright image for orientation $orientation ($name)',
async ({ orientation, swapped, topLeftIs, bottomRightIs }) => {
const inputPath = path.join(tempDir, `in-${orientation}.jpg`)
const outputPath = path.join(tempDir, `out-${orientation}.webp`)
fs.writeFileSync(inputPath, await makeJpeg(orientation))
await transcodeService.transcodeImage(inputPath, outputPath, 1000, 100)
const meta = await sharp(fs.readFileSync(outputPath)).metadata()
const expected = expectedSize(swapped)
expect(meta.width).toBe(expected.width)
expect(meta.height).toBe(expected.height)
// Direction, not just size: the stored corner that lands top-left and bottom-right.
expect(await cornerColor(outputPath, 'TL')).toBe(topLeftIs)
expect(await cornerColor(outputPath, 'BR')).toBe(bottomRightIs)
},
)
it('transcodeImage sizes a rotated preview from the displayed dimensions', async () => {
// Stored 64x48 with orientation 6 is displayed 48x64 (portrait): the short edge is the width.
const inputPath = path.join(tempDir, 'preview-in.jpg')
const outputPath = path.join(tempDir, 'preview-out.webp')
fs.writeFileSync(inputPath, await makeJpeg(6))
await transcodeService.transcodeImage(inputPath, outputPath, 24, 80, { isPreview: true })
const meta = await sharp(fs.readFileSync(outputPath)).metadata()
expect(meta.width).toBeLessThan(meta.height ?? 0)
})
describe('RAW inputs', () => {
const rawPreview = (previewPath: string, extra: Record<string, unknown>) => ({
previewPath,
cleanup: () => {},
width: STORED_WIDTH,
height: STORED_HEIGHT,
...extra,
})
it('never auto-orients dcraw_emu output that still carries an Orientation tag', async () => {
// The dcraw fallback reports orientation undefined (already upright) but flags it as applied.
const tiffLike = path.join(tempDir, 'dcraw.jpg')
const outputPath = path.join(tempDir, 'dcraw-out.webp')
fs.writeFileSync(tiffLike, await makeJpeg(6))
extractRawMock.mockResolvedValueOnce(
rawPreview(tiffLike, { orientation: undefined, orientationApplied: true }),
)
await transcodeService.transcodeImage(path.join(tempDir, 'photo.cr2'), outputPath, 1000, 100)
const meta = await sharp(fs.readFileSync(outputPath)).metadata()
// Stored landscape stays landscape and the stored corners stay put: no second rotation.
expect(meta.width).toBe(STORED_WIDTH)
expect(meta.height).toBe(STORED_HEIGHT)
expect(await cornerColor(outputPath, 'TL')).toBe('TL')
expect(await cornerColor(outputPath, 'BR')).toBe('BR')
})
it('still auto-orients an embedded preview that has no container orientation', async () => {
const embedded = path.join(tempDir, 'embedded.jpg')
const outputPath = path.join(tempDir, 'embedded-out.webp')
fs.writeFileSync(embedded, await makeJpeg(6))
extractRawMock.mockResolvedValueOnce(rawPreview(embedded, { orientation: undefined }))
await transcodeService.transcodeImage(path.join(tempDir, 'photo.cr2'), outputPath, 1000, 100)
const meta = await sharp(fs.readFileSync(outputPath)).metadata()
expect(meta.width).toBe(STORED_HEIGHT)
expect(meta.height).toBe(STORED_WIDTH)
})
})
it('overlayAnnotationsOnBuffer keeps the displayed orientation', async () => {
const annotations = [
{
type: 'box',
color: '#ffffff',
points: [
[0.1, 0.1],
[0.4, 0.4],
],
},
] as unknown as PrismaJson.AnnotationList
const annotated = await transcodeService.overlayAnnotationsOnBuffer(
await makeJpeg(6),
annotations,
)
const meta = await sharp(annotated).metadata()
expect(meta.width).toBe(STORED_HEIGHT)
expect(meta.height).toBe(STORED_WIDTH)
})
})
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,237 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import * as fs from 'fs'
import * as path from 'path'
import * as os from 'os'
import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { TurntableService } from './turntable'
describe('TurntableService', () => {
setupTestDbHooks()
const originalEnv = process.env
let tmpDir: string
let testFilePath: string
beforeEach(() => {
process.env = { ...originalEnv }
delete process.env.TURNTABLE_RENDERER_URL
delete process.env.TURNTABLE_RENDERER_BASIC_AUTH_USERNAME
delete process.env.TURNTABLE_RENDERER_BASIC_AUTH_PASSWORD
delete process.env.TURNTABLE_RENDERER_USERNAME
delete process.env.TURNTABLE_RENDERER_PASSWORD
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'turntable-test-'))
testFilePath = path.join(tmpDir, 'model.glb')
fs.writeFileSync(testFilePath, 'fake glb content')
})
afterEach(() => {
process.env = originalEnv
fs.rmSync(tmpDir, { recursive: true, force: true })
vi.restoreAllMocks()
})
describe('resolveConfig', () => {
it('returns isEnv: false when neither env nor team settings are present', async () => {
const service = new TurntableService()
const config = await service.resolveConfig()
expect(config.url).toBeUndefined()
expect(config.isEnv).toBe(false)
})
it('resolves env configuration with highest priority', async () => {
process.env.TURNTABLE_RENDERER_URL = 'http://localhost:3000/'
process.env.TURNTABLE_RENDERER_BASIC_AUTH_USERNAME = 'admin'
process.env.TURNTABLE_RENDERER_BASIC_AUTH_PASSWORD = 'secret'
const service = new TurntableService()
const config = await service.resolveConfig('any-team-id')
expect(config.url).toBe('http://localhost:3000')
expect(config.username).toBe('admin')
expect(config.password).toBe('secret')
expect(config.isEnv).toBe(true)
})
it('falls back to team DB settings when env is not set', async () => {
const team = await prisma.team.create({
data: {
name: 'Test Team 3D',
settings: {
turntable: {
url: 'http://custom-turntable:4000',
username: 'teamUser',
password: 'teamPassword',
},
},
},
})
const service = new TurntableService()
const config = await service.resolveConfig(team.id)
expect(config.url).toBe('http://custom-turntable:4000')
expect(config.username).toBe('teamUser')
expect(config.password).toBe('teamPassword')
expect(config.isEnv).toBe(false)
})
})
describe('isAvailable', () => {
it('returns false if URL is not configured', async () => {
const service = new TurntableService()
expect(await service.isAvailable()).toBe(false)
})
it('returns true when health check returns 200', async () => {
process.env.TURNTABLE_RENDERER_URL = 'http://turntable:3000'
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
} as Response)
const service = new TurntableService()
expect(await service.isAvailable()).toBe(true)
})
it('returns false when health check fails or throws', async () => {
process.env.TURNTABLE_RENDERER_URL = 'http://turntable:3000'
vi.spyOn(globalThis, 'fetch').mockRejectedValue(new Error('Connection refused'))
const service = new TurntableService()
expect(await service.isAvailable()).toBe(false)
})
})
describe('testConnection', () => {
it('returns error when url is empty', async () => {
const service = new TurntableService()
const result = await service.testConnection({})
expect(result.ok).toBe(false)
expect(result.error).toBe('URL is required')
})
it('returns version information upon successful connection', async () => {
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
json: async () => ({ version: '0.1.0', blender: '5.2.2' }),
} as Response)
const service = new TurntableService()
const result = await service.testConnection({ url: 'http://localhost:3000' })
expect(result.ok).toBe(true)
expect(result.version).toBe('0.1.0')
expect(result.blender).toBe('5.2.2')
})
})
describe('uploadFile', () => {
it('posts file buffer to /v1/files and returns file info', async () => {
process.env.TURNTABLE_RENDERER_URL = 'http://turntable:3000'
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 201,
json: async () => ({ id: 'f_test123', name: 'model.glb', size: 100 }),
} as Response)
const service = new TurntableService()
const res = await service.uploadFile(testFilePath, 'model.glb')
expect(res.id).toBe('f_test123')
expect(fetchSpy).toHaveBeenCalledWith(
'http://turntable:3000/v1/files',
expect.objectContaining({
method: 'POST',
}),
)
})
})
describe('startRender & getTaskStatus & downloadFile & deleteTask', () => {
beforeEach(() => {
process.env.TURNTABLE_RENDERER_URL = 'http://turntable:3000'
})
it('startRender calls /v1/render and returns sync response', async () => {
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
json: async () => ({
taskId: 't_test456',
status: 'queued',
poster: {
fileId: 'f_poster',
size: 200,
contentType: 'image/png',
width: 1080,
height: 1080,
},
}),
} as Response)
const service = new TurntableService()
const res = await service.startRender('f_input')
expect(res.taskId).toBe('t_test456')
expect(res.poster.fileId).toBe('f_poster')
})
it('getTaskStatus queries /v1/render/tasks/:id', async () => {
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
json: async () => ({
taskId: 't_test456',
status: 'completed',
video: {
fileId: 'f_video',
size: 1000,
contentType: 'video/mp4',
width: 1080,
height: 1080,
},
}),
} as Response)
const service = new TurntableService()
const res = await service.getTaskStatus('t_test456')
expect(res.status).toBe('completed')
expect(res.video?.fileId).toBe('f_video')
})
it('downloadFile fetches /v1/files/:id and writes to destination', async () => {
const destPath = path.join(tmpDir, 'downloaded.mp4')
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
arrayBuffer: async () => Buffer.from('video data').buffer,
} as Response)
const service = new TurntableService()
await service.downloadFile('f_video', destPath)
expect(fs.existsSync(destPath)).toBe(true)
expect(fs.readFileSync(destPath, 'utf8')).toBe('video data')
})
it('deleteTask calls DELETE /v1/render/tasks/:id and returns boolean', async () => {
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
status: 200,
} as Response)
const service = new TurntableService()
const deleted = await service.deleteTask('t_test456')
expect(deleted).toBe(true)
expect(fetchSpy).toHaveBeenCalledWith(
'http://turntable:3000/v1/render/tasks/t_test456',
expect.objectContaining({
method: 'DELETE',
}),
)
})
})
})
+364
View File
@@ -0,0 +1,364 @@
import * as fs from 'fs'
import type { TurntableSettingsResponse, UpdateTurntableSettingsRequest } from '@shumai/dtos'
import {
IntegrationDefinition,
resolveIntegrationConfig,
getIntegrationSettings,
updateIntegrationSettings,
resolveTestConnectionConfig,
getIntegrationBasicAuthHeader,
} from '@shumai/core/src/integrations/helper'
export const TURNTABLE_INTEGRATION_DEF: IntegrationDefinition<'turntable'> = {
name: 'Turntable',
settingsKey: 'turntable',
envKeys: {
url: ['TURNTABLE_RENDERER_URL'],
username: ['TURNTABLE_RENDERER_BASIC_AUTH_USERNAME', 'TURNTABLE_RENDERER_USERNAME'],
password: ['TURNTABLE_RENDERER_BASIC_AUTH_PASSWORD', 'TURNTABLE_RENDERER_PASSWORD'],
},
}
export interface TurntableConfig {
url?: string
username?: string
password?: string
isEnv: boolean
}
export interface TurntablePosterOutput {
fileId: string
size: number
contentType: string
width: number
height: number
}
export interface TurntableRenderSyncResponse {
taskId: string
status: 'queued' | 'rendering'
positionInQueue?: number
metadata?: Record<string, unknown>
poster: TurntablePosterOutput
}
export interface TurntableVideoOutput {
fileId: string
size: number
contentType: string
width: number
height: number
}
export interface TurntableRenderStats {
width: number
height: number
frames: number
fps: number
durationSeconds: number
degreesPerFrame: number
startAngle: number
direction: string
includeEndFrame: boolean
engine: string
elapsedMs: number
}
export interface TurntableTaskResponse {
taskId: string
status: 'queued' | 'rendering' | 'completed' | 'failed'
positionInQueue?: number
createdAt: string
startedAt?: string
completedAt?: string
failedAt?: string
render?: TurntableRenderStats
video?: TurntableVideoOutput
error?: {
code: string
message: string
details?: Record<string, unknown>
}
}
export class TurntableService {
async resolveConfig(teamId?: string): Promise<TurntableConfig> {
return resolveIntegrationConfig(TURNTABLE_INTEGRATION_DEF, teamId)
}
private getAuthHeader(config: TurntableConfig): string | undefined {
return getIntegrationBasicAuthHeader(config)
}
async isAvailable(teamId?: string): Promise<boolean> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
return false
}
try {
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${config.url}/health`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(3000),
})
return response.ok
} catch {
return false
}
}
async getSettings(teamId: string): Promise<TurntableSettingsResponse> {
return getIntegrationSettings(TURNTABLE_INTEGRATION_DEF, teamId)
}
async updateSettings(
teamId: string,
req: UpdateTurntableSettingsRequest,
): Promise<TurntableSettingsResponse> {
return updateIntegrationSettings(TURNTABLE_INTEGRATION_DEF, teamId, req)
}
async testConnection(
config?: {
url?: string
username?: string
password?: string
},
teamId?: string,
): Promise<{ ok: boolean; version?: string; blender?: string; error?: string }> {
const target = await resolveTestConnectionConfig(TURNTABLE_INTEGRATION_DEF, config, teamId)
if (!target.resolvedUrl) {
return { ok: false, error: 'URL is required' }
}
const cleanUrl = target.resolvedUrl.replace(/\/+$/, '')
try {
const headers: Record<string, string> = {}
const authHeader = getIntegrationBasicAuthHeader({
username: target.resolvedUsername,
password: target.resolvedPassword,
})
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${cleanUrl}/version`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(5000),
})
if (!response.ok) {
const errText = await response.text().catch(() => '')
return {
ok: false,
error: `Server returned status ${response.status}: ${errText || response.statusText}`,
}
}
const body = (await response.json()) as { version?: string; blender?: string }
return {
ok: true,
version: body.version,
blender: body.blender,
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
return { ok: false, error: message }
}
}
async uploadFile(
filePath: string,
filename: string,
teamId?: string,
): Promise<{ id: string; name: string; size: number }> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
throw new Error('Turntable renderer URL is not configured.')
}
const headers: Record<string, string> = {
'content-type': 'application/octet-stream',
'x-filename': encodeURIComponent(filename),
}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${config.url}/v1/files`, {
method: 'POST',
headers,
body: Bun.file(filePath),
signal: AbortSignal.timeout(900000),
})
if (!response.ok) {
const errorText = await response.text().catch(() => '')
throw new Error(
`Turntable upload failed with status ${response.status}: ${errorText || response.statusText}`,
)
}
return (await response.json()) as { id: string; name: string; size: number }
}
async startRender(
fileId: string,
options: Record<string, unknown> = {},
teamId?: string,
): Promise<TurntableRenderSyncResponse> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
throw new Error('Turntable renderer URL is not configured.')
}
const headers: Record<string, string> = {
'content-type': 'application/json',
}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${config.url}/v1/render`, {
method: 'POST',
headers,
body: JSON.stringify({
input: { fileId },
options,
}),
signal: AbortSignal.timeout(60000),
})
if (!response.ok) {
const errorText = await response.text().catch(() => '')
throw new Error(
`Turntable render request failed with status ${response.status}: ${errorText || response.statusText}`,
)
}
return (await response.json()) as TurntableRenderSyncResponse
}
async getTaskStatus(taskId: string, teamId?: string): Promise<TurntableTaskResponse> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
throw new Error('Turntable renderer URL is not configured.')
}
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${config.url}/v1/render/tasks/${taskId}`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(10000),
})
if (!response.ok) {
const errorText = await response.text().catch(() => '')
throw new Error(
`Failed to fetch task status (${response.status}): ${errorText || response.statusText}`,
)
}
return (await response.json()) as TurntableTaskResponse
}
async downloadFile(fileId: string, targetPath?: string, teamId?: string): Promise<Buffer> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
throw new Error('Turntable renderer URL is not configured.')
}
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
const response = await fetch(`${config.url}/v1/files/${fileId}`, {
method: 'GET',
headers,
signal: AbortSignal.timeout(120000),
})
if (!response.ok) {
const errorText = await response.text().catch(() => '')
throw new Error(
`Failed to download file ${fileId} (${response.status}): ${errorText || response.statusText}`,
)
}
const arrayBuffer = await response.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
if (targetPath) {
fs.writeFileSync(targetPath, buffer)
}
return buffer
}
async deleteTask(taskId: string, teamId?: string): Promise<boolean> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
return false
}
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
try {
const response = await fetch(`${config.url}/v1/render/tasks/${taskId}`, {
method: 'DELETE',
headers,
signal: AbortSignal.timeout(10000),
})
return response.ok
} catch {
return false
}
}
async deleteFile(fileId: string, teamId?: string): Promise<boolean> {
const config = await this.resolveConfig(teamId)
if (!config.url) {
return false
}
const headers: Record<string, string> = {}
const authHeader = this.getAuthHeader(config)
if (authHeader) {
headers['Authorization'] = authHeader
}
try {
const response = await fetch(`${config.url}/v1/files/${fileId}`, {
method: 'DELETE',
headers,
signal: AbortSignal.timeout(10000),
})
return response.ok
} catch {
return false
}
}
}
export const turntableService = new TurntableService()
+165 -3
View File
@@ -3,6 +3,7 @@ import { prisma } from '@shumai/db'
import { setupTestDbHooks } from '@shumai/db/test'
import { uploadService } from './upload'
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
import { turntableService } from '@shumai/core/src/turntable/turntable'
import { s3Service } from '@shumai/core/src/s3/s3'
import { AssetStatus, AssetType, TaskStatus, WorkflowTaskType } from '@shumai/db'
@@ -198,17 +199,19 @@ describe('UploadService', () => {
threads: 0,
sprite: true,
poster: true,
hlsEnabled: false,
},
})
})
it('should pass custom transcode.threads from team settings to transcode task', async () => {
it('should pass custom transcode.threads and videoResolutions from team settings to transcode task', async () => {
await prisma.team.update({
where: { id: teamId },
data: {
settings: {
transcode: {
videoStrategy: 'all',
videoStrategy: 'multi',
videoResolutions: ['720p', '1080p'],
hardwareAcceleration: 'auto',
threads: 12,
},
@@ -244,11 +247,13 @@ describe('UploadService', () => {
expect(workflowTask?.payload).toEqual({
projectId: projectId,
transcode: {
videoStrategy: 'all',
videoStrategy: 'multi',
videoResolutions: ['720p', '1080p'],
hardwareAcceleration: 'auto',
threads: 12,
sprite: true,
poster: true,
hlsEnabled: false,
},
})
})
@@ -446,6 +451,163 @@ describe('UploadService', () => {
expect(workflowTask).toBeNull()
})
it('should create transcode_pdf for office documents when Gotenberg is configured in team settings without global env', async () => {
vi.restoreAllMocks()
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const url = String(input)
if (url.includes('/health')) {
return new Response(JSON.stringify({ status: 'up' }), { status: 200 })
}
return new Response('Not Found', { status: 404 })
})
const originalEnv = process.env.GOTENBERG_URL
delete process.env.GOTENBERG_URL
try {
await prisma.team.update({
where: { id: teamId },
data: {
settings: {
gotenberg: {
url: 'http://gotenberg.local:3000',
},
},
},
})
const task = await prisma.task.create({
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
})
const asset = await prisma.asset.create({
data: {
name: 'report.docx',
type: AssetType.file,
project: { connect: { id: projectId } },
parent: { connect: { id: parentId } },
status: AssetStatus.uploading,
storageKey: {
connectOrCreate: {
where: { key: 'test-key-doc-team-settings' },
create: { key: 'test-key-doc-team-settings' },
},
},
mediaType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
},
})
await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id })
const workflowTask = await prisma.workflowTask.findFirst({
where: { assetId: asset.id, type: WorkflowTaskType.transcode_pdf },
})
expect(workflowTask).not.toBeNull()
expect(workflowTask?.status).toBe(TaskStatus.pending)
// Test HTML document as well
const htmlTask = await prisma.task.create({
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
})
const htmlAsset = await prisma.asset.create({
data: {
name: 'index.html',
type: AssetType.file,
project: { connect: { id: projectId } },
parent: { connect: { id: parentId } },
status: AssetStatus.uploading,
storageKey: {
connectOrCreate: {
where: { key: 'test-key-html-team-settings' },
create: { key: 'test-key-html-team-settings' },
},
},
mediaType: 'text/html',
},
})
await uploadService.confirmFileUpload(userId, htmlTask.id, { fileId: htmlAsset.id })
const htmlWorkflowTask = await prisma.workflowTask.findFirst({
where: { assetId: htmlAsset.id, type: WorkflowTaskType.transcode_pdf },
})
expect(htmlWorkflowTask).not.toBeNull()
expect(htmlWorkflowTask?.status).toBe(TaskStatus.pending)
} finally {
if (originalEnv !== undefined) {
process.env.GOTENBERG_URL = originalEnv
}
}
})
it('should confirm file upload and create transcode_3d for 3D model when turntable is available', async () => {
vi.spyOn(turntableService, 'isAvailable').mockResolvedValue(true)
const task = await prisma.task.create({
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
})
const asset = await prisma.asset.create({
data: {
name: 'robot.glb',
type: AssetType.file,
project: { connect: { id: projectId } },
parent: { connect: { id: parentId } },
status: AssetStatus.uploading,
storageKey: {
connectOrCreate: {
where: { key: 'test-key-3d-1' },
create: { key: 'test-key-3d-1' },
},
},
mediaType: 'model/gltf-binary',
},
})
await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id })
const workflowTask = await prisma.workflowTask.findFirst({
where: { assetId: asset.id, type: WorkflowTaskType.transcode_3d },
})
expect(workflowTask).toBeDefined()
expect(workflowTask?.payload).toEqual({
projectId: projectId,
transcode: {
sprite: true,
poster: true,
},
})
})
it('should mark asset processed without creating transcode_3d for 3D model when turntable is unavailable', async () => {
vi.spyOn(turntableService, 'isAvailable').mockResolvedValue(false)
const task = await prisma.task.create({
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
})
const asset = await prisma.asset.create({
data: {
name: 'robot.glb',
type: AssetType.file,
project: { connect: { id: projectId } },
parent: { connect: { id: parentId } },
status: AssetStatus.uploading,
storageKey: {
connectOrCreate: {
where: { key: 'test-key-3d-2' },
create: { key: 'test-key-3d-2' },
},
},
mediaType: 'model/gltf-binary',
},
})
await uploadService.confirmFileUpload(userId, task.id, { fileId: asset.id })
const updatedAsset = await prisma.asset.findUnique({ where: { id: asset.id } })
expect(updatedAsset?.status).toBe(AssetStatus.processed)
const workflowTask = await prisma.workflowTask.findFirst({
where: { assetId: asset.id, type: WorkflowTaskType.transcode_3d },
})
expect(workflowTask).toBeNull()
})
it('should confirm file upload and resolve empty mediaType using Bun resolver for audio', async () => {
const task = await prisma.task.create({
data: { creatorId: userId, total: 1, uploaded: 0, type: 'upload' },
+24 -2
View File
@@ -14,10 +14,11 @@ import {
S3SignResponse,
TaskInfo,
} from '@shumai/dtos'
import { ImageTranscoder, PdfTranscoder, VideoTranscoder } from '@shumai/transcode'
import { ImageTranscoder, ModelTranscoder, PdfTranscoder, VideoTranscoder } from '@shumai/transcode'
import { generateKeyBetween } from 'jittered-fractional-indexing'
import { ulid } from 'ulid'
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
import { turntableService } from '@shumai/core/src/turntable/turntable'
import { sanitizeFilename } from '@shumai/core/src/utils/filename'
import { getProxyType, isHtmlDocument, isOfficeDocument } from '@shumai/core/src/utils/mime'
import { logger } from '@shumai/core/src/logger'
@@ -323,6 +324,7 @@ export class UploadService {
const isImage = proxyType === 'image'
const isAudio = proxyType === 'audio'
const isPdf = proxyType === 'pdf'
const is3D = proxyType === '3d'
if (!proxyType) {
await tx.asset.update({
@@ -334,12 +336,17 @@ export class UploadService {
const threads = settings?.transcode?.threads ?? 0
if (isVideo) {
const strategy = settings?.transcode?.videoStrategy || 'best_match'
const videoResolutions = settings?.transcode?.videoResolutions
const hardwareAcceleration = settings?.transcode?.hardwareAcceleration || 'off'
const hlsEnabled = settings?.transcode?.hlsEnabled ?? false
const hlsResolutions = settings?.transcode?.hlsResolutions
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await new VideoTranscoder(tx as any, asset.id, team.id, projectId)
.setStrategy(strategy)
.setVideoResolutions(videoResolutions)
.setHardwareAcceleration(hardwareAcceleration)
.setThreads(threads)
.setHls(hlsEnabled, hlsResolutions)
.withSprite()
.withPoster()
.submit()
@@ -356,7 +363,7 @@ export class UploadService {
const isHtml = isHtmlDocument(asset.mediaType, asset.name)
if (isOffice || isHtml) {
const gotenbergAvailable = await gotenbergService.isAvailable()
const gotenbergAvailable = await gotenbergService.isAvailable(team.id)
if (!gotenbergAvailable) {
await tx.asset.update({
where: { id: asset.id },
@@ -371,6 +378,21 @@ export class UploadService {
.withSprite()
.withPoster()
.submit()
} else if (is3D) {
const turntableAvailable = await turntableService.isAvailable(team.id)
if (!turntableAvailable) {
await tx.asset.update({
where: { id: asset.id },
data: { status: AssetStatus.processed },
})
return
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
await new ModelTranscoder(tx as any, asset.id, team.id, projectId)
.withSprite()
.withPoster()
.submit()
}
}
}
+36 -3
View File
@@ -67,15 +67,26 @@ describe('handleDaemonCommands', () => {
}
})
it('runs the runFn on normal startup', async () => {
it('runs the runFn on normal foreground startup without creating a PID file', async () => {
process.argv = ['node', 'script.js']
const runFn = vi.fn().mockResolvedValue(undefined)
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
expect(existsSync(pidFile)).toBe(true)
expect(readFileSync(pidFile, 'utf8').trim()).toBe(process.pid.toString())
expect(existsSync(pidFile)).toBe(false)
})
it('runs foreground startup even if a stale or conflicting PID file exists', async () => {
process.argv = ['node', 'script.js']
const runFn = vi.fn().mockResolvedValue(undefined)
mkdirSync(join(mockTempDir, '.shumai', 'pids'), { recursive: true })
writeFileSync(pidFile, '12345')
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
})
it('stops the process if stop command is passed', async () => {
@@ -122,4 +133,26 @@ describe('handleDaemonCommands', () => {
expect(spawn).toHaveBeenCalled()
expect(mockExit).toHaveBeenCalledWith(0)
})
it('runs and manages PID file when running as a daemonized child', async () => {
process.argv = ['node', 'script.js']
const originalEnv = process.env.SHUMAI_DAEMONIZED
process.env.SHUMAI_DAEMONIZED = 'true'
try {
const runFn = vi.fn().mockResolvedValue(undefined)
await handleDaemonCommands(appName, runFn)
expect(runFn).toHaveBeenCalled()
expect(existsSync(pidFile)).toBe(true)
expect(readFileSync(pidFile, 'utf8').trim()).toBe(process.pid.toString())
} finally {
if (originalEnv !== undefined) {
process.env.SHUMAI_DAEMONIZED = originalEnv
} else {
delete process.env.SHUMAI_DAEMONIZED
}
}
})
})
+19 -29
View File
@@ -17,6 +17,9 @@ const PID_DIR = join(SHUMAI_DIR, 'pids')
const LOG_DIR = join(SHUMAI_DIR, 'logs')
function isProcessRunning(pid: number): boolean {
if (pid <= 1) {
return false
}
try {
process.kill(pid, 0)
return true
@@ -35,7 +38,7 @@ async function stopProcess(appName: string, pidFile: string): Promise<boolean> {
}
const pid = parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
if (isNaN(pid)) {
if (isNaN(pid) || pid <= 1) {
console.log(`Invalid PID found in ${pidFile}. Cleaning up file.`)
try {
unlinkSync(pidFile)
@@ -180,18 +183,25 @@ export async function handleDaemonCommands(
appName: string,
runFn: () => Promise<void>,
): Promise<void> {
const pidFile = join(PID_DIR, `${appName}.pid`)
const logFile = join(LOG_DIR, `${appName}.log`)
// Ensure directories exist
mkdirSync(PID_DIR, { recursive: true })
mkdirSync(LOG_DIR, { recursive: true })
const args = process.argv.slice(2)
const isStop = args.includes('stop')
const isRestart = args.includes('restart')
const isLogs = args.includes('logs')
const isDaemon = args.includes('-d') && process.env.SHUMAI_DAEMONIZED !== 'true'
const isDaemonizedChild = process.env.SHUMAI_DAEMONIZED === 'true'
// Normal foreground startup: do not create, check, or track PID files
if (!isStop && !isRestart && !isLogs && !isDaemon && !isDaemonizedChild) {
await runFn()
return
}
const pidFile = join(PID_DIR, `${appName}.pid`)
const logFile = join(LOG_DIR, `${appName}.log`)
// Ensure directories exist for daemon commands
mkdirSync(PID_DIR, { recursive: true })
mkdirSync(LOG_DIR, { recursive: true })
if (isStop) {
await stopProcess(appName, pidFile)
@@ -216,27 +226,7 @@ export async function handleDaemonCommands(
process.exit(0)
}
// Normal Startup logic: check if already running
if (existsSync(pidFile)) {
const pid = parseInt(readFileSync(pidFile, 'utf8').trim(), 10)
if (!isNaN(pid) && pid !== process.pid) {
if (isProcessRunning(pid)) {
console.error(
`${appName} is already running (PID: ${pid}). Use '${appName} stop' or '${appName} restart'.`,
)
process.exit(1)
} else {
// Process is dead, clean up PID file
try {
unlinkSync(pidFile)
} catch {
// Ignore
}
}
}
}
// Write the PID file
// Daemonized child startup (SHUMAI_DAEMONIZED === 'true')
writeFileSync(pidFile, process.pid.toString(), 'utf8')
const cleanPidFile = () => {
+24
View File
@@ -15,6 +15,30 @@ const EXTENSION_MIME_TYPES: Record<string, string> = {
'.txt': 'text/plain',
'.md': 'text/markdown',
'.markdown': 'text/markdown',
// Camera RAW formats
'.3fr': 'image/x-hasselblad-3fr',
'.arw': 'image/x-sony-arw',
'.cr2': 'image/x-canon-cr2',
'.cr3': 'image/x-canon-cr3',
'.crw': 'image/x-canon-crw',
'.dcr': 'image/x-kodak-dcr',
'.dng': 'image/x-adobe-dng',
'.erf': 'image/x-epson-erf',
'.fff': 'image/x-hasselblad-fff',
'.iiq': 'image/x-phaseone-iiq',
'.kdc': 'image/x-kodak-kdc',
'.nef': 'image/x-nikon-nef',
'.nrw': 'image/x-nikon-nrw',
'.orf': 'image/x-olympus-orf',
'.pef': 'image/x-pentax-pef',
'.raf': 'image/x-fuji-raf',
'.raw': 'image/x-panasonic-raw',
'.rw2': 'image/x-panasonic-rw2',
'.rwl': 'image/x-leica-rwl',
'.sr2': 'image/x-sony-sr2',
'.srf': 'image/x-sony-srf',
'.srw': 'image/x-samsung-srw',
'.x3f': 'image/x-sigma-x3f',
}
/**
+32
View File
@@ -92,6 +92,20 @@ describe('getProxyType', () => {
expect(getProxyType(null, 'design.psd')).toBe('image')
})
it('should detect image proxyType for RAW camera files', () => {
// RAW files typically upload with application/octet-stream or null mediaType
expect(getProxyType('application/octet-stream', 'photo.cr2')).toBe('image')
expect(getProxyType('application/octet-stream', 'photo.arw')).toBe('image')
expect(getProxyType(null, 'photo.dng')).toBe('image')
expect(getProxyType(null, 'photo.nef')).toBe('image')
expect(getProxyType(null, 'photo.raf')).toBe('image')
expect(getProxyType(null, 'photo.cr3')).toBe('image')
expect(getProxyType(null, 'photo.rw2')).toBe('image')
// Case-insensitive
expect(getProxyType(null, 'PHOTO.ARW')).toBe('image')
expect(getProxyType(null, 'Photo.DNG')).toBe('image')
})
it('should detect video proxyType', () => {
expect(getProxyType('video/mp4', 'clip.mp4')).toBe('video')
})
@@ -112,8 +126,26 @@ describe('getProxyType', () => {
expect(getProxyType(null, 'slides.pptx')).toBe('pdf')
})
it('should detect 3d proxyType for supported 3D models', () => {
expect(getProxyType('model/gltf-binary', 'model.glb')).toBe('3d')
expect(getProxyType(null, 'model.glb')).toBe('3d')
expect(getProxyType(null, 'character.fbx')).toBe('3d')
expect(getProxyType('model/obj', 'mesh.obj')).toBe('3d')
expect(getProxyType(null, 'mesh.obj')).toBe('3d')
expect(getProxyType('model/stl', 'part.stl')).toBe('3d')
expect(getProxyType(null, 'part.stl')).toBe('3d')
expect(getProxyType(null, 'scene.usd')).toBe('3d')
expect(getProxyType(null, 'scene.usda')).toBe('3d')
expect(getProxyType(null, 'scene.usdc')).toBe('3d')
expect(getProxyType('model/vnd.usdz+zip', 'scene.usdz')).toBe('3d')
expect(getProxyType('model/vnd.collada+xml', 'model.dae')).toBe('3d')
expect(getProxyType(null, 'MODEL.GLB')).toBe('3d')
})
it('should return null for unsupported files', () => {
expect(getProxyType('application/zip', 'archive.zip')).toBeNull()
expect(getProxyType(null, 'unknown.bin')).toBeNull()
expect(getProxyType('model/gltf+json', 'model.gltf')).toBeNull()
expect(getProxyType(null, 'model.gltf')).toBeNull()
})
})
+50 -2
View File
@@ -1,4 +1,43 @@
export type ProxyType = 'image' | 'video' | 'audio' | 'pdf'
import { isRawImage } from './raw'
export type ProxyType = 'image' | 'video' | 'audio' | 'pdf' | '3d'
export function is3dModel(mediaType?: string | null, filename?: string | null): boolean {
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
if (lowerMediaType === 'model/gltf+json' || lowerFilename.endsWith('.gltf')) {
return false
}
const modelExtensions = [
'.glb',
'.usd',
'.usda',
'.usdc',
'.usdz',
'.fbx',
'.obj',
'.stl',
'.dae',
]
if (modelExtensions.some((ext) => lowerFilename.endsWith(ext))) {
return true
}
if (
lowerMediaType.startsWith('model/') ||
lowerMediaType === 'model/gltf-binary' ||
lowerMediaType === 'model/obj' ||
lowerMediaType === 'model/stl' ||
lowerMediaType === 'model/vnd.usdz+zip' ||
lowerMediaType === 'model/vnd.collada+xml'
) {
return true
}
return false
}
export function isOfficeDocument(mediaType?: string | null, filename?: string | null): boolean {
const lowerMediaType = mediaType?.toLowerCase() || ''
@@ -73,7 +112,12 @@ export function getProxyType(
const lowerMediaType = mediaType?.toLowerCase() || ''
const lowerFilename = filename?.toLowerCase() || ''
if (lowerMediaType.startsWith('image/') || lowerFilename.endsWith('.psd')) return 'image'
if (
lowerMediaType.startsWith('image/') ||
lowerFilename.endsWith('.psd') ||
isRawImage(lowerFilename)
)
return 'image'
if (lowerMediaType.startsWith('video/')) return 'video'
if (lowerMediaType.startsWith('audio/')) return 'audio'
@@ -90,6 +134,10 @@ export function getProxyType(
return 'pdf'
}
if (is3dModel(mediaType, filename)) {
return '3d'
}
return null
}
+90
View File
@@ -0,0 +1,90 @@
import { describe, expect, it } from 'vitest'
import {
calculateTurntableFrameCenterTime,
degreeToSecond,
degreeToTurntableFrame,
isValidTurntableDegree,
secondToDegree,
secondToTurntableFrame,
TOTAL_TURNTABLE_FRAMES,
TURNTABLE_FPS,
} from './model3d'
describe('model3d utils', () => {
describe('secondToTurntableFrame', () => {
it('converts playback seconds to frame indices (0..23)', () => {
expect(secondToTurntableFrame(0)).toBe(0)
expect(secondToTurntableFrame(0.167)).toBe(1)
expect(secondToTurntableFrame(0.5)).toBe(3)
expect(secondToTurntableFrame(2.0)).toBe(12)
expect(secondToTurntableFrame(3.9)).toBe(23)
})
it('clamps out-of-range seconds', () => {
expect(secondToTurntableFrame(-1)).toBe(0)
expect(secondToTurntableFrame(10)).toBe(TOTAL_TURNTABLE_FRAMES - 1)
})
})
describe('secondToDegree', () => {
it('converts seconds to turntable degrees (0, 15, ..., 345)', () => {
expect(secondToDegree(0)).toBe(0)
expect(secondToDegree(1 / TURNTABLE_FPS)).toBe(15)
expect(secondToDegree(0.5)).toBe(45)
expect(secondToDegree(2.0)).toBe(180)
expect(secondToDegree(3.9)).toBe(345)
})
})
describe('degreeToTurntableFrame', () => {
it('converts discrete degrees to frame indices', () => {
expect(degreeToTurntableFrame(0)).toBe(0)
expect(degreeToTurntableFrame(15)).toBe(1)
expect(degreeToTurntableFrame(45)).toBe(3)
expect(degreeToTurntableFrame(90)).toBe(6)
expect(degreeToTurntableFrame(180)).toBe(12)
expect(degreeToTurntableFrame(345)).toBe(23)
})
it('normalizes degrees outside [0, 360)', () => {
expect(degreeToTurntableFrame(360)).toBe(0)
expect(degreeToTurntableFrame(-15)).toBe(23)
expect(degreeToTurntableFrame(720)).toBe(0)
})
})
describe('calculateTurntableFrameCenterTime and degreeToSecond', () => {
it('calculates frame center times within bounds', () => {
const centerTime0 = calculateTurntableFrameCenterTime(0)
expect(centerTime0).toBeCloseTo(0.5 / TURNTABLE_FPS)
const centerTime23 = calculateTurntableFrameCenterTime(23)
expect(centerTime23).toBeLessThan(TOTAL_TURNTABLE_FRAMES / TURNTABLE_FPS)
expect(centerTime23).toBeGreaterThan(23 / TURNTABLE_FPS)
expect(degreeToSecond(0)).toBeCloseTo(centerTime0)
expect(degreeToSecond(45)).toBeCloseTo((3 + 0.5) / TURNTABLE_FPS)
expect(degreeToSecond(345)).toBeCloseTo(centerTime23)
})
})
describe('isValidTurntableDegree', () => {
it('returns true for integer multiples of 15 from 0 to 345', () => {
for (let deg = 0; deg < 360; deg += 15) {
expect(isValidTurntableDegree(deg)).toBe(true)
}
})
it('returns false for non-multiples of 15', () => {
expect(isValidTurntableDegree(10)).toBe(false)
expect(isValidTurntableDegree(44)).toBe(false)
expect(isValidTurntableDegree(45.5)).toBe(false)
})
it('returns false for out of range or negative degrees', () => {
expect(isValidTurntableDegree(-15)).toBe(false)
expect(isValidTurntableDegree(360)).toBe(false)
expect(isValidTurntableDegree(720)).toBe(false)
})
})
})
+58
View File
@@ -0,0 +1,58 @@
export const TOTAL_TURNTABLE_FRAMES = 24
export const TURNTABLE_FPS = 6
export const TURNTABLE_FRAME_DURATION = 1 / TURNTABLE_FPS
/**
* Converts a playback second into a turntable frame index (0..23), clamped.
*/
export function secondToTurntableFrame(second: number): number {
return Math.min(
Math.max(0, Math.floor(second * TURNTABLE_FPS + 1e-4)),
TOTAL_TURNTABLE_FRAMES - 1,
)
}
/**
* Converts a turntable playback second to turntable degree (0, 15, 30, ..., 345).
*/
export function secondToDegree(second: number): number {
const frameIndex = secondToTurntableFrame(second)
return (frameIndex * 15) % 360
}
/**
* Calculates the presentation time within a turntable frame.
* Seeking near frame center avoids PTS boundary inaccuracies in video decoders.
*/
export function calculateTurntableFrameCenterTime(frameIndex: number): number {
const normalizedFrame =
((frameIndex % TOTAL_TURNTABLE_FRAMES) + TOTAL_TURNTABLE_FRAMES) % TOTAL_TURNTABLE_FRAMES
if (normalizedFrame === TOTAL_TURNTABLE_FRAMES - 1) {
return normalizedFrame * TURNTABLE_FRAME_DURATION + TURNTABLE_FRAME_DURATION * 0.25
}
return (normalizedFrame + 0.5) * TURNTABLE_FRAME_DURATION
}
/**
* Converts a rotation degree (0..345) to a turntable frame index (0..23).
*/
export function degreeToTurntableFrame(degree: number): number {
const normalizedDegree = ((Math.round(degree) % 360) + 360) % 360
return Math.round(normalizedDegree / 15) % TOTAL_TURNTABLE_FRAMES
}
/**
* Converts a rotation degree into a turntable video playback second (center time of that frame).
*/
export function degreeToSecond(degree: number): number {
const frameIndex = degreeToTurntableFrame(degree)
return calculateTurntableFrameCenterTime(frameIndex)
}
/**
* Validates whether a degree is a valid discrete turntable angle:
* integer multiple of 15 between 0 and 345 inclusive (0, 15, 30, ..., 345).
*/
export function isValidTurntableDegree(degree: number): boolean {
return Number.isInteger(degree) && degree >= 0 && degree <= 345 && degree % 15 === 0
}
+68
View File
@@ -0,0 +1,68 @@
import { describe, it, expect } from 'vitest'
import { isRawImage } from './raw'
describe('isRawImage', () => {
it('recognizes common RAW extensions (lowercase)', () => {
expect(isRawImage('photo.cr2')).toBe(true)
expect(isRawImage('photo.arw')).toBe(true)
expect(isRawImage('photo.dng')).toBe(true)
expect(isRawImage('photo.nef')).toBe(true)
expect(isRawImage('photo.raf')).toBe(true)
expect(isRawImage('photo.rw2')).toBe(true)
expect(isRawImage('photo.orf')).toBe(true)
expect(isRawImage('photo.pef')).toBe(true)
expect(isRawImage('photo.cr3')).toBe(true)
expect(isRawImage('photo.x3f')).toBe(true)
expect(isRawImage('photo.raw')).toBe(true)
expect(isRawImage('photo.3fr')).toBe(true)
expect(isRawImage('photo.iiq')).toBe(true)
expect(isRawImage('photo.kdc')).toBe(true)
expect(isRawImage('photo.dcr')).toBe(true)
expect(isRawImage('photo.erf')).toBe(true)
expect(isRawImage('photo.fff')).toBe(true)
expect(isRawImage('photo.crw')).toBe(true)
expect(isRawImage('photo.nrw')).toBe(true)
expect(isRawImage('photo.rwl')).toBe(true)
expect(isRawImage('photo.sr2')).toBe(true)
expect(isRawImage('photo.srf')).toBe(true)
expect(isRawImage('photo.srw')).toBe(true)
})
it('recognizes RAW extensions case-insensitively', () => {
expect(isRawImage('photo.CR2')).toBe(true)
expect(isRawImage('IMG_1234.ARW')).toBe(true)
expect(isRawImage('test.DNG')).toBe(true)
expect(isRawImage('photo.Nef')).toBe(true)
})
it('rejects non-RAW image files', () => {
expect(isRawImage('photo.jpg')).toBe(false)
expect(isRawImage('photo.png')).toBe(false)
expect(isRawImage('photo.webp')).toBe(false)
expect(isRawImage('photo.gif')).toBe(false)
expect(isRawImage('photo.svg')).toBe(false)
})
it('rejects non-image files', () => {
expect(isRawImage('design.psd')).toBe(false)
expect(isRawImage('video.mp4')).toBe(false)
expect(isRawImage('doc.pdf')).toBe(false)
expect(isRawImage('readme.txt')).toBe(false)
})
it('rejects files without extensions', () => {
expect(isRawImage('photo')).toBe(false)
expect(isRawImage('rawfile')).toBe(false)
})
it('handles filenames with multiple dots', () => {
expect(isRawImage('my.photo.cr2')).toBe(true)
expect(isRawImage('backup.2024.dng')).toBe(true)
expect(isRawImage('my.photo.jpg')).toBe(false)
})
it('handles paths with directories', () => {
expect(isRawImage('/home/user/photos/photo.cr2')).toBe(true)
expect(isRawImage('C:\\Users\\photos\\photo.arw')).toBe(true)
})
})
+37
View File
@@ -0,0 +1,37 @@
/**
* Centralized set of recognized camera RAW file extensions.
* Used only for routing files into the ExifTool extraction path.
*/
const RAW_EXTENSIONS: ReadonlySet<string> = new Set([
'.3fr',
'.arw',
'.cr2',
'.cr3',
'.crw',
'.dcr',
'.dng',
'.erf',
'.fff',
'.iiq',
'.kdc',
'.nef',
'.nrw',
'.orf',
'.pef',
'.raf',
'.raw',
'.rw2',
'.rwl',
'.sr2',
'.srf',
'.srw',
'.x3f',
])
/** Check whether a filename has a recognized camera RAW extension. */
export function isRawImage(filename: string): boolean {
const dotIndex = filename.lastIndexOf('.')
if (dotIndex === -1) return false
const ext = filename.slice(dotIndex).toLowerCase()
return RAW_EXTENSIONS.has(ext)
}
@@ -258,6 +258,57 @@ describe('WatermarkService', () => {
expect(mediaIds).toContain(mediaFile.id)
})
it('should include 3D assets with turntable video in getMediaAssetIdsInShareLink', async () => {
const user = await prisma.user.create({
data: { name: '3D User', email: '3d-wm@example.com' },
})
const team = await teamService.createTeam(user, { name: '3D Team' })
const projectFolder = await prisma.asset.create({
data: { name: 'root', type: 'root', status: 'processed' },
})
const project = await prisma.project.create({
data: { name: '3D Project', teamId: team.id, rootFolderId: projectFolder.id },
})
const shareLink = await shareService.createShareLink(project.id, { name: '3D Share' }, user.id)
const modelAsset = await prisma.asset.create({
data: {
name: 'robot.glb',
type: 'file',
mediaType: 'model/gltf-binary',
status: 'processed',
projectId: project.id,
media: {
duration: 4,
filesize: 100,
frames: 24,
proxyType: '3d',
videoTranscodes: [
{ key: 'files/asset-3d/turntable.mp4', width: 1080, height: 1080, resolution: '1080p' },
],
finishedAt: new Date().toISOString(),
original: { key: 'files/asset-3d/robot.glb', filesizeInBytes: 100, codec: '' },
} as PrismaJson.MediaInfo,
},
})
await prisma.asset.create({
data: {
name: 'robot.glb',
type: 'symlink',
status: 'processed',
projectId: project.id,
parentId: shareLink.rootFolderId,
targetId: modelAsset.id,
},
})
const mediaIds = await watermarkService.getMediaAssetIdsInShareLink(shareLink.rootFolderId)
expect(mediaIds).toContain(modelAsset.id)
})
describe('purgeOrphanWatermarkConfigs', () => {
const bucket = 'shumai-gc-test-bucket'
+4 -2
View File
@@ -23,6 +23,7 @@ import {
} from '@shumai/core/src/share/errors'
import { shareService } from '@shumai/core/src/share/share'
import { logger } from '@shumai/core/src/logger'
import { is3dModel } from '@shumai/core/src/utils/mime'
// Union of the global client and interactive-transaction client, which share the
// same delegate shapes for the models used by this service.
@@ -319,11 +320,12 @@ export class WatermarkService {
const proxyType = mediaInfo?.proxyType
const isVideo = proxyType === 'video' || asset.mediaType?.startsWith('video/')
const isImage = proxyType === 'image' || asset.mediaType?.startsWith('image/')
const is3d = proxyType === '3d' || is3dModel(asset.mediaType)
if (isVideo || isImage) {
if (isVideo || isImage || is3d) {
mediaAssetIds.push(asset.id)
}
} else if (asset.type === 'folder') {
} else if (asset.type === 'folder' || asset.type === 'version_stack') {
folderIds.push(asset.id)
} else if (asset.type === 'symlink' && asset.targetId) {
// Resolve nested symlinks (e.g. folders that contain their own symlinks)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@shumai/db",
"version": "0.4.7",
"version": "0.5.2",
"private": true,
"type": "module",
"main": "./src/index.ts",
@@ -0,0 +1,11 @@
-- CreateEnum
CREATE TYPE "NotificationEmailStatus" AS ENUM ('pending', 'processing', 'processed', 'failed');
-- AlterTable
ALTER TABLE "notifications" ADD COLUMN "email_status" "NotificationEmailStatus" NOT NULL DEFAULT 'pending';
-- Update legacy rows to processed
UPDATE "notifications" SET "email_status" = 'processed';
-- CreateIndex
CREATE INDEX "notifications_email_status_created_at_idx" ON "notifications"("email_status", "created_at");
@@ -0,0 +1,16 @@
-- Migrate videoStrategy 'all' / 'full' to 'multi'
UPDATE "teams"
SET "settings" = jsonb_set("settings", '{transcode,videoStrategy}', '"multi"')
WHERE "settings"->'transcode'->>'videoStrategy' IN ('all', 'full');
-- Normalize legacy videoStrategy values 'single' / 'disable' to 'best_match'
UPDATE "teams"
SET "settings" = jsonb_set("settings", '{transcode,videoStrategy}', '"best_match"')
WHERE "settings"->'transcode'->>'videoStrategy' IN ('single', 'disable');
-- Backfill default videoResolutions where transcode settings exist without videoResolutions
UPDATE "teams"
SET "settings" = jsonb_set("settings", '{transcode,videoResolutions}', '["480p", "720p", "1080p", "1440p", "2160p"]'::jsonb)
WHERE "settings" IS NOT NULL
AND jsonb_typeof("settings"->'transcode') = 'object'
AND NOT ("settings"->'transcode' ? 'videoResolutions');
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "AssetStatus" ADD VALUE 'failed';
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "WorkflowTaskType" ADD VALUE 'transcode_3d';
+12
View File
@@ -40,6 +40,7 @@ enum AssetStatus {
uploaded
processing
processed
failed
trashed
pending_purge
}
@@ -76,6 +77,13 @@ enum NotificationType {
kanban_task_comment_created
}
enum NotificationEmailStatus {
pending
processing
processed
failed
}
enum ProjectMemberRole {
owner
editor
@@ -113,6 +121,7 @@ enum WorkflowTaskType {
transcode_screenshot
transcode_image_annotation
transcode_watermark
transcode_3d
ai_metadata_autofill
chat
ai_embedding
@@ -776,9 +785,12 @@ model Notification {
userId String? @map("user_id")
user User? @relation("UserToNotification", fields: [userId], references: [id])
emailStatus NotificationEmailStatus @default(pending) @map("email_status")
readByMembers TeamMember? @relation("TeamMemberToLastReadNotification")
@@index([kanbanTaskId])
@@index([emailStatus, createdAt])
@@map("notifications")
}
+34
View File
@@ -538,6 +538,13 @@ export type EnumNotificationTypeNullableFilter<$PrismaModel = never> = {
not?: Prisma.NestedEnumNotificationTypeNullableFilter<$PrismaModel> | $Enums.NotificationType | null
}
export type EnumNotificationEmailStatusFilter<$PrismaModel = never> = {
equals?: $Enums.NotificationEmailStatus | Prisma.EnumNotificationEmailStatusFieldRefInput<$PrismaModel>
in?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
notIn?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
not?: Prisma.NestedEnumNotificationEmailStatusFilter<$PrismaModel> | $Enums.NotificationEmailStatus
}
export type EnumNotificationTypeNullableWithAggregatesFilter<$PrismaModel = never> = {
equals?: $Enums.NotificationType | Prisma.EnumNotificationTypeFieldRefInput<$PrismaModel> | null
in?: $Enums.NotificationType[] | Prisma.ListEnumNotificationTypeFieldRefInput<$PrismaModel> | null
@@ -548,6 +555,16 @@ export type EnumNotificationTypeNullableWithAggregatesFilter<$PrismaModel = neve
_max?: Prisma.NestedEnumNotificationTypeNullableFilter<$PrismaModel>
}
export type EnumNotificationEmailStatusWithAggregatesFilter<$PrismaModel = never> = {
equals?: $Enums.NotificationEmailStatus | Prisma.EnumNotificationEmailStatusFieldRefInput<$PrismaModel>
in?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
notIn?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
not?: Prisma.NestedEnumNotificationEmailStatusWithAggregatesFilter<$PrismaModel> | $Enums.NotificationEmailStatus
_count?: Prisma.NestedIntFilter<$PrismaModel>
_min?: Prisma.NestedEnumNotificationEmailStatusFilter<$PrismaModel>
_max?: Prisma.NestedEnumNotificationEmailStatusFilter<$PrismaModel>
}
export type EnumTaskTypeNullableFilter<$PrismaModel = never> = {
equals?: $Enums.TaskType | Prisma.EnumTaskTypeFieldRefInput<$PrismaModel> | null
in?: $Enums.TaskType[] | Prisma.ListEnumTaskTypeFieldRefInput<$PrismaModel> | null
@@ -1367,6 +1384,13 @@ export type NestedEnumNotificationTypeNullableFilter<$PrismaModel = never> = {
not?: Prisma.NestedEnumNotificationTypeNullableFilter<$PrismaModel> | $Enums.NotificationType | null
}
export type NestedEnumNotificationEmailStatusFilter<$PrismaModel = never> = {
equals?: $Enums.NotificationEmailStatus | Prisma.EnumNotificationEmailStatusFieldRefInput<$PrismaModel>
in?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
notIn?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
not?: Prisma.NestedEnumNotificationEmailStatusFilter<$PrismaModel> | $Enums.NotificationEmailStatus
}
export type NestedEnumNotificationTypeNullableWithAggregatesFilter<$PrismaModel = never> = {
equals?: $Enums.NotificationType | Prisma.EnumNotificationTypeFieldRefInput<$PrismaModel> | null
in?: $Enums.NotificationType[] | Prisma.ListEnumNotificationTypeFieldRefInput<$PrismaModel> | null
@@ -1377,6 +1401,16 @@ export type NestedEnumNotificationTypeNullableWithAggregatesFilter<$PrismaModel
_max?: Prisma.NestedEnumNotificationTypeNullableFilter<$PrismaModel>
}
export type NestedEnumNotificationEmailStatusWithAggregatesFilter<$PrismaModel = never> = {
equals?: $Enums.NotificationEmailStatus | Prisma.EnumNotificationEmailStatusFieldRefInput<$PrismaModel>
in?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
notIn?: $Enums.NotificationEmailStatus[] | Prisma.ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel>
not?: Prisma.NestedEnumNotificationEmailStatusWithAggregatesFilter<$PrismaModel> | $Enums.NotificationEmailStatus
_count?: Prisma.NestedIntFilter<$PrismaModel>
_min?: Prisma.NestedEnumNotificationEmailStatusFilter<$PrismaModel>
_max?: Prisma.NestedEnumNotificationEmailStatusFilter<$PrismaModel>
}
export type NestedEnumTaskTypeNullableFilter<$PrismaModel = never> = {
equals?: $Enums.TaskType | Prisma.EnumTaskTypeFieldRefInput<$PrismaModel> | null
in?: $Enums.TaskType[] | Prisma.ListEnumTaskTypeFieldRefInput<$PrismaModel> | null
+12
View File
@@ -36,6 +36,7 @@ export const AssetStatus = {
uploaded: 'uploaded',
processing: 'processing',
processed: 'processed',
failed: 'failed',
trashed: 'trashed',
pending_purge: 'pending_purge'
} as const
@@ -87,6 +88,16 @@ export const NotificationType = {
export type NotificationType = (typeof NotificationType)[keyof typeof NotificationType]
export const NotificationEmailStatus = {
pending: 'pending',
processing: 'processing',
processed: 'processed',
failed: 'failed'
} as const
export type NotificationEmailStatus = (typeof NotificationEmailStatus)[keyof typeof NotificationEmailStatus]
export const ProjectMemberRole = {
owner: 'owner',
editor: 'editor',
@@ -139,6 +150,7 @@ export const WorkflowTaskType = {
transcode_screenshot: 'transcode_screenshot',
transcode_image_annotation: 'transcode_image_annotation',
transcode_watermark: 'transcode_watermark',
transcode_3d: 'transcode_3d',
ai_metadata_autofill: 'ai_metadata_autofill',
chat: 'chat',
ai_embedding: 'ai_embedding',
File diff suppressed because one or more lines are too long
+16 -1
View File
@@ -4724,7 +4724,8 @@ export const NotificationScalarFieldEnum = {
assetId: 'assetId',
taskId: 'taskId',
kanbanTaskId: 'kanbanTaskId',
userId: 'userId'
userId: 'userId',
emailStatus: 'emailStatus'
} as const
export type NotificationScalarFieldEnum = (typeof NotificationScalarFieldEnum)[keyof typeof NotificationScalarFieldEnum]
@@ -5421,6 +5422,20 @@ export type ListEnumNotificationTypeFieldRefInput<$PrismaModel> = FieldRefInputT
/**
* Reference to a field of type 'NotificationEmailStatus'
*/
export type EnumNotificationEmailStatusFieldRefInput<$PrismaModel> = FieldRefInputType<$PrismaModel, 'NotificationEmailStatus'>
/**
* Reference to a field of type 'NotificationEmailStatus[]'
*/
export type ListEnumNotificationEmailStatusFieldRefInput<$PrismaModel> = FieldRefInputType<$PrismaModel, 'NotificationEmailStatus[]'>
/**
* Reference to a field of type 'TaskType'
*/
@@ -490,7 +490,8 @@ export const NotificationScalarFieldEnum = {
assetId: 'assetId',
taskId: 'taskId',
kanbanTaskId: 'kanbanTaskId',
userId: 'userId'
userId: 'userId',
emailStatus: 'emailStatus'
} as const
export type NotificationScalarFieldEnum = (typeof NotificationScalarFieldEnum)[keyof typeof NotificationScalarFieldEnum]

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