mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-20 23:38:41 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c302c162a0 | ||
|
|
432be04a96 | ||
|
|
6c95d14fb3 | ||
|
|
3263580e89 | ||
|
|
f3da916905 | ||
|
|
fe8d404a44 | ||
|
|
0f9d213b1d | ||
|
|
f952318b34 | ||
|
|
43a2eced75 | ||
|
|
e894457275 | ||
|
|
4b1b64fe2b | ||
|
|
f8beb195dd | ||
|
|
a97996cb59 | ||
|
|
f870ca9b49 | ||
|
|
2e5ff281a8 | ||
|
|
de8decf113 | ||
|
|
dd57fb9ed2 | ||
|
|
9a640632aa | ||
|
|
e61641d7ec | ||
|
|
7ca8ba8b2a | ||
|
|
8805d5799a | ||
|
|
013c4a8156 | ||
|
|
20b5ebeefd | ||
|
|
daa20aed20 | ||
|
|
3564d4d164 | ||
|
|
206763e966 | ||
|
|
4e4da595a6 | ||
|
|
a21a0c9655 | ||
|
|
fc7282581f | ||
|
|
e007054f47 | ||
|
|
a84da8678e | ||
|
|
123a8cb5f4 | ||
|
|
5fe22ac52c | ||
|
|
11d21444cf |
@@ -10,6 +10,10 @@ on:
|
||||
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:
|
||||
@@ -20,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
|
||||
@@ -51,8 +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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -12,6 +12,56 @@ 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
|
||||
|
||||
@@ -52,6 +52,8 @@ 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" \
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -162,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]
|
||||
@@ -201,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
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
+8
-5
@@ -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)。
|
||||
|
||||
@@ -187,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]
|
||||
@@ -215,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`权限。
|
||||
|
||||
---
|
||||
|
||||
@@ -226,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,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent-app",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/cli",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/premiere-uxp",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode-app",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/web-app",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
},
|
||||
"apps/agent": {
|
||||
"name": "@shumai/agent-app",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"bin": {
|
||||
"shumai-agent": "./src/index.ts",
|
||||
},
|
||||
@@ -45,7 +45,7 @@
|
||||
},
|
||||
"apps/cli": {
|
||||
"name": "@shumai/cli",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"bin": {
|
||||
"shumai-cli": "./src/index.ts",
|
||||
},
|
||||
@@ -60,7 +60,7 @@
|
||||
},
|
||||
"apps/premiere-uxp": {
|
||||
"name": "@shumai/premiere-uxp",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@shumai/api": "workspace:*",
|
||||
"@shumai/dtos": "workspace:*",
|
||||
@@ -114,7 +114,7 @@
|
||||
},
|
||||
"apps/transcode": {
|
||||
"name": "@shumai/transcode-app",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"bin": {
|
||||
"shumai-transcode": "./src/index.ts",
|
||||
},
|
||||
@@ -126,7 +126,7 @@
|
||||
},
|
||||
"apps/web": {
|
||||
"name": "@shumai/web-app",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@shumai/agent": "workspace:*",
|
||||
"@shumai/api": "workspace:*",
|
||||
@@ -146,7 +146,7 @@
|
||||
},
|
||||
"packages/agent": {
|
||||
"name": "@shumai/agent",
|
||||
"version": "0.4.9",
|
||||
"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.9",
|
||||
"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.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@ai-sdk/alibaba": "2.0.38",
|
||||
"@ai-sdk/amazon-bedrock": "5.0.67",
|
||||
@@ -223,6 +223,7 @@
|
||||
"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",
|
||||
@@ -246,7 +247,7 @@
|
||||
},
|
||||
"packages/db": {
|
||||
"name": "@shumai/db",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"@prisma/adapter-pg": "7.10.0",
|
||||
@@ -262,7 +263,7 @@
|
||||
},
|
||||
"packages/dtos": {
|
||||
"name": "@shumai/dtos",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"zod": "4.5.4",
|
||||
@@ -270,7 +271,7 @@
|
||||
},
|
||||
"packages/e2e": {
|
||||
"name": "@shumai/e2e",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@earendil-works/pi-agent-core": "0.82.1",
|
||||
"@google/genai": "2.19.0",
|
||||
@@ -285,11 +286,11 @@
|
||||
},
|
||||
"packages/tableprinter": {
|
||||
"name": "@shumai/tableprinter",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
},
|
||||
"packages/transcode": {
|
||||
"name": "@shumai/transcode",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@shumai/core": "workspace:*",
|
||||
"@shumai/db": "workspace:*",
|
||||
@@ -303,7 +304,7 @@
|
||||
},
|
||||
"packages/webui": {
|
||||
"name": "@shumai/webui",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@base-ui/react": "1.7.0",
|
||||
"@dnd-kit/abstract": "0.5.0",
|
||||
@@ -363,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",
|
||||
@@ -386,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",
|
||||
},
|
||||
@@ -405,7 +406,7 @@
|
||||
},
|
||||
"packages/workflow-core": {
|
||||
"name": "@shumai/workflow-core",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"dependencies": {
|
||||
"@shumai/core": "workspace:*",
|
||||
"@shumai/db": "workspace:*",
|
||||
@@ -911,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=="],
|
||||
@@ -1561,6 +1564,8 @@
|
||||
|
||||
"@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=="],
|
||||
@@ -1627,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=="],
|
||||
@@ -1697,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=="],
|
||||
@@ -1711,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=="],
|
||||
@@ -1795,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=="],
|
||||
@@ -2001,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=="],
|
||||
@@ -2105,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=="],
|
||||
@@ -2213,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=="],
|
||||
@@ -2253,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=="],
|
||||
@@ -2317,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=="],
|
||||
@@ -2471,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=="],
|
||||
|
||||
@@ -2545,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=="],
|
||||
@@ -2559,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=="],
|
||||
@@ -2695,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=="],
|
||||
@@ -3101,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=="],
|
||||
|
||||
@@ -3,6 +3,61 @@ 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
|
||||
|
||||
@@ -99,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` |
|
||||
|
||||
@@ -55,6 +55,20 @@ Shumai includes a built-in usability probe that tests hardware encoders at start
|
||||
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.
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"using-shumai/collections",
|
||||
"using-shumai/share-links",
|
||||
"using-shumai/nle-and-premiere",
|
||||
"using-shumai/3d-asset-support",
|
||||
"using-shumai/gotenberg"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -44,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`
|
||||
|
||||
@@ -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.
|
||||
@@ -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:
|
||||
|
||||
@@ -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>
|
||||
|
||||

|
||||
### 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.
|
||||
|
||||

|
||||
|
||||
---
|
||||
|
||||
## 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,10 +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.
|
||||
|
||||
---
|
||||
|
||||
## Hardware Acceleration
|
||||
|
||||
To offload encoding workloads to GPUs (NVIDIA NVENC, Intel QuickSync, AMD/Intel VA-API, or Rockchip RKMPP), Shumai supports hardware-accelerated transcoding. See the [Hardware Transcoding Guide](/configuration/hardware-transcoding) for Docker Compose configuration, GPU passthrough, and driver prerequisites.
|
||||
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.
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "shumai",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"repository": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -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,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,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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<id>&"123"" />\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 }
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 },
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/api",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
@@ -56,10 +59,27 @@ async function applyWatermarkToAssetMedia(
|
||||
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(
|
||||
@@ -74,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,
|
||||
@@ -170,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 {
|
||||
@@ -197,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,
|
||||
@@ -206,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)
|
||||
@@ -219,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)
|
||||
@@ -360,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
|
||||
|
||||
@@ -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' })
|
||||
})
|
||||
@@ -478,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({
|
||||
@@ -866,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,
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
@@ -245,17 +261,17 @@ describe('team api', () => {
|
||||
})
|
||||
|
||||
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,
|
||||
@@ -263,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 () => {
|
||||
@@ -615,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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/core",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
@@ -42,6 +42,7 @@
|
||||
"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",
|
||||
|
||||
@@ -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')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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 /),
|
||||
}),
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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
|
||||
}
|
||||
@@ -369,8 +369,23 @@ describe('TeamService', () => {
|
||||
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 },
|
||||
})
|
||||
@@ -383,24 +398,61 @@ describe('TeamService', () => {
|
||||
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',
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
@@ -35,6 +37,7 @@ export class TeamService {
|
||||
settings: {
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
videoResolutions: ['480p', '720p', '1080p', '1440p', '2160p'],
|
||||
hardwareAcceleration: 'off',
|
||||
threads: 0,
|
||||
},
|
||||
@@ -312,8 +315,27 @@ export class TeamService {
|
||||
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']
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,6 +345,9 @@ export class TeamService {
|
||||
settings.appearance.hideAgent = false
|
||||
}
|
||||
|
||||
settings.turntable = await turntableService.getSettings(teamId)
|
||||
settings.gotenberg = await gotenbergService.getSettings(teamId)
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
@@ -336,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 = {}
|
||||
@@ -354,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 = {}
|
||||
|
||||
@@ -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 })
|
||||
})
|
||||
})
|
||||
@@ -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',
|
||||
}),
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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()
|
||||
@@ -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' },
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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
|
||||
}
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
@@ -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'
|
||||
|
||||
|
||||
@@ -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,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/db",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
+16
@@ -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';
|
||||
@@ -40,6 +40,7 @@ enum AssetStatus {
|
||||
uploaded
|
||||
processing
|
||||
processed
|
||||
failed
|
||||
trashed
|
||||
pending_purge
|
||||
}
|
||||
@@ -120,6 +121,7 @@ enum WorkflowTaskType {
|
||||
transcode_screenshot
|
||||
transcode_image_annotation
|
||||
transcode_watermark
|
||||
transcode_3d
|
||||
ai_metadata_autofill
|
||||
chat
|
||||
ai_embedding
|
||||
|
||||
+2
@@ -36,6 +36,7 @@ export const AssetStatus = {
|
||||
uploaded: 'uploaded',
|
||||
processing: 'processing',
|
||||
processed: 'processed',
|
||||
failed: 'failed',
|
||||
trashed: 'trashed',
|
||||
pending_purge: 'pending_purge'
|
||||
} as const
|
||||
@@ -149,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',
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
@@ -48,7 +48,8 @@ declare global {
|
||||
// ----------------------------------------------------------------------
|
||||
// Team Settings
|
||||
// ----------------------------------------------------------------------
|
||||
export type VideoTranscodeStrategy = 'best_match' | 'all'
|
||||
export type VideoTranscodeStrategy = 'best_match' | 'multi' | 'all'
|
||||
export type VideoResolutionLadder = '480p' | '720p' | '1080p' | '1440p' | '2160p'
|
||||
export type HardwareAcceleration = 'off' | 'auto'
|
||||
export type HdrType = 'pq' | 'hlg' | 'dovi_p5' | 'dovi_p8' | 'sdr'
|
||||
|
||||
@@ -57,10 +58,15 @@ declare global {
|
||||
// ----------------------------------------------------------------------
|
||||
export type CollectionFilter = import('@shumai/dtos').CollectionFilter
|
||||
|
||||
export type HlsResolutionLadder = '480p' | '720p' | '1080p' | '1440p' | '2160p'
|
||||
|
||||
export interface TranscodeSettings {
|
||||
videoStrategy: VideoTranscodeStrategy
|
||||
videoResolutions?: VideoResolutionLadder[]
|
||||
hardwareAcceleration?: HardwareAcceleration
|
||||
threads?: number
|
||||
hlsEnabled?: boolean
|
||||
hlsResolutions?: HlsResolutionLadder[]
|
||||
}
|
||||
|
||||
export interface MediaProviderConfig {
|
||||
@@ -97,8 +103,22 @@ declare global {
|
||||
replyTo?: string
|
||||
}
|
||||
|
||||
export interface TurntableSettings {
|
||||
url?: string
|
||||
username?: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
export interface GotenbergSettings {
|
||||
url?: string
|
||||
username?: string
|
||||
password?: string
|
||||
}
|
||||
|
||||
export interface Settings {
|
||||
transcode?: TranscodeSettings
|
||||
turntable?: TurntableSettings
|
||||
gotenberg?: GotenbergSettings
|
||||
mediaGeneration?: MediaGenerationSettings
|
||||
appearance?: AppearanceSettings
|
||||
emailNotification?: EmailNotificationSettings
|
||||
@@ -164,6 +184,8 @@ declare global {
|
||||
isHdr?: boolean
|
||||
hdrType?: HdrType
|
||||
dvProfile?: number
|
||||
videoStreamIndex?: number
|
||||
audioStreamIndex?: number
|
||||
format: unknown
|
||||
}
|
||||
|
||||
@@ -178,11 +200,17 @@ declare global {
|
||||
url?: string
|
||||
}
|
||||
|
||||
export interface HlsInfo {
|
||||
key: string
|
||||
url?: string
|
||||
resolutions: VideoTranscode[]
|
||||
}
|
||||
|
||||
export interface MediaInfo {
|
||||
duration: number
|
||||
filesize: number
|
||||
frames: number
|
||||
proxyType?: 'image' | 'video' | 'audio' | 'pdf'
|
||||
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | '3d'
|
||||
imageTranscodes: ImageTranscode[]
|
||||
videoTranscodes: VideoTranscode[]
|
||||
videoPreview?: VideoTranscode
|
||||
@@ -193,6 +221,9 @@ declare global {
|
||||
finishedAt: string
|
||||
metadata: Metadata | null
|
||||
original: OriginalInfo | null
|
||||
isHls?: boolean
|
||||
hls?: HlsInfo
|
||||
error?: string
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
@@ -336,11 +367,14 @@ declare global {
|
||||
// ----------------------------------------------------------------------
|
||||
export interface TaskSpec {
|
||||
videoStrategy?: VideoTranscodeStrategy
|
||||
videoResolutions?: VideoResolutionLadder[]
|
||||
hardwareAcceleration?: HardwareAcceleration
|
||||
threads?: number
|
||||
thumbnail?: boolean
|
||||
sprite?: boolean
|
||||
poster?: boolean
|
||||
hlsEnabled?: boolean
|
||||
hlsResolutions?: HlsResolutionLadder[]
|
||||
}
|
||||
|
||||
export interface AgentTaskPayload {
|
||||
@@ -510,7 +544,7 @@ declare global {
|
||||
key: string
|
||||
sizeByte: number
|
||||
contentType?: string | null
|
||||
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | null
|
||||
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | '3d' | null
|
||||
}
|
||||
export type KanbanCommentAttachmentList = KanbanCommentAttachment[]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/dtos",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -14,7 +14,7 @@ export const assetInfoPaginatedListSchema = z.object({
|
||||
export type AssetInfoPaginatedList = z.infer<typeof assetInfoPaginatedListSchema>
|
||||
|
||||
export const previewInfoSchema = z.object({
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
thumbnailUrl: z.string().optional(),
|
||||
originalHeight: z.number().optional(),
|
||||
originalWidth: z.number().optional(),
|
||||
@@ -76,7 +76,7 @@ export const assetInfoSchema = z.object({
|
||||
type: z.string(),
|
||||
targetType: z.string().optional().nullable(),
|
||||
status: z.string(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
latestChildren: z.array(childPreviewSchema).optional(),
|
||||
preview: previewInfoSchema.nullable().optional(),
|
||||
createdAt: z.string(),
|
||||
@@ -105,6 +105,7 @@ export const assetInfoSchema = z.object({
|
||||
width: z.number(),
|
||||
height: z.number(),
|
||||
size: z.number(),
|
||||
resolution: z.string().optional(),
|
||||
hdr: z.boolean().optional(),
|
||||
}),
|
||||
)
|
||||
@@ -123,8 +124,28 @@ export const assetInfoSchema = z.object({
|
||||
.optional(),
|
||||
videoPreview: z.object({ url: z.string(), key: z.string().optional() }).optional(),
|
||||
pdfTranscode: z.object({ url: z.string(), key: z.string().optional() }).optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
isHls: z.boolean().optional(),
|
||||
hls: z
|
||||
.object({
|
||||
key: z.string(),
|
||||
url: z.string().optional(),
|
||||
resolutions: z
|
||||
.array(
|
||||
z.object({
|
||||
width: z.number(),
|
||||
height: z.number(),
|
||||
resolution: z.string().optional(),
|
||||
hdr: z.boolean().optional(),
|
||||
key: z.string().optional(),
|
||||
url: z.string().optional(),
|
||||
}),
|
||||
)
|
||||
.optional(),
|
||||
})
|
||||
.optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
metadata: mediaMetadataSchema.optional(),
|
||||
error: z.string().optional(),
|
||||
})
|
||||
.optional(),
|
||||
ancestorFolders: z.array(ancestorFolderSchema).optional(),
|
||||
@@ -212,7 +233,7 @@ export const attachmentInfoSchema = z.object({
|
||||
id: z.string(),
|
||||
assetId: z.string(),
|
||||
url: z.string(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
})
|
||||
export type AttachmentInfo = z.infer<typeof attachmentInfoSchema>
|
||||
|
||||
@@ -338,6 +359,7 @@ export interface VideoTranscode {
|
||||
width: number
|
||||
height: number
|
||||
size: number
|
||||
resolution?: string
|
||||
hdr?: boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ export const shumaiAssetContextSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
mediaType: z.enum(['image', 'video', 'pdf', 'audio', 'other']).optional(),
|
||||
mediaType: z.enum(['image', 'video', 'pdf', 'audio', '3d', 'other']).optional(),
|
||||
mimeType: z.string().optional(),
|
||||
parentId: z.string().optional(),
|
||||
path: z.string().optional(),
|
||||
@@ -64,7 +64,7 @@ export const shumaiAttachedFileContextSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
mediaType: z.enum(['image', 'video', 'pdf', 'audio', 'other']).optional(),
|
||||
mediaType: z.enum(['image', 'video', 'pdf', 'audio', '3d', 'other']).optional(),
|
||||
mimeType: z.string().optional(),
|
||||
path: z.string().optional(),
|
||||
url: z.string().optional(),
|
||||
@@ -75,6 +75,7 @@ export type ShumaiAttachedFileContext = z.infer<typeof shumaiAttachedFileContext
|
||||
export const shumaiMediaPositionSchema = z.discriminatedUnion('type', [
|
||||
z.object({ type: z.literal('time'), seconds: z.number() }),
|
||||
z.object({ type: z.literal('page'), page: z.number() }),
|
||||
z.object({ type: z.literal('degree'), degree: z.number().int() }),
|
||||
])
|
||||
|
||||
export type ShumaiMediaPosition = z.infer<typeof shumaiMediaPositionSchema>
|
||||
|
||||
@@ -104,6 +104,8 @@ export function serializeContextToXml(context?: ShumaiMessageContext | null): st
|
||||
lines.push(` <position type="time" seconds="${context.position.seconds.toFixed(4)}" />`)
|
||||
} else if (context.position.type === 'page') {
|
||||
lines.push(` <position type="page" page="${Math.round(context.position.page)}" />`)
|
||||
} else if (context.position.type === 'degree') {
|
||||
lines.push(` <position type="degree" degree="${Math.round(context.position.degree)}" />`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ export const kanbanAttachmentPayloadSchema = z.object({
|
||||
key: z.string(),
|
||||
sizeByte: z.number(),
|
||||
contentType: z.string().nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
})
|
||||
export type KanbanAttachmentPayload = z.infer<typeof kanbanAttachmentPayloadSchema>
|
||||
|
||||
@@ -17,7 +17,7 @@ export const kanbanAttachmentInfoSchema = z.object({
|
||||
sizeByte: z.number(),
|
||||
contentType: z.string().nullable().optional(),
|
||||
url: z.string(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
})
|
||||
export type KanbanAttachmentInfo = z.infer<typeof kanbanAttachmentInfoSchema>
|
||||
|
||||
@@ -28,7 +28,7 @@ export const postKanbanAttachmentResponseSchema = z.object({
|
||||
sizeByte: z.number(),
|
||||
contentType: z.string().nullable().optional(),
|
||||
uploadUrl: z.string(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
})
|
||||
export type PostKanbanAttachmentResponse = z.infer<typeof postKanbanAttachmentResponseSchema>
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ export const kanbanTaskAssetInfoSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
type: z.string(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
thumbnailUrl: z.string().nullable().optional(),
|
||||
path: z.string(),
|
||||
creator: kanbanUserInfoSchema.nullable().optional(),
|
||||
|
||||
@@ -18,7 +18,7 @@ export type EntityInfo = z.infer<typeof entityInfoSchema>
|
||||
|
||||
export const assetPreviewSchema = z.object({
|
||||
id: z.string().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
|
||||
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
|
||||
name: z.string().optional(),
|
||||
preview: z.string().optional(),
|
||||
thumbnailUrl: z.string().optional(),
|
||||
|
||||
@@ -69,22 +69,56 @@ export const listMembersQuerySchema = z.object({
|
||||
export const VideoTranscodeStrategy = {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
best_match: 'best_match',
|
||||
multi: 'multi',
|
||||
all: 'all',
|
||||
} as const
|
||||
export type VideoTranscodeStrategy =
|
||||
(typeof VideoTranscodeStrategy)[keyof typeof VideoTranscodeStrategy]
|
||||
|
||||
export const VideoResolutionLadder = {
|
||||
r480p: '480p',
|
||||
r720p: '720p',
|
||||
r1080p: '1080p',
|
||||
r1440p: '1440p',
|
||||
r2160p: '2160p',
|
||||
} as const
|
||||
export type VideoResolutionLadder =
|
||||
(typeof VideoResolutionLadder)[keyof typeof VideoResolutionLadder]
|
||||
|
||||
export const DEFAULT_VIDEO_RESOLUTIONS: VideoResolutionLadder[] = [
|
||||
'480p',
|
||||
'720p',
|
||||
'1080p',
|
||||
'1440p',
|
||||
'2160p',
|
||||
]
|
||||
|
||||
export const HardwareAcceleration = {
|
||||
off: 'off',
|
||||
auto: 'auto',
|
||||
} as const
|
||||
export type HardwareAcceleration = (typeof HardwareAcceleration)[keyof typeof HardwareAcceleration]
|
||||
|
||||
export const HlsResolutionLadder = {
|
||||
r480p: '480p',
|
||||
r720p: '720p',
|
||||
r1080p: '1080p',
|
||||
r1440p: '1440p',
|
||||
r2160p: '2160p',
|
||||
} as const
|
||||
export type HlsResolutionLadder = (typeof HlsResolutionLadder)[keyof typeof HlsResolutionLadder]
|
||||
|
||||
export const DEFAULT_HLS_RESOLUTIONS: HlsResolutionLadder[] = ['480p', '720p', '1080p']
|
||||
|
||||
export const updateTeamSettingsRequestSchema = z.union([
|
||||
z.object({
|
||||
key: z.literal('transcode.videoStrategy'),
|
||||
value: z.nativeEnum(VideoTranscodeStrategy),
|
||||
}),
|
||||
z.object({
|
||||
key: z.literal('transcode.videoResolutions'),
|
||||
value: z.array(z.nativeEnum(VideoResolutionLadder)),
|
||||
}),
|
||||
z.object({
|
||||
key: z.literal('transcode.hardwareAcceleration'),
|
||||
value: z.nativeEnum(HardwareAcceleration),
|
||||
@@ -93,6 +127,14 @@ export const updateTeamSettingsRequestSchema = z.union([
|
||||
key: z.literal('transcode.threads'),
|
||||
value: z.number().int().min(0).max(32),
|
||||
}),
|
||||
z.object({
|
||||
key: z.literal('transcode.hlsEnabled'),
|
||||
value: z.boolean(),
|
||||
}),
|
||||
z.object({
|
||||
key: z.literal('transcode.hlsResolutions'),
|
||||
value: z.array(z.nativeEnum(HlsResolutionLadder)),
|
||||
}),
|
||||
z.object({
|
||||
key: z.literal('appearance.hideAgent'),
|
||||
value: z.boolean(),
|
||||
@@ -100,6 +142,36 @@ export const updateTeamSettingsRequestSchema = z.union([
|
||||
])
|
||||
export type UpdateTeamSettingsRequest = z.infer<typeof updateTeamSettingsRequestSchema>
|
||||
|
||||
export const turntableSettingsResponseSchema = z.object({
|
||||
url: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
hasPassword: z.boolean(),
|
||||
isEnvConfigured: z.boolean(),
|
||||
})
|
||||
export type TurntableSettingsResponse = z.infer<typeof turntableSettingsResponseSchema>
|
||||
|
||||
export const updateTurntableSettingsRequestSchema = z.object({
|
||||
url: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
})
|
||||
export type UpdateTurntableSettingsRequest = z.infer<typeof updateTurntableSettingsRequestSchema>
|
||||
|
||||
export const gotenbergSettingsResponseSchema = z.object({
|
||||
url: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
hasPassword: z.boolean(),
|
||||
isEnvConfigured: z.boolean(),
|
||||
})
|
||||
export type GotenbergSettingsResponse = z.infer<typeof gotenbergSettingsResponseSchema>
|
||||
|
||||
export const updateGotenbergSettingsRequestSchema = z.object({
|
||||
url: z.string().optional(),
|
||||
username: z.string().optional(),
|
||||
password: z.string().optional(),
|
||||
})
|
||||
export type UpdateGotenbergSettingsRequest = z.infer<typeof updateGotenbergSettingsRequestSchema>
|
||||
|
||||
export interface TeamAppearanceSettings {
|
||||
hideAgent?: boolean
|
||||
}
|
||||
@@ -107,9 +179,14 @@ export interface TeamAppearanceSettings {
|
||||
export interface TeamSettingsResponse {
|
||||
transcode?: {
|
||||
videoStrategy?: VideoTranscodeStrategy
|
||||
videoResolutions?: VideoResolutionLadder[]
|
||||
hardwareAcceleration?: HardwareAcceleration
|
||||
threads?: number
|
||||
hlsEnabled?: boolean
|
||||
hlsResolutions?: HlsResolutionLadder[]
|
||||
}
|
||||
turntable?: TurntableSettingsResponse
|
||||
gotenberg?: GotenbergSettingsResponse
|
||||
appearance?: TeamAppearanceSettings
|
||||
semanticSearchEnabled?: boolean
|
||||
[key: string]: unknown
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/e2e",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
|
||||
import { prisma, AssetStatus } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import { workflowService, TaskQueueTranscode } from '@shumai/workflow-core'
|
||||
import { initTranscodeWorkflows } from '@shumai/transcode'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { fileURLToPath } from 'url'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||||
const transcodeWorkflowsPath = path.resolve(currentDir, '../../../apps/transcode/src/workflows.ts')
|
||||
const fixturesDir = path.resolve(currentDir, '../fixtures')
|
||||
|
||||
describe.each(['local', 'temporal'] as const)(
|
||||
'Workflow E2E - 3D Asset Transcode (executor: %s)',
|
||||
(mode) => {
|
||||
setupTestDbHooks()
|
||||
|
||||
let transcodeWorkerPromise: Promise<void> | null = null
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
let mockTurntableServer: any = null
|
||||
|
||||
beforeAll(async () => {
|
||||
process.env.S3_BUCKET = 'shumai-e2e-test-bucket-3d'
|
||||
|
||||
const smallPngBuffer = fs.readFileSync(path.join(fixturesDir, 'small.png'))
|
||||
const smallMp4Buffer = fs.readFileSync(path.join(fixturesDir, 'small.mp4'))
|
||||
|
||||
mockTurntableServer = Bun.serve({
|
||||
port: 0,
|
||||
fetch(req) {
|
||||
const url = new URL(req.url)
|
||||
if (url.pathname === '/version') {
|
||||
return Response.json({ version: '1.0.0', runtime: 'bun', blender: '5.2.0' })
|
||||
}
|
||||
if (url.pathname === '/v1/files' && req.method === 'POST') {
|
||||
return Response.json({ id: 'f_input3d', name: 'model.glb', size: 100 }, { status: 201 })
|
||||
}
|
||||
if (url.pathname === '/v1/render' && req.method === 'POST') {
|
||||
return Response.json(
|
||||
{
|
||||
taskId: 't_render3d',
|
||||
status: 'completed',
|
||||
poster: {
|
||||
fileId: 'f_poster3d',
|
||||
size: smallPngBuffer.length,
|
||||
contentType: 'image/png',
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
},
|
||||
metadata: { format: 'glb' },
|
||||
},
|
||||
{ status: 201 },
|
||||
)
|
||||
}
|
||||
if (url.pathname === '/v1/render/tasks/t_render3d') {
|
||||
if (req.method === 'DELETE') {
|
||||
return Response.json({ ok: true })
|
||||
}
|
||||
return Response.json({
|
||||
taskId: 't_render3d',
|
||||
status: 'completed',
|
||||
posterFileId: 'f_poster3d',
|
||||
video: {
|
||||
fileId: 'f_video3d',
|
||||
size: smallMp4Buffer.length,
|
||||
contentType: 'video/mp4',
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
},
|
||||
})
|
||||
}
|
||||
if (url.pathname === '/v1/files/f_poster3d') {
|
||||
return new Response(smallPngBuffer, {
|
||||
headers: { 'Content-Type': 'image/png' },
|
||||
})
|
||||
}
|
||||
if (url.pathname === '/v1/files/f_video3d') {
|
||||
return new Response(smallMp4Buffer, {
|
||||
headers: { 'Content-Type': 'video/mp4' },
|
||||
})
|
||||
}
|
||||
return new Response('Not Found', { status: 404 })
|
||||
},
|
||||
})
|
||||
|
||||
process.env.TURNTABLE_RENDERER_URL = `http://localhost:${mockTurntableServer.port}`
|
||||
|
||||
workflowService.setExecutorType(mode)
|
||||
initTranscodeWorkflows()
|
||||
|
||||
if (mode === 'temporal') {
|
||||
console.log('Starting background worker for transcode Temporal E2E tests...')
|
||||
transcodeWorkerPromise = workflowService.startWorkers(TaskQueueTranscode, {
|
||||
workflowsPath: transcodeWorkflowsPath,
|
||||
})
|
||||
await new Promise((resolve) => setTimeout(resolve, 2000))
|
||||
} else {
|
||||
console.log('Starting local workflow service polling...')
|
||||
workflowService.start()
|
||||
}
|
||||
}, 120000)
|
||||
|
||||
afterAll(async () => {
|
||||
if (mode === 'temporal') {
|
||||
console.log('Shutting down Temporal workers...')
|
||||
await workflowService.shutdownWorkers()
|
||||
await Promise.all([transcodeWorkerPromise].filter(Boolean))
|
||||
}
|
||||
workflowService.close()
|
||||
vi.restoreAllMocks()
|
||||
|
||||
if (mockTurntableServer) {
|
||||
mockTurntableServer.stop()
|
||||
}
|
||||
|
||||
delete process.env.TURNTABLE_RENDERER_URL
|
||||
|
||||
try {
|
||||
console.log('Cleaning up E2E storage files...')
|
||||
await s3Service.deletePrefix('shumai-e2e-test-bucket-3d', '')
|
||||
} catch (err) {
|
||||
console.error('Failed to clean up E2E storage folder:', err)
|
||||
}
|
||||
}, 120000)
|
||||
|
||||
it('should process 3D model transcode workflow task', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E 3D Transcode Team' },
|
||||
})
|
||||
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E 3D Transcode Project', teamId: team.id },
|
||||
})
|
||||
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: {
|
||||
key: 'projects/e2e/model.glb',
|
||||
status: 'active',
|
||||
},
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'model.glb',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'model/gltf-binary',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const dummyGlbBuffer = Buffer.from('dummy glb content')
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-3d',
|
||||
'projects/e2e/model.glb',
|
||||
dummyGlbBuffer,
|
||||
dummyGlbBuffer.length,
|
||||
'model/gltf-binary',
|
||||
)
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_3d',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
poster: true,
|
||||
sprite: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
console.log(
|
||||
`Submitted E2E 3D Transcode Workflow Task. ID: ${task.id}. Awaiting completion...`,
|
||||
)
|
||||
const completedTask = await workflowService.executeWait(task, 60000)
|
||||
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType?: string
|
||||
videoPreview?: { key: string }
|
||||
poster?: { key: string }
|
||||
sprite?: { key: string }
|
||||
}
|
||||
expect(mediaInfo).toBeDefined()
|
||||
expect(mediaInfo.proxyType).toBe('3d')
|
||||
expect(mediaInfo.videoPreview?.key).toBe('projects/e2e/turntable.mp4')
|
||||
expect(mediaInfo.poster?.key).toBe('projects/e2e/poster.webp')
|
||||
expect(mediaInfo.sprite?.key).toBe('projects/e2e/sprite.webp')
|
||||
}, 90000)
|
||||
},
|
||||
)
|
||||
@@ -214,5 +214,166 @@ describe.each(['local', 'temporal'] as const)(
|
||||
expect(mediaInfo.imageTranscodes.length).toBeGreaterThan(0)
|
||||
expect(mediaInfo.thumbnail).toBeDefined()
|
||||
}, 50000)
|
||||
|
||||
it('should run transcodeMedia workflow for a RAW image asset (.dng) successfully', async () => {
|
||||
// 1. Seed Database
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E RAW Transcode Team' },
|
||||
})
|
||||
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E RAW Transcode Project', teamId: team.id },
|
||||
})
|
||||
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: {
|
||||
key: 'projects/e2e/test.dng',
|
||||
},
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'test.dng',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'image/x-adobe-dng',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
// 2. Seed S3 Storage from fixture test.dng
|
||||
const dngPath = path.join(fixturesDir, 'test.dng')
|
||||
const dngBuffer = fs.readFileSync(dngPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/test.dng',
|
||||
dngBuffer,
|
||||
dngBuffer.length,
|
||||
'image/x-adobe-dng',
|
||||
)
|
||||
|
||||
// 3. Create Workflow Task
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_image',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
thumbnail: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 4. Wait for workflow to complete
|
||||
console.log(
|
||||
`Submitted E2E RAW Image Transcode Workflow Task. ID: ${task.id}. Awaiting completion...`,
|
||||
)
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
|
||||
// 5. Verification
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType: string
|
||||
imageTranscodes: unknown[]
|
||||
thumbnail: unknown
|
||||
}
|
||||
expect(mediaInfo).toBeDefined()
|
||||
expect(mediaInfo.proxyType).toBe('image')
|
||||
expect(mediaInfo.imageTranscodes).toBeDefined()
|
||||
expect(mediaInfo.imageTranscodes.length).toBeGreaterThan(0)
|
||||
expect(mediaInfo.thumbnail).toBeDefined()
|
||||
}, 50000)
|
||||
|
||||
it('should transcode a rotated camera photo upright', async () => {
|
||||
// 1. Seed Database
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Rotated Transcode Team' },
|
||||
})
|
||||
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Rotated Transcode Project', teamId: team.id },
|
||||
})
|
||||
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: {
|
||||
key: 'projects/e2e/portrait-rotated.jpg',
|
||||
},
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'portrait-rotated.jpg',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'image/jpeg',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
// 2. Seed S3 Storage from fixture portrait-rotated.jpg: stored 600x400 with EXIF
|
||||
// orientation 6, the way cameras save portrait shots, so it is displayed 400x600.
|
||||
const jpgPath = path.join(fixturesDir, 'portrait-rotated.jpg')
|
||||
const jpgBuffer = fs.readFileSync(jpgPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/portrait-rotated.jpg',
|
||||
jpgBuffer,
|
||||
jpgBuffer.length,
|
||||
'image/jpeg',
|
||||
)
|
||||
|
||||
// 3. Create Workflow Task
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_image',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
thumbnail: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 4. Wait for workflow to complete
|
||||
console.log(
|
||||
`Submitted E2E Rotated Image Transcode Workflow Task. ID: ${task.id}. Awaiting completion...`,
|
||||
)
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
|
||||
// 5. Verification: the asset and its transcode are portrait, not the stored landscape.
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
imageTranscodes: Array<{ width: number; height: number }>
|
||||
metadata: { originalWidth: number; originalHeight: number }
|
||||
}
|
||||
expect(mediaInfo.metadata.originalWidth).toBe(400)
|
||||
expect(mediaInfo.metadata.originalHeight).toBe(600)
|
||||
expect(mediaInfo.imageTranscodes[0].width).toBe(400)
|
||||
expect(mediaInfo.imageTranscodes[0].height).toBe(600)
|
||||
}, 50000)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,17 +1,63 @@
|
||||
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
|
||||
import { prisma, AssetStatus } from '@shumai/db'
|
||||
import { prisma, AssetStatus, AssetType } from '@shumai/db'
|
||||
import { setupTestDbHooks } from '@shumai/db/test'
|
||||
import { workflowService, TaskQueueTranscode } from '@shumai/workflow-core'
|
||||
import { initTranscodeWorkflows } from '@shumai/transcode'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { assetService } from '@shumai/core/src/asset/asset'
|
||||
import { fileURLToPath } from 'url'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
import { execFile } from 'child_process'
|
||||
import { promisify } from 'util'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||||
const transcodeWorkflowsPath = path.resolve(currentDir, '../../../apps/transcode/src/workflows.ts')
|
||||
const fixturesDir = path.resolve(currentDir, '../fixtures')
|
||||
|
||||
async function sampleFirstFrameRgb(
|
||||
buffer: Buffer,
|
||||
ext: string = 'mp4',
|
||||
): Promise<{ r: number; g: number; b: number }> {
|
||||
const tmpFile = path.join(
|
||||
os.tmpdir(),
|
||||
`sample-${Date.now()}-${Math.random().toString(36).slice(2)}.${ext}`,
|
||||
)
|
||||
try {
|
||||
fs.writeFileSync(tmpFile, buffer)
|
||||
const proc = await execFileAsync(
|
||||
'ffmpeg',
|
||||
[
|
||||
'-y',
|
||||
'-i',
|
||||
tmpFile,
|
||||
'-vframes',
|
||||
'1',
|
||||
'-s',
|
||||
'1x1',
|
||||
'-f',
|
||||
'rawvideo',
|
||||
'-pix_fmt',
|
||||
'rgb24',
|
||||
'pipe:1',
|
||||
],
|
||||
{ encoding: 'buffer' },
|
||||
)
|
||||
return {
|
||||
r: proc.stdout[0],
|
||||
g: proc.stdout[1],
|
||||
b: proc.stdout[2],
|
||||
}
|
||||
} finally {
|
||||
if (fs.existsSync(tmpFile)) {
|
||||
fs.unlinkSync(tmpFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe.each(['local', 'temporal'] as const)(
|
||||
'Workflow E2E - transcodeVideoWorkflow (executor: %s)',
|
||||
(mode) => {
|
||||
@@ -221,5 +267,915 @@ describe.each(['local', 'temporal'] as const)(
|
||||
// Audio proxy key should end with -audio-proxy.mp4
|
||||
expect(mediaInfo.videoTranscodes[0].key).toContain('-audio-proxy.mp4')
|
||||
}, 50000)
|
||||
|
||||
it('should run transcodeMedia workflow with HLS enabled and serve playlists for version stacks and symlinks', async () => {
|
||||
// 1. Seed Database
|
||||
const team = await prisma.team.create({
|
||||
data: {
|
||||
name: 'E2E HLS Video Transcode Team',
|
||||
settings: {
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hlsEnabled: true,
|
||||
hlsResolutions: ['480p'],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E HLS Video Transcode Project', teamId: team.id },
|
||||
})
|
||||
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: {
|
||||
key: 'projects/e2e/video-hls.mp4',
|
||||
},
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video-hls.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
// 2. Seed S3 Storage from Fixture (small-480p.mp4)
|
||||
const mp4Path = path.join(fixturesDir, 'small-480p.mp4')
|
||||
const mp4Buffer = fs.readFileSync(mp4Path)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/video-hls.mp4',
|
||||
mp4Buffer,
|
||||
mp4Buffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
|
||||
// 3. Create Workflow Task
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hlsEnabled: true,
|
||||
hlsResolutions: ['480p'],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
// 4. Wait for workflow to complete
|
||||
console.log(
|
||||
`Submitted E2E HLS Transcode Workflow Task. ID: ${task.id}. Awaiting completion...`,
|
||||
)
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
// 5. Verification of HLS generation
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as PrismaJson.MediaInfo
|
||||
expect(mediaInfo.isHls).toBe(true)
|
||||
expect(mediaInfo.hls).toBeDefined()
|
||||
expect(mediaInfo.hls?.key).toBe('projects/e2e/hls/master.m3u8')
|
||||
expect(mediaInfo.hls?.resolutions).toBeDefined()
|
||||
expect(mediaInfo.hls?.resolutions?.length).toBeGreaterThan(0)
|
||||
expect(mediaInfo.hls?.resolutions?.[0]?.resolution).toBe('480p')
|
||||
|
||||
// Verify master playlist in S3
|
||||
const masterObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/hls/master.m3u8',
|
||||
)
|
||||
const masterPlaylist = masterObj.buffer.toString('utf-8')
|
||||
expect(masterPlaylist).toContain('#EXTM3U')
|
||||
expect(masterPlaylist).toContain('480p/index.m3u8')
|
||||
|
||||
// Verify variant playlist in S3
|
||||
const variantObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/hls/480p/index.m3u8',
|
||||
)
|
||||
expect(variantObj.buffer.toString('utf-8')).toContain('#EXTM3U')
|
||||
|
||||
// 6. Test Version Stack & Symlink Resolution
|
||||
const stack = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video-hls-stack',
|
||||
type: AssetType.version_stack,
|
||||
status: AssetStatus.processed,
|
||||
projectId: project.id,
|
||||
},
|
||||
})
|
||||
|
||||
await prisma.asset.update({
|
||||
where: { id: asset.id },
|
||||
data: {
|
||||
parentId: stack.id,
|
||||
sortIndex: 'a',
|
||||
},
|
||||
})
|
||||
|
||||
const symlink = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video-hls-symlink',
|
||||
type: AssetType.symlink,
|
||||
status: AssetStatus.processed,
|
||||
projectId: project.id,
|
||||
targetId: stack.id,
|
||||
},
|
||||
})
|
||||
|
||||
// Calling getHlsMasterPlaylist with stack ID
|
||||
const stackMaster = await assetService.getHlsMasterPlaylist({ assetId: stack.id })
|
||||
expect(stackMaster).toContain('#EXTM3U')
|
||||
expect(stackMaster).toContain('480p/index.m3u8')
|
||||
|
||||
// Calling getHlsMasterPlaylist with symlink ID
|
||||
const symlinkMaster = await assetService.getHlsMasterPlaylist({ assetId: symlink.id })
|
||||
expect(symlinkMaster).toContain('#EXTM3U')
|
||||
expect(symlinkMaster).toContain('480p/index.m3u8')
|
||||
|
||||
// Calling getHlsVariantPlaylist with symlink ID
|
||||
const symlinkVariant = await assetService.getHlsVariantPlaylist({
|
||||
assetId: symlink.id,
|
||||
resolution: '480p',
|
||||
})
|
||||
expect(symlinkVariant).toContain('#EXTM3U')
|
||||
}, 60000)
|
||||
|
||||
it('Case 1: should ignore attached picture cover art (Red) and select primary video stream (Green)', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Cover Art Video Team' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Cover Art Video Project', teamId: team.id },
|
||||
})
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'projects/e2e/case1/video.mp4' },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-case1-'))
|
||||
const videoPath = path.join(tmpDir, 'case1.mp4')
|
||||
try {
|
||||
await execFileAsync('ffmpeg', [
|
||||
'-y',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=green:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=red:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'sine=f=1000:d=2',
|
||||
'-map',
|
||||
'0:v',
|
||||
'-map',
|
||||
'1:v',
|
||||
'-map',
|
||||
'2:a',
|
||||
'-c:v:0',
|
||||
'libx264',
|
||||
'-pix_fmt:v:0',
|
||||
'yuv420p',
|
||||
'-c:v:1',
|
||||
'mjpeg',
|
||||
'-pix_fmt:v:1',
|
||||
'yuvj420p',
|
||||
'-c:a',
|
||||
'aac',
|
||||
'-disposition:v:1',
|
||||
'attached_pic',
|
||||
videoPath,
|
||||
])
|
||||
const mp4Buffer = fs.readFileSync(videoPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/case1/video.mp4',
|
||||
mp4Buffer,
|
||||
mp4Buffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
sprite: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType: string
|
||||
metadata: { videoStreamIndex: number }
|
||||
poster: { key: string }
|
||||
sprite: { key: string }
|
||||
videoTranscodes: { key: string }[]
|
||||
}
|
||||
expect(mediaInfo.proxyType).toBe('video')
|
||||
expect(mediaInfo.metadata.videoStreamIndex).toBe(0)
|
||||
|
||||
// Verify poster is Green (not Red attached pic)
|
||||
expect(mediaInfo.poster?.key).toBeDefined()
|
||||
const posterObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.poster.key,
|
||||
)
|
||||
const posterColor = await sampleFirstFrameRgb(posterObj.buffer, 'webp')
|
||||
expect(posterColor.g).toBeGreaterThan(100)
|
||||
expect(posterColor.r).toBeLessThan(50)
|
||||
expect(posterColor.b).toBeLessThan(50)
|
||||
|
||||
// Verify MP4 proxy is Green
|
||||
expect(mediaInfo.videoTranscodes.length).toBeGreaterThan(0)
|
||||
const videoObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.videoTranscodes[0].key,
|
||||
)
|
||||
const videoColor = await sampleFirstFrameRgb(videoObj.buffer, 'mp4')
|
||||
expect(videoColor.g).toBeGreaterThan(100)
|
||||
expect(videoColor.r).toBeLessThan(50)
|
||||
expect(videoColor.b).toBeLessThan(50)
|
||||
|
||||
// Verify sprite sheet exists
|
||||
expect(mediaInfo.sprite?.key).toBeDefined()
|
||||
await s3Service.headObject('shumai-e2e-test-bucket-transcode', mediaInfo.sprite.key)
|
||||
}, 60000)
|
||||
|
||||
it('Case 2: should select higher bitrate stream (Blue) when both streams have default flag', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Bitrate Comparison Team' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Bitrate Comparison Project', teamId: team.id },
|
||||
})
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'projects/e2e/case2/video.mp4' },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-case2-'))
|
||||
const videoPath = path.join(tmpDir, 'case2.mp4')
|
||||
try {
|
||||
await execFileAsync('ffmpeg', [
|
||||
'-y',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=red:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=blue:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'sine=f=1000:d=2',
|
||||
'-map',
|
||||
'0:v',
|
||||
'-map',
|
||||
'1:v',
|
||||
'-map',
|
||||
'2:a',
|
||||
'-c:v:0',
|
||||
'libx264',
|
||||
'-b:v:0',
|
||||
'200k',
|
||||
'-minrate:v:0',
|
||||
'200k',
|
||||
'-maxrate:v:0',
|
||||
'200k',
|
||||
'-bufsize:v:0',
|
||||
'200k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:0',
|
||||
'default',
|
||||
'-c:v:1',
|
||||
'libx264',
|
||||
'-b:v:1',
|
||||
'2000k',
|
||||
'-minrate:v:1',
|
||||
'2000k',
|
||||
'-maxrate:v:1',
|
||||
'2000k',
|
||||
'-bufsize:v:1',
|
||||
'2000k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:1',
|
||||
'default',
|
||||
'-c:a',
|
||||
'aac',
|
||||
videoPath,
|
||||
])
|
||||
const mp4Buffer = fs.readFileSync(videoPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/case2/video.mp4',
|
||||
mp4Buffer,
|
||||
mp4Buffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType: string
|
||||
metadata: { videoStreamIndex: number }
|
||||
poster: { key: string }
|
||||
videoTranscodes: { key: string }[]
|
||||
}
|
||||
expect(mediaInfo.proxyType).toBe('video')
|
||||
// Stream 1 (Blue, 2000k) should be selected over Stream 0 (Red, 200k)
|
||||
expect(mediaInfo.metadata.videoStreamIndex).toBe(1)
|
||||
|
||||
const posterObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.poster.key,
|
||||
)
|
||||
const posterColor = await sampleFirstFrameRgb(posterObj.buffer, 'webp')
|
||||
expect(posterColor.b).toBeGreaterThan(100)
|
||||
expect(posterColor.r).toBeLessThan(50)
|
||||
expect(posterColor.g).toBeLessThan(50)
|
||||
|
||||
const videoObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.videoTranscodes[0].key,
|
||||
)
|
||||
const videoColor = await sampleFirstFrameRgb(videoObj.buffer, 'mp4')
|
||||
expect(videoColor.b).toBeGreaterThan(100)
|
||||
expect(videoColor.r).toBeLessThan(50)
|
||||
expect(videoColor.g).toBeLessThan(50)
|
||||
}, 60000)
|
||||
|
||||
it('Case 3: should select stream with default flag (Yellow) over higher bitrate stream without default flag (Blue)', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Default Flag Team' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Default Flag Project', teamId: team.id },
|
||||
})
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'projects/e2e/case3/video.mp4' },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-case3-'))
|
||||
const videoPath = path.join(tmpDir, 'case3.mp4')
|
||||
try {
|
||||
await execFileAsync('ffmpeg', [
|
||||
'-y',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=yellow:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=blue:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'sine=f=1000:d=2',
|
||||
'-map',
|
||||
'0:v',
|
||||
'-map',
|
||||
'1:v',
|
||||
'-map',
|
||||
'2:a',
|
||||
'-c:v:0',
|
||||
'libx264',
|
||||
'-b:v:0',
|
||||
'200k',
|
||||
'-minrate:v:0',
|
||||
'200k',
|
||||
'-maxrate:v:0',
|
||||
'200k',
|
||||
'-bufsize:v:0',
|
||||
'200k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:0',
|
||||
'default',
|
||||
'-c:v:1',
|
||||
'libx264',
|
||||
'-b:v:1',
|
||||
'2000k',
|
||||
'-minrate:v:1',
|
||||
'2000k',
|
||||
'-maxrate:v:1',
|
||||
'2000k',
|
||||
'-bufsize:v:1',
|
||||
'2000k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:1',
|
||||
'0',
|
||||
'-c:a',
|
||||
'aac',
|
||||
videoPath,
|
||||
])
|
||||
const mp4Buffer = fs.readFileSync(videoPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/case3/video.mp4',
|
||||
mp4Buffer,
|
||||
mp4Buffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType: string
|
||||
metadata: { videoStreamIndex: number }
|
||||
poster: { key: string }
|
||||
videoTranscodes: { key: string }[]
|
||||
}
|
||||
expect(mediaInfo.proxyType).toBe('video')
|
||||
// Stream 0 (Yellow, default: 1) should win over Stream 1 (Blue, 10x higher bitrate but default: 0)
|
||||
expect(mediaInfo.metadata.videoStreamIndex).toBe(0)
|
||||
|
||||
const posterObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.poster.key,
|
||||
)
|
||||
const posterColor = await sampleFirstFrameRgb(posterObj.buffer, 'webp')
|
||||
expect(posterColor.r).toBeGreaterThan(100)
|
||||
expect(posterColor.g).toBeGreaterThan(100)
|
||||
expect(posterColor.b).toBeLessThan(50)
|
||||
|
||||
const videoObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.videoTranscodes[0].key,
|
||||
)
|
||||
const videoColor = await sampleFirstFrameRgb(videoObj.buffer, 'mp4')
|
||||
expect(videoColor.r).toBeGreaterThan(100)
|
||||
expect(videoColor.g).toBeGreaterThan(100)
|
||||
expect(videoColor.b).toBeLessThan(50)
|
||||
}, 60000)
|
||||
|
||||
it('Case 4: should handle audio-only MP4 with cover art by downgrading to audio proxy (catches audio bug)', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Audio Cover Art Team' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Audio Cover Art Project', teamId: team.id },
|
||||
})
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'projects/e2e/case4/audio-cover.mp4' },
|
||||
})
|
||||
// Uploaded as video/mp4 because of .mp4 container, even though it only has audio + cover art
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'audio-cover.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-case4-'))
|
||||
const videoPath = path.join(tmpDir, 'case4.mp4')
|
||||
try {
|
||||
await execFileAsync('ffmpeg', [
|
||||
'-y',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'sine=f=1000:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=magenta:s=320x240:d=2',
|
||||
'-map',
|
||||
'0:a',
|
||||
'-map',
|
||||
'1:v',
|
||||
'-c:a',
|
||||
'aac',
|
||||
'-c:v',
|
||||
'mjpeg',
|
||||
'-pix_fmt:v:0',
|
||||
'yuvj420p',
|
||||
'-disposition:v:0',
|
||||
'attached_pic',
|
||||
videoPath,
|
||||
])
|
||||
const mp4Buffer = fs.readFileSync(videoPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/case4/audio-cover.mp4',
|
||||
mp4Buffer,
|
||||
mp4Buffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
// Spec requested poster, sprite, videoStrategy as video upload would
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
poster: true,
|
||||
sprite: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
// Must complete without error (previously failed trying to generate poster/sprite for audio)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType: string
|
||||
poster?: unknown
|
||||
sprite?: unknown
|
||||
videoTranscodes: { key: string }[]
|
||||
}
|
||||
expect(mediaInfo.proxyType).toBe('audio')
|
||||
expect(mediaInfo.poster).toBeUndefined()
|
||||
expect(mediaInfo.sprite).toBeUndefined()
|
||||
expect(mediaInfo.videoTranscodes.length).toBeGreaterThan(0)
|
||||
expect(mediaInfo.videoTranscodes[0].key).toContain('-audio-proxy.mp4')
|
||||
await s3Service.headObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.videoTranscodes[0].key,
|
||||
)
|
||||
}, 60000)
|
||||
|
||||
it('Case 5: should rank 3 video streams with HLS enabled and select highest bitrate stream (Blue)', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: {
|
||||
name: 'E2E Multi Stream HLS Team',
|
||||
settings: {
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hlsEnabled: true,
|
||||
hlsResolutions: ['480p'],
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Multi Stream HLS Project', teamId: team.id },
|
||||
})
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'projects/e2e/case5/video.mp4' },
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'video.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'e2e-case5-'))
|
||||
const videoPath = path.join(tmpDir, 'case5.mp4')
|
||||
try {
|
||||
await execFileAsync('ffmpeg', [
|
||||
'-y',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=red:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=green:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'color=c=blue:s=320x240:d=2',
|
||||
'-f',
|
||||
'lavfi',
|
||||
'-i',
|
||||
'sine=f=1000:d=2',
|
||||
'-map',
|
||||
'0:v',
|
||||
'-map',
|
||||
'1:v',
|
||||
'-map',
|
||||
'2:v',
|
||||
'-map',
|
||||
'3:a',
|
||||
'-c:v:0',
|
||||
'libx264',
|
||||
'-b:v:0',
|
||||
'100k',
|
||||
'-minrate:v:0',
|
||||
'100k',
|
||||
'-maxrate:v:0',
|
||||
'100k',
|
||||
'-bufsize:v:0',
|
||||
'100k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:0',
|
||||
'default',
|
||||
'-c:v:1',
|
||||
'libx264',
|
||||
'-b:v:1',
|
||||
'500k',
|
||||
'-minrate:v:1',
|
||||
'500k',
|
||||
'-maxrate:v:1',
|
||||
'500k',
|
||||
'-bufsize:v:1',
|
||||
'500k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:1',
|
||||
'default',
|
||||
'-c:v:2',
|
||||
'libx264',
|
||||
'-b:v:2',
|
||||
'1500k',
|
||||
'-minrate:v:2',
|
||||
'1500k',
|
||||
'-maxrate:v:2',
|
||||
'1500k',
|
||||
'-bufsize:v:2',
|
||||
'1500k',
|
||||
'-nal-hrd',
|
||||
'cbr',
|
||||
'-disposition:v:2',
|
||||
'default',
|
||||
'-c:a',
|
||||
'aac',
|
||||
videoPath,
|
||||
])
|
||||
const mp4Buffer = fs.readFileSync(videoPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/case5/video.mp4',
|
||||
mp4Buffer,
|
||||
mp4Buffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
} finally {
|
||||
fs.rmSync(tmpDir, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
hlsEnabled: true,
|
||||
hlsResolutions: ['480p'],
|
||||
poster: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const completedTask = await workflowService.executeWait(task, 45000)
|
||||
expect(completedTask.status).toBe('completed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.processed)
|
||||
|
||||
const mediaInfo = updatedAsset?.media as unknown as {
|
||||
proxyType: string
|
||||
metadata: { videoStreamIndex: number }
|
||||
poster: { key: string }
|
||||
isHls: boolean
|
||||
hls: { key: string; resolutions: { resolution: string }[] }
|
||||
}
|
||||
expect(mediaInfo.proxyType).toBe('video')
|
||||
// Stream 2 (Blue, 1500k) should be selected
|
||||
expect(mediaInfo.metadata.videoStreamIndex).toBe(2)
|
||||
|
||||
const posterObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.poster.key,
|
||||
)
|
||||
const posterColor = await sampleFirstFrameRgb(posterObj.buffer, 'webp')
|
||||
expect(posterColor.b).toBeGreaterThan(100)
|
||||
expect(posterColor.r).toBeLessThan(50)
|
||||
expect(posterColor.g).toBeLessThan(50)
|
||||
|
||||
expect(mediaInfo.isHls).toBe(true)
|
||||
const masterObj = await s3Service.getObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
mediaInfo.hls.key,
|
||||
)
|
||||
expect(masterObj.buffer.toString('utf-8')).toContain('480p/index.m3u8')
|
||||
}, 60000)
|
||||
|
||||
it('should transition both task and asset to failed status with media.error when transcoding fails', async () => {
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Failed Transcode Team' },
|
||||
})
|
||||
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'E2E Failed Transcode Project', teamId: team.id },
|
||||
})
|
||||
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'projects/e2e/corrupt-video.mp4' },
|
||||
})
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'corrupt-video.mp4',
|
||||
type: 'file',
|
||||
status: 'uploaded',
|
||||
mediaType: 'video/mp4',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
},
|
||||
})
|
||||
|
||||
const corruptBuffer = Buffer.from('not a valid mp4 media stream at all')
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-transcode',
|
||||
'projects/e2e/corrupt-video.mp4',
|
||||
corruptBuffer,
|
||||
corruptBuffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
|
||||
const task = await prisma.workflowTask.create({
|
||||
data: {
|
||||
type: 'transcode_video',
|
||||
status: 'pending',
|
||||
assetId: asset.id,
|
||||
projectId: project.id,
|
||||
teamId: team.id,
|
||||
payload: {
|
||||
projectId: project.id,
|
||||
transcode: {
|
||||
videoStrategy: 'best_match',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await expect(workflowService.executeWait(task, 45000)).rejects.toThrow()
|
||||
|
||||
const failedTask = await prisma.workflowTask.findUnique({
|
||||
where: { id: task.id },
|
||||
})
|
||||
expect(failedTask?.status).toBe('failed')
|
||||
|
||||
const updatedAsset = await prisma.asset.findUnique({
|
||||
where: { id: asset.id },
|
||||
})
|
||||
expect(updatedAsset?.status).toBe(AssetStatus.failed)
|
||||
|
||||
const media = updatedAsset?.media as PrismaJson.MediaInfo
|
||||
expect(media?.error).toBeDefined()
|
||||
expect(media?.error?.length).toBeGreaterThan(0)
|
||||
}, 45000)
|
||||
},
|
||||
)
|
||||
|
||||
@@ -312,6 +312,128 @@ describe.each(['local', 'temporal'] as const)(
|
||||
expect(mediaInfo?.videoTranscodes?.[0].resolution).toBe('360p')
|
||||
})
|
||||
|
||||
it('should generate watermark proxy for a 3d asset from turntable video and update sharelink status to ready', async () => {
|
||||
// 1. Seed Database
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'E2E Watermark 3D Team' },
|
||||
})
|
||||
const projectFolder = await prisma.asset.create({
|
||||
data: { name: 'root', type: 'root', status: 'processed' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: {
|
||||
name: 'E2E Watermark 3D Project',
|
||||
teamId: team.id,
|
||||
rootFolderId: projectFolder.id,
|
||||
},
|
||||
})
|
||||
|
||||
const storageKey = await prisma.storageKey.create({
|
||||
data: { key: 'files/e2e-watermark-3d/model.glb' },
|
||||
})
|
||||
|
||||
const turntableKey = 'files/e2e-watermark-3d/turntable.mp4'
|
||||
const videoPath = path.join(fixturesDir, 'small.mp4')
|
||||
const videoBuffer = fs.readFileSync(videoPath)
|
||||
await s3Service.putObject(
|
||||
'shumai-e2e-test-bucket-watermark',
|
||||
turntableKey,
|
||||
videoBuffer,
|
||||
videoBuffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'model.glb',
|
||||
type: 'file',
|
||||
mediaType: 'model/gltf-binary',
|
||||
status: 'processed',
|
||||
projectId: project.id,
|
||||
storageKeyId: storageKey.id,
|
||||
media: {
|
||||
duration: 1,
|
||||
filesize: videoBuffer.length,
|
||||
frames: 30,
|
||||
proxyType: '3d',
|
||||
imageTranscodes: [],
|
||||
videoTranscodes: [{ key: turntableKey, width: 640, height: 360, resolution: '360p' }],
|
||||
videoPreview: { key: turntableKey, width: 640, height: 360, resolution: '360p' },
|
||||
poster: { key: 'files/e2e-watermark-3d/poster.webp' },
|
||||
finishedAt: new Date().toISOString(),
|
||||
metadata: {
|
||||
originalWidth: 640,
|
||||
originalHeight: 360,
|
||||
duration: 1,
|
||||
bitRate: 0,
|
||||
frameRate: 30,
|
||||
totalFrames: 30,
|
||||
startTimecode: '00:00:00:00',
|
||||
hasAudio: false,
|
||||
format: {},
|
||||
},
|
||||
original: {
|
||||
key: storageKey.key,
|
||||
filesizeInBytes: 100,
|
||||
codec: '',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
const shareLink = await shareService.createShareLink(project.id, {
|
||||
name: 'Public Watermarked 3D Share',
|
||||
})
|
||||
await shareService.addAssetToShare(shareLink.id, { assetIds: [asset.id] })
|
||||
|
||||
const watermarkConfig: WatermarkConfigSpec = {
|
||||
blocks: [
|
||||
{
|
||||
id: 'b1',
|
||||
type: 'text',
|
||||
x: 0.5,
|
||||
y: 0.5,
|
||||
opacity: 0.5,
|
||||
rotation: 0,
|
||||
text: 'CONFIDENTIAL 3D',
|
||||
size: 0.2,
|
||||
color: '#FF0000',
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const updatedShare = await watermarkService.updateShareLinkWatermark(
|
||||
shareLink.id,
|
||||
true,
|
||||
watermarkConfig,
|
||||
)
|
||||
expect(updatedShare.watermarkStatus).toBe('processing')
|
||||
|
||||
let share = await shareService.getShareLink(shareLink.id)
|
||||
const startTime = Date.now()
|
||||
while (share.watermarkStatus === 'processing' && Date.now() - startTime < 60000) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 500))
|
||||
share = await shareService.getShareLink(shareLink.id)
|
||||
}
|
||||
expect(share.watermarkStatus).toBe('ready')
|
||||
|
||||
const wf = await prisma.watermarkFile.findUnique({
|
||||
where: {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
assetId_watermarkConfigId: {
|
||||
assetId: asset.id,
|
||||
watermarkConfigId: updatedShare.watermarkConfigId!,
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(wf).toBeDefined()
|
||||
expect(wf?.status).toBe(WatermarkFileStatus.completed)
|
||||
const media = wf?.media as PrismaJson.MediaInfo
|
||||
expect(media.proxyType).toBe('3d')
|
||||
expect(media.videoTranscodes?.length).toBeGreaterThan(0)
|
||||
expect(media.videoPreview?.key).toBe(media.videoTranscodes?.[0]?.key)
|
||||
})
|
||||
|
||||
it('should watermark a newly added asset after the sharelink is already ready', async () => {
|
||||
// 1. Seed Database
|
||||
const team = await prisma.team.create({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/tableprinter",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode",
|
||||
"version": "0.4.9",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
|
||||
@@ -0,0 +1,355 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import {
|
||||
render3dModelActivity,
|
||||
start3dRenderActivity,
|
||||
waitFor3dVideoRenderActivity,
|
||||
generate3dSpriteActivity,
|
||||
generate3dViewsActivity,
|
||||
} from './transcode'
|
||||
import { turntableService } from '@shumai/core/src/turntable/turntable'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcodeService } from '@shumai/core/src/transcode/transcode'
|
||||
import * as fs from 'fs'
|
||||
|
||||
vi.mock('@shumai/core/src/turntable/turntable', () => ({
|
||||
turntableService: {
|
||||
uploadFile: vi.fn(),
|
||||
startRender: vi.fn(),
|
||||
getTaskStatus: vi.fn(),
|
||||
downloadFile: vi.fn(),
|
||||
deleteTask: vi.fn(),
|
||||
deleteFile: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@shumai/core/src/s3/s3', () => ({
|
||||
s3Service: {
|
||||
putObject: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@shumai/core/src/transcode/transcode', () => ({
|
||||
transcodeService: {
|
||||
convertImageToWebp: vi.fn(),
|
||||
generate3dSprite: vi.fn(),
|
||||
generate3dViews: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@shumai/core/src/asset/asset', () => ({
|
||||
assetService: {
|
||||
isAssetPurging: vi.fn().mockResolvedValue(false),
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('fs', async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import('fs')>()
|
||||
return {
|
||||
...actual,
|
||||
readFileSync: vi.fn(),
|
||||
writeFileSync: vi.fn(),
|
||||
}
|
||||
})
|
||||
|
||||
describe('3D Transcode Activities', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
vi.mocked(fs.readFileSync).mockReturnValue(Buffer.from('mock-bytes'))
|
||||
vi.mocked(transcodeService.convertImageToWebp).mockResolvedValue(Buffer.from('webp-bytes'))
|
||||
vi.mocked(transcodeService.generate3dSprite).mockResolvedValue()
|
||||
vi.mocked(transcodeService.generate3dViews).mockResolvedValue()
|
||||
vi.mocked(s3Service.putObject).mockResolvedValue({} as never)
|
||||
vi.mocked(turntableService.deleteTask).mockResolvedValue(true)
|
||||
})
|
||||
|
||||
describe('start3dRenderActivity', () => {
|
||||
it('uploads file, starts render, immediately downloads and uploads poster to S3', async () => {
|
||||
vi.mocked(turntableService.uploadFile).mockResolvedValue({
|
||||
id: 'f_input',
|
||||
name: 'model.glb',
|
||||
size: 1024,
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.startRender).mockResolvedValue({
|
||||
taskId: 'task_render_1',
|
||||
status: 'queued',
|
||||
poster: {
|
||||
fileId: 'f_poster',
|
||||
contentType: 'image/png',
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
size: 5000,
|
||||
},
|
||||
metadata: { format: 'glb', vertices: 120 },
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.downloadFile).mockResolvedValue(Buffer.from('poster-raw-data'))
|
||||
|
||||
const res = await start3dRenderActivity({
|
||||
taskId: 'wf-task-1',
|
||||
teamId: 'team-1',
|
||||
assetId: 'asset-1',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
filePath: '/tmp/model.glb',
|
||||
filename: 'model.glb',
|
||||
targetPosterKey: 'files/asset-1/poster.webp',
|
||||
})
|
||||
|
||||
expect(turntableService.uploadFile).toHaveBeenCalledWith(
|
||||
'/tmp/model.glb',
|
||||
'model.glb',
|
||||
'team-1',
|
||||
)
|
||||
expect(turntableService.startRender).toHaveBeenCalledWith('f_input', {}, 'team-1')
|
||||
expect(turntableService.downloadFile).toHaveBeenCalledWith('f_poster', undefined, 'team-1')
|
||||
expect(transcodeService.convertImageToWebp).toHaveBeenCalledWith(
|
||||
Buffer.from('poster-raw-data'),
|
||||
)
|
||||
expect(s3Service.putObject).toHaveBeenCalledWith(
|
||||
'shumai',
|
||||
'files/asset-1/poster.webp',
|
||||
Buffer.from('webp-bytes'),
|
||||
Buffer.from('webp-bytes').length,
|
||||
'image/webp',
|
||||
)
|
||||
|
||||
expect(res.renderTaskId).toBe('task_render_1')
|
||||
expect(res.posterFilePath).toBe('/tmp/poster.webp')
|
||||
expect(res.posterWidth).toBe(1080)
|
||||
expect(res.posterHeight).toBe(1080)
|
||||
expect(res.modelMetadata).toEqual({ format: 'glb', vertices: 120 })
|
||||
})
|
||||
|
||||
it('throws ApplicationFailure when poster file ID is missing', async () => {
|
||||
vi.mocked(turntableService.uploadFile).mockResolvedValue({
|
||||
id: 'f_input',
|
||||
name: 'model.glb',
|
||||
size: 1024,
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.startRender).mockResolvedValue({
|
||||
taskId: 'task_render_1',
|
||||
status: 'queued',
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
poster: undefined as any,
|
||||
})
|
||||
|
||||
await expect(
|
||||
start3dRenderActivity({
|
||||
taskId: 'wf-task-1',
|
||||
teamId: 'team-1',
|
||||
assetId: 'asset-1',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
filePath: '/tmp/model.glb',
|
||||
filename: 'model.glb',
|
||||
targetPosterKey: 'files/asset-1/poster.webp',
|
||||
}),
|
||||
).rejects.toThrow('Poster file ID missing from turntable render result')
|
||||
|
||||
expect(turntableService.deleteTask).toHaveBeenCalledWith('task_render_1', 'team-1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('waitFor3dVideoRenderActivity', () => {
|
||||
it('polls until complete, downloads video, uploads to S3, and cleans up task', async () => {
|
||||
vi.mocked(turntableService.getTaskStatus).mockResolvedValue({
|
||||
taskId: 'task_render_1',
|
||||
status: 'completed',
|
||||
createdAt: new Date().toISOString(),
|
||||
video: {
|
||||
fileId: 'f_video',
|
||||
contentType: 'video/mp4',
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
size: 1000,
|
||||
},
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.downloadFile).mockResolvedValue(Buffer.from('video-data'))
|
||||
|
||||
const res = await waitFor3dVideoRenderActivity({
|
||||
taskId: 'wf-task-1',
|
||||
teamId: 'team-1',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
renderTaskId: 'task_render_1',
|
||||
targetVideoKey: 'files/asset-1/turntable.mp4',
|
||||
tmpDir: '/tmp',
|
||||
})
|
||||
|
||||
expect(turntableService.getTaskStatus).toHaveBeenCalledWith('task_render_1', 'team-1')
|
||||
expect(turntableService.downloadFile).toHaveBeenCalledWith(
|
||||
'f_video',
|
||||
'/tmp/turntable.mp4',
|
||||
'team-1',
|
||||
)
|
||||
expect(s3Service.putObject).toHaveBeenCalledWith(
|
||||
'shumai',
|
||||
'files/asset-1/turntable.mp4',
|
||||
Buffer.from('video-data'),
|
||||
Buffer.from('video-data').length,
|
||||
'video/mp4',
|
||||
)
|
||||
expect(turntableService.deleteTask).toHaveBeenCalledWith('task_render_1', 'team-1')
|
||||
expect(res.videoFilePath).toBe('/tmp/turntable.mp4')
|
||||
})
|
||||
|
||||
it('throws ApplicationFailure when render fails on turntable-renderer', async () => {
|
||||
vi.mocked(turntableService.getTaskStatus).mockResolvedValue({
|
||||
taskId: 'task_render_2',
|
||||
status: 'failed',
|
||||
createdAt: new Date().toISOString(),
|
||||
error: {
|
||||
code: 'render_failed',
|
||||
message: 'Blender failed to import model',
|
||||
},
|
||||
})
|
||||
|
||||
await expect(
|
||||
waitFor3dVideoRenderActivity({
|
||||
taskId: 'wf-task-2',
|
||||
teamId: 'team-1',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
renderTaskId: 'task_render_2',
|
||||
targetVideoKey: 'files/asset-1/turntable.mp4',
|
||||
tmpDir: '/tmp',
|
||||
}),
|
||||
).rejects.toThrow('Blender failed to import model')
|
||||
|
||||
expect(turntableService.deleteTask).toHaveBeenCalledWith('task_render_2', 'team-1')
|
||||
})
|
||||
})
|
||||
|
||||
describe('render3dModelActivity (legacy wrapper)', () => {
|
||||
it('uploads file, starts render, polls until complete, and uploads to S3', async () => {
|
||||
vi.mocked(turntableService.uploadFile).mockResolvedValue({
|
||||
id: 'f_input',
|
||||
name: 'model.glb',
|
||||
size: 1024,
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.startRender).mockResolvedValue({
|
||||
taskId: 'task_render_1',
|
||||
status: 'queued',
|
||||
poster: {
|
||||
fileId: 'f_poster',
|
||||
contentType: 'image/png',
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
size: 5000,
|
||||
},
|
||||
metadata: { format: 'glb', vertices: 120 },
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.getTaskStatus).mockResolvedValue({
|
||||
taskId: 'task_render_1',
|
||||
status: 'completed',
|
||||
createdAt: new Date().toISOString(),
|
||||
video: {
|
||||
fileId: 'f_video',
|
||||
contentType: 'video/mp4',
|
||||
width: 1080,
|
||||
height: 1080,
|
||||
size: 1000,
|
||||
},
|
||||
})
|
||||
|
||||
vi.mocked(turntableService.downloadFile).mockResolvedValue(Buffer.from('downloaded-data'))
|
||||
|
||||
const res = await render3dModelActivity({
|
||||
taskId: 'wf-task-1',
|
||||
teamId: 'team-1',
|
||||
assetId: 'asset-1',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
filePath: '/tmp/model.glb',
|
||||
filename: 'model.glb',
|
||||
targetVideoKey: 'files/asset-1/turntable.mp4',
|
||||
targetPosterKey: 'files/asset-1/poster.webp',
|
||||
})
|
||||
|
||||
expect(turntableService.uploadFile).toHaveBeenCalledWith(
|
||||
'/tmp/model.glb',
|
||||
'model.glb',
|
||||
'team-1',
|
||||
)
|
||||
expect(turntableService.startRender).toHaveBeenCalledWith('f_input', {}, 'team-1')
|
||||
expect(turntableService.getTaskStatus).toHaveBeenCalledWith('task_render_1', 'team-1')
|
||||
expect(turntableService.downloadFile).toHaveBeenCalledWith(
|
||||
'f_video',
|
||||
'/tmp/turntable.mp4',
|
||||
'team-1',
|
||||
)
|
||||
expect(turntableService.downloadFile).toHaveBeenCalledWith('f_poster', undefined, 'team-1')
|
||||
expect(transcodeService.convertImageToWebp).toHaveBeenCalledWith(expect.any(Buffer))
|
||||
|
||||
expect(s3Service.putObject).toHaveBeenCalledWith(
|
||||
'shumai',
|
||||
'files/asset-1/turntable.mp4',
|
||||
expect.any(Buffer),
|
||||
expect.any(Number),
|
||||
'video/mp4',
|
||||
)
|
||||
expect(s3Service.putObject).toHaveBeenCalledWith(
|
||||
'shumai',
|
||||
'files/asset-1/poster.webp',
|
||||
expect.any(Buffer),
|
||||
expect.any(Number),
|
||||
'image/webp',
|
||||
)
|
||||
|
||||
expect(turntableService.deleteTask).toHaveBeenCalledWith('task_render_1', 'team-1')
|
||||
expect(res.modelMetadata).toEqual({ format: 'glb', vertices: 120 })
|
||||
expect(res.videoFilePath).toBe('/tmp/turntable.mp4')
|
||||
expect(res.posterFilePath).toBe('/tmp/poster.webp')
|
||||
})
|
||||
})
|
||||
|
||||
describe('generate3dSpriteActivity', () => {
|
||||
it('generates 3d sprite sheet and uploads to S3', async () => {
|
||||
const res = await generate3dSpriteActivity({
|
||||
taskId: 'wf-task-3',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
videoFilePath: '/tmp/turntable.mp4',
|
||||
spriteKey: 'files/asset-1/sprite.webp',
|
||||
})
|
||||
|
||||
expect(transcodeService.generate3dSprite).toHaveBeenCalledWith(
|
||||
'/tmp/turntable.mp4',
|
||||
'/tmp/sprite.webp',
|
||||
undefined,
|
||||
)
|
||||
expect(s3Service.putObject).toHaveBeenCalledWith(
|
||||
'shumai',
|
||||
'files/asset-1/sprite.webp',
|
||||
expect.any(Buffer),
|
||||
expect.any(Number),
|
||||
'image/webp',
|
||||
)
|
||||
expect(res.spriteKey).toBe('files/asset-1/sprite.webp')
|
||||
})
|
||||
})
|
||||
|
||||
describe('generate3dViewsActivity', () => {
|
||||
it('generates 3d 4-views composite image and uploads to S3', async () => {
|
||||
const res = await generate3dViewsActivity({
|
||||
taskId: 'wf-task-4',
|
||||
assetKey: 'files/asset-1/model.glb',
|
||||
videoFilePath: '/tmp/turntable.mp4',
|
||||
viewsKey: 'files/asset-1/views.webp',
|
||||
})
|
||||
|
||||
expect(transcodeService.generate3dViews).toHaveBeenCalledWith(
|
||||
'/tmp/turntable.mp4',
|
||||
'/tmp/views.webp',
|
||||
undefined,
|
||||
)
|
||||
expect(s3Service.putObject).toHaveBeenCalledWith(
|
||||
'shumai',
|
||||
'files/asset-1/views.webp',
|
||||
expect.any(Buffer),
|
||||
expect.any(Number),
|
||||
'image/webp',
|
||||
)
|
||||
expect(res.viewsKey).toBe('files/asset-1/views.webp')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
transcodeVideoChunkActivity,
|
||||
deleteS3ObjectActivity,
|
||||
createAutofillTaskIfEnabledActivity,
|
||||
createEmbeddingTaskIfEnabledActivity,
|
||||
} from './transcode'
|
||||
|
||||
vi.mock('@shumai/core/src/s3/s3', () => ({
|
||||
@@ -217,6 +218,86 @@ describe('Transcode Activities', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('should downgrade proxyType to audio when getVideoInfo throws No video stream found but audio exists', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: { name: 'audio-with-art.mp4', type: 'file', status: 'uploaded' },
|
||||
})
|
||||
|
||||
vi.mocked(transcodeService.getVideoInfo).mockRejectedValueOnce(
|
||||
new Error('No video stream found'),
|
||||
)
|
||||
vi.mocked(transcodeService.getAudioInfo).mockResolvedValueOnce({
|
||||
originalWidth: 0,
|
||||
originalHeight: 0,
|
||||
duration: 42,
|
||||
bitRate: 192000,
|
||||
frameRate: 0,
|
||||
totalFrames: 0,
|
||||
hasAudio: true,
|
||||
audioCodec: 'aac',
|
||||
audioChannels: 2,
|
||||
audioSampleRate: 44100,
|
||||
audioBitDepth: 16,
|
||||
audioStreamIndex: 0,
|
||||
mimeType: 'audio/mp4',
|
||||
})
|
||||
|
||||
const result = await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/audio-with-art.mp4',
|
||||
proxyType: 'video',
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
expect(transcodeService.getVideoInfo).toHaveBeenCalledWith('/tmp/audio-with-art.mp4')
|
||||
expect(transcodeService.getAudioInfo).toHaveBeenCalledWith('/tmp/audio-with-art.mp4')
|
||||
expect(result.proxyType).toBe('audio')
|
||||
expect(result.duration).toBe(42)
|
||||
expect(result.metadata?.hasAudio).toBe(true)
|
||||
expect(result.metadata?.audioStreamIndex).toBe(0)
|
||||
expect(result.metadata?.videoStreamIndex).toBeUndefined()
|
||||
expect(metadataService.updateAssetMetadata).toHaveBeenCalledWith(
|
||||
asset.id,
|
||||
expect.arrayContaining([
|
||||
{ key: 'file_type', value: 'audio' },
|
||||
{ key: 'proxy_type', value: 'audio' },
|
||||
{ key: 'duration', value: 42 },
|
||||
]),
|
||||
true,
|
||||
)
|
||||
})
|
||||
|
||||
it('should populate videoStreamIndex and audioStreamIndex in mediaInfo.metadata', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: { name: 'dual-stream.mp4', type: 'file', status: 'uploaded' },
|
||||
})
|
||||
|
||||
vi.mocked(transcodeService.getVideoInfo).mockResolvedValueOnce({
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 15,
|
||||
bitRate: 2000000,
|
||||
frameRate: 30,
|
||||
totalFrames: 450,
|
||||
hasAudio: true,
|
||||
videoCodec: 'h264',
|
||||
audioCodec: 'aac',
|
||||
videoStreamIndex: 1,
|
||||
audioStreamIndex: 2,
|
||||
mimeType: 'video/mp4',
|
||||
})
|
||||
|
||||
const result = await getMediaInfoActivity({
|
||||
assetId: asset.id,
|
||||
filePath: '/tmp/dual-stream.mp4',
|
||||
proxyType: 'video',
|
||||
mediaType: 'video/mp4',
|
||||
})
|
||||
|
||||
expect(result.metadata?.videoStreamIndex).toBe(1)
|
||||
expect(result.metadata?.audioStreamIndex).toBe(2)
|
||||
})
|
||||
|
||||
it('should call getImageInfo and set file_type to image', async () => {
|
||||
const asset = await prisma.asset.create({
|
||||
data: { name: 'i.png', type: 'file', status: 'uploaded' },
|
||||
@@ -703,6 +784,28 @@ describe('Transcode Activities', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('transcodeVideoActivity forwards streamIndex and audioStreamIndex to transcodeService', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
|
||||
await transcodeVideoActivity({
|
||||
assetKey: 'v.mp4',
|
||||
filePath: '/tmp/v.mp4',
|
||||
videoSpec: { resolution: '720p', width: 1280, height: 720 },
|
||||
duration: 10,
|
||||
originalFps: 30,
|
||||
streamIndex: 2,
|
||||
audioStreamIndex: 1,
|
||||
})
|
||||
|
||||
expect(transcodeService.transcodeVideo).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
inputFile: '/tmp/v.mp4',
|
||||
streamIndex: 2,
|
||||
audioStreamIndex: 1,
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
it('transcodeVideoActivity appends -hdr.mp4 suffix and forwards HDR metadata', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
|
||||
@@ -896,6 +999,24 @@ describe('Transcode Activities', () => {
|
||||
).rejects.toThrowError(/Image transcoding failed/)
|
||||
})
|
||||
|
||||
it('should throw non-retryable ApplicationFailure when transcodeImageActivity fails with dcraw error', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
vi.mocked(transcodeService.transcodeImage).mockRejectedValue(
|
||||
new Error('dcraw_emu failed to decode RAW file'),
|
||||
)
|
||||
|
||||
await expect(
|
||||
transcodeImageActivity({
|
||||
assetKey: 'photo.cr2',
|
||||
filePath: '/tmp/photo.cr2',
|
||||
imageSpec: { width: 800, height: 600, quality: 90, format: 'webp' },
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
message: expect.stringContaining('Image transcoding failed'),
|
||||
nonRetryable: true,
|
||||
})
|
||||
})
|
||||
|
||||
it('should throw non-retryable ApplicationFailure when generateSpriteActivity fails with error', async () => {
|
||||
vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found'))
|
||||
vi.mocked(transcodeService.generateSprite).mockRejectedValue(new Error('FFmpeg failed'))
|
||||
@@ -946,6 +1067,44 @@ describe('Transcode Activities', () => {
|
||||
hdrType: 'pq',
|
||||
colorTransfer: 'smpte2084',
|
||||
},
|
||||
undefined,
|
||||
)
|
||||
})
|
||||
|
||||
it('generateSpriteActivity forwards videoStreamIndex to transcodeService.generateSprite', async () => {
|
||||
vi.mocked(transcodeService.generateSprite).mockImplementation(
|
||||
async (_in, spriteOut, posterOut) => {
|
||||
const fs = await import('fs')
|
||||
fs.writeFileSync(spriteOut, 'fake-sprite')
|
||||
fs.writeFileSync(posterOut, 'fake-poster')
|
||||
},
|
||||
)
|
||||
|
||||
await generateSpriteActivity({
|
||||
assetKey: 'files/asset-1/video.mp4',
|
||||
filePath: '/tmp/video.mp4',
|
||||
mediaInfo: {
|
||||
duration: 10,
|
||||
metadata: {
|
||||
videoStreamIndex: 1,
|
||||
},
|
||||
} as unknown as PrismaJson.MediaInfo,
|
||||
spriteSpec: { key: 'files/asset-1/sprite.webp', frames: 100, tileX: 10, tileY: 10 },
|
||||
posterSpec: { key: 'files/asset-1/poster.webp' },
|
||||
})
|
||||
|
||||
expect(transcodeService.generateSprite).toHaveBeenCalledWith(
|
||||
'/tmp/video.mp4',
|
||||
expect.any(String),
|
||||
expect.any(String),
|
||||
10,
|
||||
undefined,
|
||||
{
|
||||
isHdr: undefined,
|
||||
hdrType: undefined,
|
||||
colorTransfer: undefined,
|
||||
},
|
||||
1,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1559,4 +1718,115 @@ describe('Transcode Activities', () => {
|
||||
expect((task?.payload as any)?.agent?.agentId).toBe(autofillAgent.id)
|
||||
})
|
||||
})
|
||||
|
||||
describe('createEmbeddingTaskIfEnabledActivity', () => {
|
||||
it('should create ai_embedding task for 3D asset with imageTranscodes', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Test User Embedding', email: 'test-embedding-agent@test.com' },
|
||||
})
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Test Team Embedding' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: team.id, userId: user.id, role: 'owner' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'Test Project Embedding', teamId: team.id },
|
||||
})
|
||||
const embeddingAgent = await prisma.agent.create({
|
||||
data: {
|
||||
id: user.id,
|
||||
type: 'embedding',
|
||||
enabled: true,
|
||||
teamId: team.id,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
config: { provider: 'test', model: 'test' } as any,
|
||||
},
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'robot.glb',
|
||||
mediaType: 'model/gltf-binary',
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
projectId: project.id,
|
||||
media: {
|
||||
proxyType: '3d',
|
||||
imageTranscodes: [
|
||||
{
|
||||
key: 'files/asset-1/views.webp',
|
||||
width: 2880,
|
||||
height: 2880,
|
||||
quality: 85,
|
||||
format: 'webp',
|
||||
},
|
||||
],
|
||||
} as unknown as PrismaJson.MediaInfo,
|
||||
},
|
||||
})
|
||||
|
||||
await createEmbeddingTaskIfEnabledActivity({
|
||||
assetId: asset.id,
|
||||
teamId: team.id,
|
||||
projectId: project.id,
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.findFirst({
|
||||
where: { assetId: asset.id, type: 'ai_embedding' },
|
||||
})
|
||||
expect(task).toBeDefined()
|
||||
expect(task?.status).toBe('pending')
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
expect((task?.payload as any)?.agent?.agentId).toBe(embeddingAgent.id)
|
||||
})
|
||||
|
||||
it('should NOT create ai_embedding task for 3D asset without imageTranscodes', async () => {
|
||||
const user = await prisma.user.create({
|
||||
data: { name: 'Test User Embedding 2', email: 'test-embedding-agent-2@test.com' },
|
||||
})
|
||||
const team = await prisma.team.create({
|
||||
data: { name: 'Test Team Embedding 2' },
|
||||
})
|
||||
await prisma.teamMember.create({
|
||||
data: { teamId: team.id, userId: user.id, role: 'owner' },
|
||||
})
|
||||
const project = await prisma.project.create({
|
||||
data: { name: 'Test Project Embedding 2', teamId: team.id },
|
||||
})
|
||||
await prisma.agent.create({
|
||||
data: {
|
||||
id: user.id,
|
||||
type: 'embedding',
|
||||
enabled: true,
|
||||
teamId: team.id,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
config: { provider: 'test', model: 'test' } as any,
|
||||
},
|
||||
})
|
||||
const asset = await prisma.asset.create({
|
||||
data: {
|
||||
name: 'robot.glb',
|
||||
mediaType: 'model/gltf-binary',
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
projectId: project.id,
|
||||
media: {
|
||||
proxyType: '3d',
|
||||
imageTranscodes: [],
|
||||
} as unknown as PrismaJson.MediaInfo,
|
||||
},
|
||||
})
|
||||
|
||||
await createEmbeddingTaskIfEnabledActivity({
|
||||
assetId: asset.id,
|
||||
teamId: team.id,
|
||||
projectId: project.id,
|
||||
})
|
||||
|
||||
const task = await prisma.workflowTask.findFirst({
|
||||
where: { assetId: asset.id, type: 'ai_embedding' },
|
||||
})
|
||||
expect(task).toBeNull()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
import { AssetStatus, prisma, WorkflowTaskType, WorkflowTaskStatus } from '@shumai/db'
|
||||
import { s3Service } from '@shumai/core/src/s3/s3'
|
||||
import { transcodeService, type HdrType } from '@shumai/core/src/transcode/transcode'
|
||||
import {
|
||||
transcodeService,
|
||||
buildHlsMasterPlaylist,
|
||||
calculateEffectiveBitrateBps,
|
||||
type HdrType,
|
||||
} from '@shumai/core/src/transcode/transcode'
|
||||
import { metadataService } from '@shumai/core/src/metadata/metadata'
|
||||
import { getDerivedArtifactDirectory, stemFromKey } from '@shumai/core/src/utils/filename'
|
||||
import { gotenbergService } from '@shumai/core/src/gotenberg/gotenberg'
|
||||
import {
|
||||
gotenbergService,
|
||||
type GotenbergConvertOptions,
|
||||
} from '@shumai/core/src/gotenberg/gotenberg'
|
||||
import { turntableService } from '@shumai/core/src/turntable/turntable'
|
||||
import { parseCsvContent } from '@shumai/core/src/transcode/transcode'
|
||||
import { resolutionToDimensions } from '../workflows/transcode-utils'
|
||||
import {
|
||||
getProxyType,
|
||||
isCsvDocument,
|
||||
@@ -124,54 +134,110 @@ export async function getMediaInfoActivity(params: {
|
||||
}
|
||||
|
||||
if (isVideo) {
|
||||
const info = await transcodeService.getVideoInfo(params.filePath)
|
||||
mediaInfo.duration = info.duration
|
||||
mediaInfo.frames = info.totalFrames
|
||||
mediaInfo.metadata = {
|
||||
originalWidth: info.originalWidth,
|
||||
originalHeight: info.originalHeight,
|
||||
duration: info.duration,
|
||||
bitRate: info.bitRate,
|
||||
videoBitRate: info.videoBitRate,
|
||||
frameRate: info.frameRate,
|
||||
totalFrames: info.totalFrames,
|
||||
startTimecode: info.startTimecode || '00:00:00:00',
|
||||
hasAudio: info.hasAudio,
|
||||
videoCodec: info.videoCodec,
|
||||
audioCodec: info.audioCodec,
|
||||
audioChannels: info.audioChannels,
|
||||
audioSampleRate: info.audioSampleRate,
|
||||
audioBitDepth: info.audioBitDepth,
|
||||
colorTransfer: info.colorTransfer,
|
||||
colorPrimaries: info.colorPrimaries,
|
||||
colorSpace: info.colorSpace,
|
||||
isHdr: info.isHdr,
|
||||
hdrType: info.hdrType,
|
||||
dvProfile: info.dvProfile,
|
||||
rotation: info.rotation,
|
||||
format: {},
|
||||
let isDowngradedToAudio = false
|
||||
let videoInfo: Awaited<ReturnType<typeof transcodeService.getVideoInfo>> | null = null
|
||||
try {
|
||||
videoInfo = await transcodeService.getVideoInfo(params.filePath)
|
||||
} catch (err) {
|
||||
if (err instanceof Error && err.message.includes('No video stream found')) {
|
||||
try {
|
||||
const audioInfo = await transcodeService.getAudioInfo(params.filePath)
|
||||
isDowngradedToAudio = true
|
||||
mediaInfo.proxyType = 'audio'
|
||||
mediaInfo.duration = audioInfo.duration
|
||||
mediaInfo.metadata = {
|
||||
originalWidth: 0,
|
||||
originalHeight: 0,
|
||||
duration: audioInfo.duration,
|
||||
bitRate: audioInfo.bitRate,
|
||||
frameRate: 0,
|
||||
totalFrames: 0,
|
||||
startTimecode: '00:00:00:00',
|
||||
hasAudio: true,
|
||||
videoCodec: undefined,
|
||||
audioCodec: audioInfo.audioCodec,
|
||||
audioChannels: audioInfo.audioChannels,
|
||||
audioSampleRate: audioInfo.audioSampleRate,
|
||||
audioBitDepth: audioInfo.audioBitDepth,
|
||||
audioStreamIndex: audioInfo.audioStreamIndex,
|
||||
format: {},
|
||||
}
|
||||
const ftIdx = metadataUpdates.findIndex((u) => u.key === 'file_type')
|
||||
if (ftIdx !== -1) metadataUpdates[ftIdx].value = 'audio'
|
||||
const ptIdx = metadataUpdates.findIndex((u) => u.key === 'proxy_type')
|
||||
if (ptIdx !== -1) metadataUpdates[ptIdx].value = 'audio'
|
||||
metadataUpdates.push(
|
||||
{ key: 'duration', value: audioInfo.duration },
|
||||
{ key: 'bitRate', value: audioInfo.bitRate / 1000 },
|
||||
)
|
||||
if (audioInfo.audioCodec)
|
||||
metadataUpdates.push({ key: 'audio_codec', value: audioInfo.audioCodec })
|
||||
if (audioInfo.audioChannels !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_channels', value: audioInfo.audioChannels })
|
||||
if (audioInfo.audioSampleRate !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_sample_rate', value: audioInfo.audioSampleRate })
|
||||
if (audioInfo.audioBitDepth !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_bit_depth', value: audioInfo.audioBitDepth })
|
||||
} catch {
|
||||
throw err
|
||||
}
|
||||
} else {
|
||||
throw err
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDowngradedToAudio && videoInfo) {
|
||||
const info = videoInfo
|
||||
mediaInfo.duration = info.duration
|
||||
mediaInfo.frames = info.totalFrames
|
||||
mediaInfo.metadata = {
|
||||
originalWidth: info.originalWidth,
|
||||
originalHeight: info.originalHeight,
|
||||
duration: info.duration,
|
||||
bitRate: info.bitRate,
|
||||
videoBitRate: info.videoBitRate,
|
||||
frameRate: info.frameRate,
|
||||
totalFrames: info.totalFrames,
|
||||
startTimecode: info.startTimecode || '00:00:00:00',
|
||||
hasAudio: info.hasAudio,
|
||||
videoCodec: info.videoCodec,
|
||||
audioCodec: info.audioCodec,
|
||||
audioChannels: info.audioChannels,
|
||||
audioSampleRate: info.audioSampleRate,
|
||||
audioBitDepth: info.audioBitDepth,
|
||||
colorTransfer: info.colorTransfer,
|
||||
colorPrimaries: info.colorPrimaries,
|
||||
colorSpace: info.colorSpace,
|
||||
isHdr: info.isHdr,
|
||||
hdrType: info.hdrType,
|
||||
dvProfile: info.dvProfile,
|
||||
rotation: info.rotation,
|
||||
videoStreamIndex: info.videoStreamIndex,
|
||||
audioStreamIndex: info.audioStreamIndex,
|
||||
format: {},
|
||||
}
|
||||
metadataUpdates.push(
|
||||
{ key: 'resolution_width', value: info.originalWidth },
|
||||
{ key: 'resolution_height', value: info.originalHeight },
|
||||
{ key: 'duration', value: info.duration },
|
||||
{ key: 'bitRate', value: info.bitRate / 1000 },
|
||||
{ key: 'frame_rate', value: info.frameRate },
|
||||
)
|
||||
if (info.rotation !== undefined)
|
||||
metadataUpdates.push({ key: 'rotation', value: info.rotation })
|
||||
if (info.isHdr !== undefined)
|
||||
metadataUpdates.push({ key: 'is_hdr', value: info.isHdr ? 1 : 0 })
|
||||
if (info.colorTransfer)
|
||||
metadataUpdates.push({ key: 'color_transfer', value: info.colorTransfer })
|
||||
if (info.videoCodec) metadataUpdates.push({ key: 'video_codec', value: info.videoCodec })
|
||||
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
|
||||
if (info.audioChannels !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_channels', value: info.audioChannels })
|
||||
if (info.audioSampleRate !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_sample_rate', value: info.audioSampleRate })
|
||||
if (info.audioBitDepth !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_bit_depth', value: info.audioBitDepth })
|
||||
}
|
||||
metadataUpdates.push(
|
||||
{ key: 'resolution_width', value: info.originalWidth },
|
||||
{ key: 'resolution_height', value: info.originalHeight },
|
||||
{ key: 'duration', value: info.duration },
|
||||
{ key: 'bitRate', value: info.bitRate / 1000 },
|
||||
{ key: 'frame_rate', value: info.frameRate },
|
||||
)
|
||||
if (info.rotation !== undefined)
|
||||
metadataUpdates.push({ key: 'rotation', value: info.rotation })
|
||||
if (info.isHdr !== undefined)
|
||||
metadataUpdates.push({ key: 'is_hdr', value: info.isHdr ? 1 : 0 })
|
||||
if (info.colorTransfer)
|
||||
metadataUpdates.push({ key: 'color_transfer', value: info.colorTransfer })
|
||||
if (info.videoCodec) metadataUpdates.push({ key: 'video_codec', value: info.videoCodec })
|
||||
if (info.audioCodec) metadataUpdates.push({ key: 'audio_codec', value: info.audioCodec })
|
||||
if (info.audioChannels !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_channels', value: info.audioChannels })
|
||||
if (info.audioSampleRate !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_sample_rate', value: info.audioSampleRate })
|
||||
if (info.audioBitDepth !== undefined)
|
||||
metadataUpdates.push({ key: 'audio_bit_depth', value: info.audioBitDepth })
|
||||
} else if (isAudio) {
|
||||
const info = await transcodeService.getAudioInfo(params.filePath)
|
||||
mediaInfo.duration = info.duration
|
||||
@@ -189,6 +255,7 @@ export async function getMediaInfoActivity(params: {
|
||||
audioChannels: info.audioChannels,
|
||||
audioSampleRate: info.audioSampleRate,
|
||||
audioBitDepth: info.audioBitDepth,
|
||||
audioStreamIndex: info.audioStreamIndex,
|
||||
format: {},
|
||||
}
|
||||
metadataUpdates.push(
|
||||
@@ -271,6 +338,9 @@ export interface VideoActivityParams {
|
||||
sourceColorTransfer?: string
|
||||
sourceColorPrimaries?: string
|
||||
sourceColorSpace?: string
|
||||
sourceRotation?: number
|
||||
streamIndex?: number
|
||||
audioStreamIndex?: number
|
||||
}
|
||||
|
||||
export async function transcodeVideoActivity(
|
||||
@@ -332,6 +402,9 @@ export async function transcodeVideoActivity(
|
||||
sourceColorTransfer: params.sourceColorTransfer,
|
||||
sourceColorPrimaries: params.sourceColorPrimaries,
|
||||
sourceColorSpace: params.sourceColorSpace,
|
||||
sourceRotation: params.sourceRotation,
|
||||
streamIndex: params.streamIndex,
|
||||
audioStreamIndex: params.audioStreamIndex,
|
||||
})
|
||||
|
||||
const stat = fs.statSync(outputFile)
|
||||
@@ -380,11 +453,199 @@ export async function transcodeVideoActivity(
|
||||
}
|
||||
}
|
||||
|
||||
export interface HlsActivityParams {
|
||||
taskId: string
|
||||
assetKey: string
|
||||
filePath: string
|
||||
ladders: PrismaJson.HlsResolutionLadder[]
|
||||
originalWidth: number
|
||||
originalHeight: number
|
||||
duration: number
|
||||
originalFps: number
|
||||
hardwareAcceleration?: 'off' | 'auto'
|
||||
sourceVideoBitrate?: number
|
||||
threads?: number
|
||||
sourceIsHdr?: boolean
|
||||
sourceHdrType?: HdrType
|
||||
sourceColorTransfer?: string
|
||||
sourceColorPrimaries?: string
|
||||
sourceColorSpace?: string
|
||||
sourceRotation?: number
|
||||
streamIndex?: number
|
||||
audioStreamIndex?: number
|
||||
}
|
||||
|
||||
export async function transcodeHlsActivity(params: HlsActivityParams): Promise<PrismaJson.HlsInfo> {
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const assetDir = path.posix.dirname(params.assetKey)
|
||||
const hlsDirKey = path.posix.join(assetDir, 'hls')
|
||||
const masterKey = path.posix.join(hlsDirKey, 'master.m3u8')
|
||||
|
||||
const signal = getActivityCancellationSignal(params.taskId)
|
||||
if (signal?.aborted) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'HLS transcoding cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const hlsTmpDir = path.join(path.dirname(params.filePath), `hls-${ulid()}`)
|
||||
|
||||
try {
|
||||
const renditionSpecs: Array<{
|
||||
resolution: string
|
||||
width: number
|
||||
height: number
|
||||
bitrateBps: number
|
||||
isHdr?: boolean
|
||||
}> = []
|
||||
|
||||
const mediaResolutions: PrismaJson.VideoTranscode[] = []
|
||||
|
||||
for (const ladder of params.ladders) {
|
||||
if (signal?.aborted) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'HLS transcoding cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const [width, height] = resolutionToDimensions(
|
||||
ladder,
|
||||
params.originalWidth,
|
||||
params.originalHeight,
|
||||
)
|
||||
const targetBps = calculateEffectiveBitrateBps(
|
||||
height,
|
||||
width,
|
||||
params.sourceVideoBitrate,
|
||||
params.originalFps,
|
||||
)
|
||||
const ladderDir = path.join(hlsTmpDir, ladder)
|
||||
|
||||
await transcodeService.transcodeHlsRendition({
|
||||
inputFile: params.filePath,
|
||||
outputDir: ladderDir,
|
||||
width,
|
||||
height,
|
||||
frameRate: params.originalFps,
|
||||
hardwareAcceleration: params.hardwareAcceleration,
|
||||
sourceVideoBitrate: params.sourceVideoBitrate,
|
||||
threads: params.threads,
|
||||
signal,
|
||||
hdr: Boolean(params.sourceIsHdr),
|
||||
sourceIsHdr: params.sourceIsHdr,
|
||||
sourceHdrType: params.sourceHdrType,
|
||||
sourceColorTransfer: params.sourceColorTransfer,
|
||||
sourceColorPrimaries: params.sourceColorPrimaries,
|
||||
sourceColorSpace: params.sourceColorSpace,
|
||||
sourceRotation: params.sourceRotation,
|
||||
streamIndex: params.streamIndex,
|
||||
audioStreamIndex: params.audioStreamIndex,
|
||||
})
|
||||
|
||||
renditionSpecs.push({
|
||||
resolution: ladder,
|
||||
width,
|
||||
height,
|
||||
bitrateBps: targetBps,
|
||||
isHdr: params.sourceIsHdr,
|
||||
})
|
||||
|
||||
mediaResolutions.push({
|
||||
resolution: ladder,
|
||||
width,
|
||||
height,
|
||||
hdr: Boolean(params.sourceIsHdr),
|
||||
})
|
||||
|
||||
await ensureAssetNotPurging(params.assetKey)
|
||||
const files = fs.readdirSync(ladderDir)
|
||||
for (const file of files) {
|
||||
const localFilePath = path.join(ladderDir, file)
|
||||
const stat = fs.statSync(localFilePath)
|
||||
const s3Key = path.posix.join(hlsDirKey, ladder, file)
|
||||
let contentType = 'application/octet-stream'
|
||||
if (file.endsWith('.m3u8')) {
|
||||
contentType = 'application/vnd.apple.mpegurl'
|
||||
} else if (file.endsWith('.mp4')) {
|
||||
contentType = 'video/mp4'
|
||||
} else if (file.endsWith('.m4s')) {
|
||||
contentType = 'video/iso.segment'
|
||||
}
|
||||
|
||||
const stream = Bun.file(localFilePath).stream()
|
||||
await s3Service.putObject(bucket, s3Key, stream, stat.size, contentType)
|
||||
}
|
||||
}
|
||||
|
||||
const masterContent = buildHlsMasterPlaylist(renditionSpecs)
|
||||
const masterBuffer = Buffer.from(masterContent, 'utf-8')
|
||||
await ensureAssetNotPurging(params.assetKey)
|
||||
await s3Service.putObject(
|
||||
bucket,
|
||||
masterKey,
|
||||
masterBuffer,
|
||||
masterBuffer.length,
|
||||
'application/vnd.apple.mpegurl',
|
||||
)
|
||||
|
||||
return {
|
||||
key: masterKey,
|
||||
resolutions: mediaResolutions,
|
||||
}
|
||||
} catch (err) {
|
||||
const { code, message } = getErrorDetails(err)
|
||||
const lowerMsg = message.toLowerCase()
|
||||
|
||||
if (
|
||||
signal?.aborted ||
|
||||
code === 'ABORT_ERR' ||
|
||||
message.includes('aborted') ||
|
||||
lowerMsg.includes('abort')
|
||||
) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'HLS transcoding cancelled',
|
||||
nonRetryable: true,
|
||||
cause: err instanceof Error ? err : undefined,
|
||||
})
|
||||
}
|
||||
|
||||
if (
|
||||
code === 'ENOENT' ||
|
||||
lowerMsg.includes('enoent') ||
|
||||
lowerMsg.includes('ffmpeg') ||
|
||||
lowerMsg.includes('ffprobe') ||
|
||||
lowerMsg.includes('spawn') ||
|
||||
lowerMsg.includes('format') ||
|
||||
lowerMsg.includes('no video stream found') ||
|
||||
lowerMsg.includes('zscale') ||
|
||||
lowerMsg.includes('tonemap')
|
||||
) {
|
||||
throw ApplicationFailure.create({
|
||||
message: `HLS transcoding failed: ${message}`,
|
||||
nonRetryable: true,
|
||||
cause: err instanceof Error ? err : undefined,
|
||||
})
|
||||
}
|
||||
throw err
|
||||
} finally {
|
||||
if (fs.existsSync(hlsTmpDir)) {
|
||||
try {
|
||||
fs.rmSync(hlsTmpDir, { recursive: true, force: true })
|
||||
} catch {
|
||||
// ignore cleanup error
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface AudioActivityParams {
|
||||
taskId?: string
|
||||
assetKey: string
|
||||
filePath: string
|
||||
threads?: number
|
||||
audioStreamIndex?: number
|
||||
}
|
||||
|
||||
export async function transcodeAudioActivity(
|
||||
@@ -419,6 +680,7 @@ export async function transcodeAudioActivity(
|
||||
bitrate: '128k',
|
||||
threads: params.threads,
|
||||
signal,
|
||||
audioStreamIndex: params.audioStreamIndex,
|
||||
})
|
||||
|
||||
const stat = fs.statSync(outputFile)
|
||||
@@ -518,6 +780,8 @@ export async function transcodeImageActivity(
|
||||
lowerMsg.includes('imagemagick') ||
|
||||
lowerMsg.includes('magick') ||
|
||||
lowerMsg.includes('convert') ||
|
||||
lowerMsg.includes('dcraw') ||
|
||||
lowerMsg.includes('raw') ||
|
||||
lowerMsg.includes('spawn') ||
|
||||
lowerMsg.includes('format')
|
||||
) {
|
||||
@@ -590,6 +854,7 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
|
||||
hdrType: params.mediaInfo.metadata?.hdrType,
|
||||
colorTransfer: params.mediaInfo.metadata?.colorTransfer,
|
||||
},
|
||||
params.mediaInfo.metadata?.videoStreamIndex,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -654,6 +919,7 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
|
||||
}
|
||||
|
||||
export interface GeneratePdfProxyActivityParams {
|
||||
teamId?: string | null
|
||||
assetId: string
|
||||
assetKey: string
|
||||
filePath: string
|
||||
@@ -680,8 +946,12 @@ export async function generatePdfProxyActivity(
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const pdfFilePath = path.join(tmpDir, 'proxy.pdf')
|
||||
|
||||
const targetTeamId = params.teamId || undefined
|
||||
|
||||
try {
|
||||
const gotenbergAvailable = await gotenbergService.isAvailable()
|
||||
const gotenbergAvailable = await (targetTeamId
|
||||
? gotenbergService.isAvailable(targetTeamId)
|
||||
: gotenbergService.isAvailable())
|
||||
|
||||
if (isOffice) {
|
||||
if (!gotenbergAvailable) {
|
||||
@@ -689,10 +959,14 @@ export async function generatePdfProxyActivity(
|
||||
'Gotenberg service is required for Office document conversion but is unavailable.',
|
||||
)
|
||||
}
|
||||
const pdfBuffer = await gotenbergService.convertDocumentToPdf(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
)
|
||||
const pdfBuffer = await (targetTeamId
|
||||
? gotenbergService.convertDocumentToPdf(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
{ teamId: targetTeamId },
|
||||
targetTeamId,
|
||||
)
|
||||
: gotenbergService.convertDocumentToPdf(params.filePath, params.filename))
|
||||
fs.writeFileSync(pdfFilePath, pdfBuffer)
|
||||
} else if (isHtml) {
|
||||
if (!gotenbergAvailable) {
|
||||
@@ -700,7 +974,9 @@ export async function generatePdfProxyActivity(
|
||||
'Gotenberg service is required for HTML document conversion but is unavailable.',
|
||||
)
|
||||
}
|
||||
const pdfBuffer = await gotenbergService.convertHtmlToPdf(params.filePath, params.filename)
|
||||
const pdfBuffer = await (targetTeamId
|
||||
? gotenbergService.convertHtmlToPdf(params.filePath, params.filename, targetTeamId)
|
||||
: gotenbergService.convertHtmlToPdf(params.filePath, params.filename))
|
||||
fs.writeFileSync(pdfFilePath, pdfBuffer)
|
||||
} else if (isCsv) {
|
||||
if (gotenbergAvailable) {
|
||||
@@ -713,10 +989,14 @@ export async function generatePdfProxyActivity(
|
||||
} catch {
|
||||
// Fallback landscape calculation
|
||||
}
|
||||
const options: GotenbergConvertOptions = {
|
||||
landscape: isLandscape,
|
||||
...(targetTeamId ? { teamId: targetTeamId } : {}),
|
||||
}
|
||||
const pdfBuffer = await gotenbergService.convertDocumentToPdf(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
{ landscape: isLandscape },
|
||||
options,
|
||||
)
|
||||
fs.writeFileSync(pdfFilePath, pdfBuffer)
|
||||
} else {
|
||||
@@ -724,20 +1004,23 @@ export async function generatePdfProxyActivity(
|
||||
}
|
||||
} else if (isMd) {
|
||||
if (gotenbergAvailable) {
|
||||
const pdfBuffer = await gotenbergService.convertMarkdownToPdf(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
)
|
||||
const pdfBuffer = await (targetTeamId
|
||||
? gotenbergService.convertMarkdownToPdf(params.filePath, params.filename, targetTeamId)
|
||||
: gotenbergService.convertMarkdownToPdf(params.filePath, params.filename))
|
||||
fs.writeFileSync(pdfFilePath, pdfBuffer)
|
||||
} else {
|
||||
await transcodeService.generatePdfFromText(params.filePath, pdfFilePath)
|
||||
}
|
||||
} else if (isTxt) {
|
||||
if (gotenbergAvailable) {
|
||||
const pdfBuffer = await gotenbergService.convertDocumentToPdf(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
)
|
||||
const pdfBuffer = await (targetTeamId
|
||||
? gotenbergService.convertDocumentToPdf(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
{ teamId: targetTeamId },
|
||||
targetTeamId,
|
||||
)
|
||||
: gotenbergService.convertDocumentToPdf(params.filePath, params.filename))
|
||||
fs.writeFileSync(pdfFilePath, pdfBuffer)
|
||||
} else {
|
||||
await transcodeService.generatePdfFromText(params.filePath, pdfFilePath)
|
||||
@@ -894,6 +1177,7 @@ export interface ExtractPosterActivityParams {
|
||||
isHdr?: boolean
|
||||
hdrType?: HdrType
|
||||
colorTransfer?: string
|
||||
streamIndex?: number
|
||||
}
|
||||
|
||||
export async function extractPosterActivity(
|
||||
@@ -925,6 +1209,7 @@ export async function extractPosterActivity(
|
||||
hdrType: params.hdrType,
|
||||
colorTransfer: params.colorTransfer,
|
||||
signal,
|
||||
streamIndex: params.streamIndex,
|
||||
})
|
||||
|
||||
const posterBuffer = fs.readFileSync(posterFile)
|
||||
@@ -1075,8 +1360,11 @@ export async function createEmbeddingTaskIfEnabledActivity(
|
||||
return
|
||||
}
|
||||
|
||||
const mediaInfo = asset.media as PrismaJson.MediaInfo | null
|
||||
const isVideo = asset.mediaType?.startsWith('video/')
|
||||
const isImage = asset.mediaType?.startsWith('image/')
|
||||
const isImage =
|
||||
asset.mediaType?.startsWith('image/') ||
|
||||
(mediaInfo?.proxyType === '3d' && (mediaInfo.imageTranscodes?.length ?? 0) > 0)
|
||||
if (!isVideo && !isImage) {
|
||||
return
|
||||
}
|
||||
@@ -1241,6 +1529,8 @@ export async function transcodeVideoChunkActivity(
|
||||
params.startTime.toString(),
|
||||
'-i',
|
||||
inputSource,
|
||||
'-map',
|
||||
'0:V:0',
|
||||
'-t',
|
||||
(params.endTime - params.startTime).toString(),
|
||||
'-vf',
|
||||
@@ -1286,3 +1576,364 @@ export async function deleteS3ObjectActivity(params: { key: string }): Promise<v
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
await s3Service.deleteObject(bucket, params.key)
|
||||
}
|
||||
|
||||
export interface Render3dModelActivityParams {
|
||||
taskId: string
|
||||
teamId: string
|
||||
assetId: string
|
||||
assetKey: string
|
||||
filePath: string
|
||||
filename: string
|
||||
targetVideoKey: string
|
||||
targetPosterKey: string
|
||||
}
|
||||
|
||||
export interface Render3dModelActivityResult {
|
||||
videoFilePath: string
|
||||
posterFilePath: string
|
||||
modelMetadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export interface Start3dRenderActivityParams {
|
||||
taskId: string
|
||||
teamId: string
|
||||
assetId: string
|
||||
assetKey: string
|
||||
filePath: string
|
||||
filename: string
|
||||
targetPosterKey: string
|
||||
}
|
||||
|
||||
export interface Start3dRenderActivityResult {
|
||||
renderTaskId: string
|
||||
posterFilePath: string
|
||||
posterWidth?: number
|
||||
posterHeight?: number
|
||||
modelMetadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export async function start3dRenderActivity(
|
||||
params: Start3dRenderActivityParams,
|
||||
): Promise<Start3dRenderActivityResult> {
|
||||
const signal = getActivityCancellationSignal(params.taskId)
|
||||
if (signal?.aborted) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Render cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const posterFilePath = path.join(tmpDir, 'poster.webp')
|
||||
|
||||
let fileId: string | undefined
|
||||
let renderTaskId: string | undefined
|
||||
|
||||
try {
|
||||
const uploadResult = await turntableService.uploadFile(
|
||||
params.filePath,
|
||||
params.filename,
|
||||
params.teamId,
|
||||
)
|
||||
fileId = uploadResult.id
|
||||
|
||||
if (signal?.aborted) {
|
||||
await turntableService.deleteFile(fileId, params.teamId).catch(() => {})
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Render cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const startResult = await turntableService.startRender(fileId, {}, params.teamId)
|
||||
renderTaskId = startResult.taskId
|
||||
|
||||
const posterFileId = startResult.poster?.fileId
|
||||
if (!posterFileId) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Poster file ID missing from turntable render result',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const posterBuffer = await turntableService.downloadFile(posterFileId, undefined, params.teamId)
|
||||
const posterWebpBuffer = await transcodeService.convertImageToWebp(posterBuffer)
|
||||
fs.writeFileSync(posterFilePath, posterWebpBuffer)
|
||||
|
||||
await ensureAssetNotPurging(params.assetKey)
|
||||
|
||||
await s3Service.putObject(
|
||||
bucket,
|
||||
params.targetPosterKey,
|
||||
posterWebpBuffer,
|
||||
posterWebpBuffer.length,
|
||||
'image/webp',
|
||||
)
|
||||
|
||||
return {
|
||||
renderTaskId,
|
||||
posterFilePath,
|
||||
posterWidth: startResult.poster?.width,
|
||||
posterHeight: startResult.poster?.height,
|
||||
modelMetadata: (startResult.metadata as Record<string, unknown>) || {},
|
||||
}
|
||||
} catch (err) {
|
||||
if (renderTaskId) {
|
||||
await turntableService.deleteTask(renderTaskId, params.teamId).catch(() => {})
|
||||
} else if (fileId) {
|
||||
await turntableService.deleteFile(fileId, params.teamId).catch(() => {})
|
||||
}
|
||||
if (err instanceof ApplicationFailure) {
|
||||
throw err
|
||||
}
|
||||
const errMsg = err instanceof Error ? err.message : String(err)
|
||||
throw ApplicationFailure.create({
|
||||
message: `Failed to start 3D render: ${errMsg}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export interface WaitFor3dVideoRenderActivityParams {
|
||||
taskId: string
|
||||
teamId: string
|
||||
assetKey: string
|
||||
renderTaskId: string
|
||||
targetVideoKey: string
|
||||
tmpDir: string
|
||||
}
|
||||
|
||||
export interface WaitFor3dVideoRenderActivityResult {
|
||||
videoFilePath: string
|
||||
}
|
||||
|
||||
export async function waitFor3dVideoRenderActivity(
|
||||
params: WaitFor3dVideoRenderActivityParams,
|
||||
): Promise<WaitFor3dVideoRenderActivityResult> {
|
||||
const signal = getActivityCancellationSignal(params.taskId)
|
||||
if (signal?.aborted) {
|
||||
await turntableService.deleteTask(params.renderTaskId, params.teamId).catch(() => {})
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Render cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const videoFilePath = path.join(params.tmpDir, 'turntable.mp4')
|
||||
|
||||
try {
|
||||
let finishedStatus: 'completed' | 'failed' | null = null
|
||||
let taskRecord: Awaited<ReturnType<typeof turntableService.getTaskStatus>> | null = null
|
||||
|
||||
for (let i = 0; i < 360; i++) {
|
||||
if (signal?.aborted) {
|
||||
await turntableService.deleteTask(params.renderTaskId, params.teamId).catch(() => {})
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Render cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000))
|
||||
}
|
||||
|
||||
taskRecord = await turntableService.getTaskStatus(params.renderTaskId, params.teamId)
|
||||
if (taskRecord.status === 'completed') {
|
||||
finishedStatus = 'completed'
|
||||
break
|
||||
}
|
||||
if (taskRecord.status === 'failed') {
|
||||
finishedStatus = 'failed'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if (finishedStatus !== 'completed' || !taskRecord) {
|
||||
const errMsg =
|
||||
finishedStatus === 'failed'
|
||||
? taskRecord?.error?.message || '3D render failed on turntable server'
|
||||
: '3D render timed out on turntable server'
|
||||
throw ApplicationFailure.create({
|
||||
message: errMsg,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const videoFileId = taskRecord.video?.fileId
|
||||
if (!videoFileId) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Video file ID missing from turntable render result',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const videoBuffer = await turntableService.downloadFile(
|
||||
videoFileId,
|
||||
videoFilePath,
|
||||
params.teamId,
|
||||
)
|
||||
|
||||
await ensureAssetNotPurging(params.assetKey)
|
||||
|
||||
await s3Service.putObject(
|
||||
bucket,
|
||||
params.targetVideoKey,
|
||||
videoBuffer,
|
||||
videoBuffer.length,
|
||||
'video/mp4',
|
||||
)
|
||||
|
||||
await turntableService.deleteTask(params.renderTaskId, params.teamId).catch((err) => {
|
||||
logger.warn(
|
||||
{ err, taskId: params.renderTaskId },
|
||||
'Failed to delete turntable task after completion',
|
||||
)
|
||||
})
|
||||
|
||||
return {
|
||||
videoFilePath,
|
||||
}
|
||||
} catch (err) {
|
||||
await turntableService.deleteTask(params.renderTaskId, params.teamId).catch(() => {})
|
||||
if (err instanceof ApplicationFailure) {
|
||||
throw err
|
||||
}
|
||||
const errMsg = err instanceof Error ? err.message : String(err)
|
||||
throw ApplicationFailure.create({
|
||||
message: `Failed to render 3D model video: ${errMsg}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Legacy monolithic 3D render activity. Prefer using `start3dRenderActivity` and `waitFor3dVideoRenderActivity`.
|
||||
*/
|
||||
export async function render3dModelActivity(
|
||||
params: Render3dModelActivityParams,
|
||||
): Promise<Render3dModelActivityResult> {
|
||||
const tmpDir = path.dirname(params.filePath)
|
||||
const startResult = await start3dRenderActivity({
|
||||
taskId: params.taskId,
|
||||
teamId: params.teamId,
|
||||
assetId: params.assetId,
|
||||
assetKey: params.assetKey,
|
||||
filePath: params.filePath,
|
||||
filename: params.filename,
|
||||
targetPosterKey: params.targetPosterKey,
|
||||
})
|
||||
|
||||
const videoResult = await waitFor3dVideoRenderActivity({
|
||||
taskId: params.taskId,
|
||||
teamId: params.teamId,
|
||||
assetKey: params.assetKey,
|
||||
renderTaskId: startResult.renderTaskId,
|
||||
targetVideoKey: params.targetVideoKey,
|
||||
tmpDir,
|
||||
})
|
||||
|
||||
return {
|
||||
videoFilePath: videoResult.videoFilePath,
|
||||
posterFilePath: startResult.posterFilePath,
|
||||
modelMetadata: startResult.modelMetadata,
|
||||
}
|
||||
}
|
||||
|
||||
export interface Generate3dSpriteActivityParams {
|
||||
taskId: string
|
||||
assetKey: string
|
||||
videoFilePath: string
|
||||
spriteKey: string
|
||||
}
|
||||
|
||||
export async function generate3dSpriteActivity(
|
||||
params: Generate3dSpriteActivityParams,
|
||||
): Promise<{ spriteKey: string }> {
|
||||
const signal = getActivityCancellationSignal(params.taskId)
|
||||
if (signal?.aborted) {
|
||||
throw ApplicationFailure.create({
|
||||
message: 'Sprite generation cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const tmpDir = path.dirname(params.videoFilePath)
|
||||
const spriteFilePath = path.join(tmpDir, 'sprite.webp')
|
||||
|
||||
try {
|
||||
await transcodeService.generate3dSprite(params.videoFilePath, spriteFilePath, signal)
|
||||
const spriteBuffer = fs.readFileSync(spriteFilePath)
|
||||
|
||||
await ensureAssetNotPurging(params.assetKey)
|
||||
await s3Service.putObject(
|
||||
bucket,
|
||||
params.spriteKey,
|
||||
spriteBuffer,
|
||||
spriteBuffer.length,
|
||||
'image/webp',
|
||||
)
|
||||
|
||||
return { spriteKey: params.spriteKey }
|
||||
} catch (err) {
|
||||
if (err instanceof ApplicationFailure) {
|
||||
throw err
|
||||
}
|
||||
const errMsg = err instanceof Error ? err.message : String(err)
|
||||
throw ApplicationFailure.create({
|
||||
message: `Failed to generate 3D sprite: ${errMsg}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export interface Generate3dViewsActivityParams {
|
||||
taskId: string
|
||||
assetKey: string
|
||||
videoFilePath: string
|
||||
viewsKey: string
|
||||
}
|
||||
|
||||
export async function generate3dViewsActivity(
|
||||
params: Generate3dViewsActivityParams,
|
||||
): Promise<{ viewsKey: string }> {
|
||||
const signal = getActivityCancellationSignal(params.taskId)
|
||||
if (signal?.aborted) {
|
||||
throw ApplicationFailure.create({
|
||||
message: '3D views generation cancelled',
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
|
||||
const bucket = process.env.S3_BUCKET || 'shumai'
|
||||
const tmpDir = path.dirname(params.videoFilePath)
|
||||
const viewsFilePath = path.join(tmpDir, 'views.webp')
|
||||
|
||||
try {
|
||||
await transcodeService.generate3dViews(params.videoFilePath, viewsFilePath, signal)
|
||||
const viewsBuffer = fs.readFileSync(viewsFilePath)
|
||||
|
||||
await ensureAssetNotPurging(params.assetKey)
|
||||
await s3Service.putObject(
|
||||
bucket,
|
||||
params.viewsKey,
|
||||
viewsBuffer,
|
||||
viewsBuffer.length,
|
||||
'image/webp',
|
||||
)
|
||||
|
||||
return { viewsKey: params.viewsKey }
|
||||
} catch (err) {
|
||||
if (err instanceof ApplicationFailure) {
|
||||
throw err
|
||||
}
|
||||
const errMsg = err instanceof Error ? err.message : String(err)
|
||||
throw ApplicationFailure.create({
|
||||
message: `Failed to generate 3D views: ${errMsg}`,
|
||||
nonRetryable: true,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user