mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-19 23:36:58 +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 | ||
|
|
f2b0415580 | ||
|
|
c9d0b476cd | ||
|
|
bf5ac566b6 | ||
|
|
af8f24aa95 | ||
|
|
d98f486c9d | ||
|
|
94ea4c917a | ||
|
|
941bf0fd1b | ||
|
|
59742dde78 | ||
|
|
29cd5d807c | ||
|
|
f6e27095a5 | ||
|
|
55637bc9a8 | ||
|
|
0d6671c3e1 | ||
|
|
c3375ee935 | ||
|
|
f579947770 | ||
|
|
53c9485f10 | ||
|
|
75bf9b3b88 | ||
|
|
657cd761bc | ||
|
|
de634a5dc5 | ||
|
|
09b65a1eb6 | ||
|
|
b52b2ce7d8 | ||
|
|
145aa6bfb4 | ||
|
|
a91d8c4521 | ||
|
|
3a509537fd | ||
|
|
76ffb51bb2 | ||
|
|
ca94e51424 | ||
|
|
d8621a53b6 | ||
|
|
e2f741eda6 | ||
|
|
7af3647913 | ||
|
|
12f99797d2 | ||
|
|
1796de8eda | ||
|
|
a6b7ac4383 | ||
|
|
ca575803cb | ||
|
|
def42cd000 | ||
|
|
ede52e5009 | ||
|
|
ddbf897b27 | ||
|
|
7d56b5bf90 | ||
|
|
87e88396d1 | ||
|
|
c5b57ca862 | ||
|
|
3420d848cb | ||
|
|
70b81355c2 | ||
|
|
1d552e4ae4 | ||
|
|
b37b2172e7 | ||
|
|
941000d277 | ||
|
|
4a61e87a27 | ||
|
|
04fd571bd9 | ||
|
|
3a05332cd6 | ||
|
|
51f63fc9e4 | ||
|
|
b35c824a27 | ||
|
|
f62df9555a | ||
|
|
67b767f1e8 | ||
|
|
62e86b703e | ||
|
|
6c87db0581 | ||
|
|
bc85dc4541 | ||
|
|
659a0af2c5 | ||
|
|
54d2c407b5 | ||
|
|
8e31d05f8a | ||
|
|
8c1e59d131 | ||
|
|
b087bf73ae | ||
|
|
a49722d5c7 | ||
|
|
576d8ebe64 | ||
|
|
ffc1889cdc | ||
|
|
6285ff8618 | ||
|
|
1e60933cdb | ||
|
|
dd0ea05a88 | ||
|
|
52330869a2 | ||
|
|
0c561e9b39 | ||
|
|
a236cd3a97 | ||
|
|
c3ef769f51 | ||
|
|
e58dfaa71a | ||
|
|
35b57cc0ab | ||
|
|
5a754bcb94 | ||
|
|
64b68e7d63 | ||
|
|
c2f477a391 | ||
|
|
9263971653 | ||
|
|
79a479c87c | ||
|
|
134eb8b7fa | ||
|
|
e06478df88 | ||
|
|
6e9cf8dfb6 | ||
|
|
d2620f6911 | ||
|
|
4537baa6a2 | ||
|
|
810e0c4cf5 | ||
|
|
07cb648183 | ||
|
|
c6602c9f1c | ||
|
|
86032539ed | ||
|
|
b2ec012e10 | ||
|
|
7fd8623684 | ||
|
|
083753a96d | ||
|
|
4b62c31f29 | ||
|
|
2208d4e0e0 | ||
|
|
df7f4c3c2d | ||
|
|
12323e1416 | ||
|
|
2edc5e1071 | ||
|
|
2162ed9ebe | ||
|
|
6acebb73ec | ||
|
|
7a1d6c0ab5 | ||
|
|
d16e31c0e5 | ||
|
|
d9a8b6a191 | ||
|
|
5ec4cd7fcd | ||
|
|
a7925e3c79 | ||
|
|
472b420620 | ||
|
|
8f55ba1d37 | ||
|
|
7b1428bf51 | ||
|
|
d5b3b1868e | ||
|
|
49f3fc0be5 | ||
|
|
59e641ccb3 | ||
|
|
1d9268b224 | ||
|
|
470a4bd6f7 | ||
|
|
8801d59b2e | ||
|
|
6a20e06982 | ||
|
|
b17abce2c2 | ||
|
|
f67e334016 | ||
|
|
c1de66520e | ||
|
|
37e086d822 | ||
|
|
d21f8ca8de | ||
|
|
6af4e7c2ec | ||
|
|
1f2bdc8c9e | ||
|
|
4c0fd29b7f | ||
|
|
ffef67be8f | ||
|
|
4d100bf542 | ||
|
|
8a75d015a1 | ||
|
|
f806272c06 | ||
|
|
4935eeff28 | ||
|
|
eed0264b9c | ||
|
|
dd82daf65c | ||
|
|
55d9596835 | ||
|
|
cb1c1c502b | ||
|
|
6d4f62d6f6 | ||
|
|
43808216e6 | ||
|
|
f66bb7af73 | ||
|
|
ae86d56a7d | ||
|
|
1cee103b1c | ||
|
|
3c3b6880e4 | ||
|
|
0b84402c83 | ||
|
|
61a61abc7c | ||
|
|
fc878775c2 | ||
|
|
7acf736300 | ||
|
|
9d50301a43 | ||
|
|
7f185ca23c | ||
|
|
94582c9001 | ||
|
|
41b73feeab | ||
|
|
96493a5493 | ||
|
|
93c593545d | ||
|
|
11758c23c0 | ||
|
|
1cd94a77c6 | ||
|
|
5ad3fdbf69 | ||
|
|
851ae49c84 | ||
|
|
82aee9a291 | ||
|
|
1b5cbf936a | ||
|
|
1daeaf51ef | ||
|
|
49ef48a74a | ||
|
|
a680fccb12 | ||
|
|
e67552d8bd | ||
|
|
8080acfb2e | ||
|
|
dbd30a815f | ||
|
|
442568de00 | ||
|
|
d15fc5c6be | ||
|
|
aa6d5ed626 | ||
|
|
283d28bed9 | ||
|
|
315cacd474 | ||
|
|
44ab1e7023 | ||
|
|
beef4e9963 | ||
|
|
990f68fb3b | ||
|
|
ee4933a4f8 | ||
|
|
c91867b8eb | ||
|
|
8608ee027a | ||
|
|
394ddc8db4 | ||
|
|
83455aeaea | ||
|
|
707c091c9b | ||
|
|
d3f5892dd2 | ||
|
|
70b6c33204 | ||
|
|
624a3a6a54 | ||
|
|
03aea2cb36 | ||
|
|
0a31659588 | ||
|
|
39a66dc569 | ||
|
|
2a27e19b15 | ||
|
|
f306229b21 | ||
|
|
f5786f742b | ||
|
|
fe7e541585 | ||
|
|
47ecbdff6a | ||
|
|
2dc0f08725 | ||
|
|
e76ed19013 | ||
|
|
b7d3e32fb9 | ||
|
|
94bda76c56 | ||
|
|
7586b8a44a | ||
|
|
d9a6734527 | ||
|
|
72aad56560 | ||
|
|
ffeccaa514 | ||
|
|
d73f7f81a1 | ||
|
|
1104ec36cc | ||
|
|
ac5970c03e | ||
|
|
b568eac77d | ||
|
|
bb9c53adad | ||
|
|
29161f3a1a | ||
|
|
b806b0e2ba | ||
|
|
033652cde3 | ||
|
|
30021b07d0 | ||
|
|
07ad0d2f65 | ||
|
|
5ef763fbae | ||
|
|
e6fde25446 | ||
|
|
dd2f8e68d9 | ||
|
|
c938e84ccc | ||
|
|
9745985f57 | ||
|
|
b645a29608 | ||
|
|
deeb02351f | ||
|
|
c53919b891 | ||
|
|
edf1f6a327 | ||
|
|
1afdbb671b | ||
|
|
134d19d907 | ||
|
|
043cde9fcc | ||
|
|
472ffddc99 | ||
|
|
78eb840bf5 | ||
|
|
077536de98 | ||
|
|
3789366d35 | ||
|
|
5647231d7f | ||
|
|
b2a11c5ce9 | ||
|
|
4532deb753 | ||
|
|
6efa634f54 | ||
|
|
d696c39622 | ||
|
|
83d22d47a2 | ||
|
|
4436c3304d | ||
|
|
2fee708863 | ||
|
|
dbe3420b6c | ||
|
|
16d136b45a | ||
|
|
2656a42c86 | ||
|
|
15910a0bf4 | ||
|
|
5458189c1f | ||
|
|
d3aef5f0c1 | ||
|
|
5946a679ea | ||
|
|
a54c04e15a | ||
|
|
0bccd13399 | ||
|
|
3b86d9b6d8 | ||
|
|
1600949e4a | ||
|
|
2f5b968935 | ||
|
|
97069042b2 | ||
|
|
fb66166b49 | ||
|
|
b0d8ecb589 | ||
|
|
2d61fae699 | ||
|
|
5ef7716c9c | ||
|
|
6d80f06c22 | ||
|
|
0324b95c7e | ||
|
|
7dfb2c7f2f | ||
|
|
11fc76e56b | ||
|
|
52f85fcd15 | ||
|
|
118107ebc9 | ||
|
|
7a83f7d406 | ||
|
|
c2d25bd2f1 | ||
|
|
8e223da8e3 | ||
|
|
92147c858f | ||
|
|
e602e96a28 | ||
|
|
cb1054bc2c | ||
|
|
87ccbe5330 | ||
|
|
04f0a39300 | ||
|
|
fd1ff8d70e | ||
|
|
79ea3c3ffd | ||
|
|
18780a9117 | ||
|
|
846732d7d4 | ||
|
|
1bf22231ec | ||
|
|
361e4f32be | ||
|
|
5bb546bd8c | ||
|
|
e802469a70 | ||
|
|
31894bfb59 | ||
|
|
8a45364160 | ||
|
|
a64ed2aa13 | ||
|
|
c61a23c0c1 | ||
|
|
668871b730 | ||
|
|
cd8a9e58fd | ||
|
|
69c57b16ab | ||
|
|
8837b03b3c | ||
|
|
36ae27fdd5 | ||
|
|
9a4f8d67c3 | ||
|
|
7949c1572a | ||
|
|
f161437797 | ||
|
|
5b19cfe98e | ||
|
|
9ba61b3d3e | ||
|
|
db04df88f1 | ||
|
|
4a4d9cdfb7 | ||
|
|
f1c0f4e50d | ||
|
|
b49adf8ff1 | ||
|
|
cdc344ab7a | ||
|
|
f3d42cd0ce | ||
|
|
bb789a9557 | ||
|
|
d267c7de98 | ||
|
|
1c7a87488b | ||
|
|
a756f7dc2a | ||
|
|
41622f45b4 | ||
|
|
952323deca | ||
|
|
acb64f44bb | ||
|
|
343750e178 | ||
|
|
b75e0c7fdc | ||
|
|
d8c3f46a8d | ||
|
|
48c71efc6c | ||
|
|
35f6206e63 | ||
|
|
03f8ad90d2 | ||
|
|
8308bd5bb7 | ||
|
|
006fb1726b | ||
|
|
19df011dc2 | ||
|
|
d6a74b8294 | ||
|
|
37331eae64 | ||
|
|
825044f16d | ||
|
|
e51d86e8f0 | ||
|
|
d0d29b34ed | ||
|
|
219961755c | ||
|
|
bca2d26e1d | ||
|
|
4bd166d7b9 | ||
|
|
51208d3ff0 | ||
|
|
ae5c58d48c | ||
|
|
eb73ba7d6a | ||
|
|
3727879c19 | ||
|
|
f46fa31262 | ||
|
|
08552c229d | ||
|
|
9dfda1d446 | ||
|
|
e214036308 | ||
|
|
9da6818adc | ||
|
|
ff113906d7 | ||
|
|
56421cd562 | ||
|
|
4e2694e2d9 | ||
|
|
b876af464e | ||
|
|
216538fcfa | ||
|
|
bb71e6bb2a | ||
|
|
9bfa174348 | ||
|
|
cd3c7f3641 | ||
|
|
b8345f7c46 | ||
|
|
d364e13eb7 | ||
|
|
f429873362 | ||
|
|
d81fc09b35 | ||
|
|
6dec8e9786 | ||
|
|
e1ec56147e | ||
|
|
972b1c7458 | ||
|
|
07396725aa | ||
|
|
869bb873cf | ||
|
|
fd7b4ca331 | ||
|
|
c4bba31f20 | ||
|
|
72654e84b2 | ||
|
|
cec3821d00 | ||
|
|
dc3dbcb73e | ||
|
|
6226090fd1 | ||
|
|
d052c56d39 | ||
|
|
bd13fa7774 | ||
|
|
5e462cc7b1 | ||
|
|
73c11af9a3 | ||
|
|
adb73b56a2 | ||
|
|
e5dcf02b26 | ||
|
|
684f88a406 | ||
|
|
8ec970e2bf | ||
|
|
3eb7894df9 | ||
|
|
464167ec83 |
+2
-1
@@ -14,4 +14,5 @@ helm-charts
|
||||
.env
|
||||
.editorconfig
|
||||
.idea
|
||||
coverage*
|
||||
coverage*
|
||||
packages/webui/paraglide
|
||||
+65
-10
@@ -22,9 +22,9 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
bun-version: 1.4.2
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
@@ -34,6 +34,9 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ripgrep bubblewrap socat ffmpeg poppler-utils imagemagick
|
||||
|
||||
- name: Compile i18n
|
||||
run: bun run i18n:compile
|
||||
|
||||
- name: Lint
|
||||
run: bun run lint
|
||||
|
||||
@@ -76,20 +79,23 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
bun-version: 1.4.2
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: Compile i18n
|
||||
run: bun run i18n:compile
|
||||
|
||||
- name: Install Playwright browser (${{ matrix.project }})
|
||||
run: bunx playwright install --with-deps ${{ matrix.project }}
|
||||
|
||||
- name: Run video player harness tests
|
||||
env:
|
||||
E2E_SKIP_APP_SERVER: true
|
||||
run: bun run test:e2e --project=harness-${{ matrix.project }}
|
||||
run: bunx playwright test --project=harness-${{ matrix.project }}
|
||||
|
||||
- name: Upload Playwright report
|
||||
if: ${{ !cancelled() }}
|
||||
@@ -118,18 +124,26 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
bun-version: 1.4.2
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y ripgrep bubblewrap socat ffmpeg poppler-utils imagemagick
|
||||
|
||||
- name: Compile i18n
|
||||
run: bun run i18n:compile
|
||||
|
||||
- name: Install Playwright browser (${{ matrix.project }})
|
||||
run: bunx playwright install --with-deps ${{ matrix.project }}
|
||||
|
||||
- name: Run app E2E tests
|
||||
run: bun run test:e2e --project=app-${{ matrix.project }} --no-deps
|
||||
run: bunx playwright test --project=app-${{ matrix.project }} --no-deps
|
||||
|
||||
- name: Upload Playwright report
|
||||
if: ${{ !cancelled() }}
|
||||
@@ -147,9 +161,9 @@ jobs:
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v1
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
bun-version: 1.4.2
|
||||
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
@@ -161,3 +175,44 @@ jobs:
|
||||
|
||||
- name: Run Workflow E2E Tests
|
||||
run: bun run test:e2e:workflow
|
||||
|
||||
docker_compose_deploy:
|
||||
name: Docker Compose Deployment
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build Docker Image
|
||||
run: |
|
||||
docker build -t shumaione/shumai:latest .
|
||||
|
||||
- name: Start Docker Compose
|
||||
run: |
|
||||
docker compose -f docker-compose/local/docker-compose.yaml up -d
|
||||
|
||||
- name: Verify Home Page HTTP 200
|
||||
run: |
|
||||
echo "Waiting for shumai_app container to start..."
|
||||
for i in {1..30}; do
|
||||
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:3000 || true)
|
||||
echo "Attempt $i: HTTP status code $STATUS_CODE"
|
||||
if [ "$STATUS_CODE" -eq 200 ]; then
|
||||
echo "✅ Docker compose app is running cleanly (HTTP 200 OK)"
|
||||
exit 0
|
||||
fi
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo "❌ Container failed to respond with HTTP 200 OK within 60s"
|
||||
echo "--- Container Logs ---"
|
||||
docker compose -f docker-compose/local/docker-compose.yaml logs
|
||||
exit 1
|
||||
|
||||
- name: Cleanup Docker Compose
|
||||
if: always()
|
||||
run: |
|
||||
docker compose -f docker-compose/local/docker-compose.yaml down -v
|
||||
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
- name: Setup Bun
|
||||
uses: oven-sh/setup-bun@v2
|
||||
with:
|
||||
bun-version: latest
|
||||
bun-version: 1.4.2
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v6
|
||||
@@ -53,6 +53,9 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: bun install
|
||||
|
||||
- name: Compile i18n
|
||||
run: bun run i18n:compile
|
||||
|
||||
- name: Lint
|
||||
run: bun run lint
|
||||
|
||||
@@ -65,18 +68,42 @@ jobs:
|
||||
- name: Build NPM packages
|
||||
run: bun run build-npm
|
||||
|
||||
- name: Generate release notes
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
CHANGELOG_NOTES=$(bun run scripts/extract-changelog.ts "${{ env.RELEASE_TAG }}" 2>/dev/null || true)
|
||||
PR_NOTES=$(gh api "repos/${{ github.repository }}/releases/generate-notes" -f tag_name="${{ env.RELEASE_TAG }}" --jq .body 2>/dev/null || true)
|
||||
|
||||
{
|
||||
if [ -n "$CHANGELOG_NOTES" ]; then
|
||||
echo "$CHANGELOG_NOTES"
|
||||
echo ""
|
||||
echo "---"
|
||||
echo ""
|
||||
fi
|
||||
if [ -n "$PR_NOTES" ]; then
|
||||
echo "$PR_NOTES"
|
||||
fi
|
||||
} > /tmp/release-notes.md
|
||||
|
||||
- name: Create GitHub Release
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
if [ ! -s /tmp/release-notes.md ]; then
|
||||
NOTES_FLAG="--generate-notes"
|
||||
else
|
||||
NOTES_FLAG="--notes-file /tmp/release-notes.md"
|
||||
fi
|
||||
if gh release view "${{ env.RELEASE_TAG }}" >/dev/null 2>&1; then
|
||||
gh release edit "${{ env.RELEASE_TAG }}" \
|
||||
--title "${{ env.RELEASE_TAG }}" \
|
||||
--generate-notes
|
||||
$NOTES_FLAG
|
||||
else
|
||||
gh release create "${{ env.RELEASE_TAG }}" \
|
||||
--title "${{ env.RELEASE_TAG }}" \
|
||||
--generate-notes
|
||||
$NOTES_FLAG
|
||||
fi
|
||||
|
||||
- name: Upgrade npm for trusted publishing
|
||||
|
||||
@@ -4,6 +4,16 @@ on:
|
||||
push:
|
||||
branches: ['main']
|
||||
tags: ['v*']
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
tag:
|
||||
description: 'Docker image tag (e.g. feature-vaapi)'
|
||||
required: false
|
||||
type: string
|
||||
pr:
|
||||
description: 'Pull request number (e.g. 449)'
|
||||
required: false
|
||||
type: string
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
@@ -14,7 +24,10 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
id: checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ inputs.pr && format('refs/pull/{0}/head', inputs.pr) || github.ref }}
|
||||
|
||||
# Set up Docker Buildx
|
||||
- name: Set up Docker Buildx
|
||||
@@ -45,7 +58,11 @@ jobs:
|
||||
crpi-000nkafzu6xvpwsc.cn-hongkong.personal.cr.aliyuncs.com/shumai-one/shumai
|
||||
tags: |
|
||||
type=semver,pattern={{version}}
|
||||
type=ref,event=branch
|
||||
type=ref,event=branch,enable=${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && !inputs.pr && !inputs.tag) }}
|
||||
type=raw,value=pr-${{ inputs.pr }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.pr != '' && inputs.tag == '' }}
|
||||
type=raw,value=${{ inputs.tag }},enable=${{ github.event_name == 'workflow_dispatch' && inputs.tag != '' }}
|
||||
labels: |
|
||||
org.opencontainers.image.revision=${{ steps.checkout.outputs.commit }}
|
||||
|
||||
# Build and push Docker image
|
||||
- name: Build and push Docker image
|
||||
@@ -54,5 +71,6 @@ jobs:
|
||||
platforms: linux/amd64,linux/arm64
|
||||
context: .
|
||||
push: true
|
||||
provenance: false
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
|
||||
@@ -2,6 +2,8 @@ node_modules
|
||||
.bun
|
||||
dist
|
||||
out
|
||||
*.ccx
|
||||
!apps/premiere-uxp/shumai-premiere.ccx
|
||||
.DS_Store
|
||||
*.log
|
||||
.env
|
||||
@@ -11,6 +13,7 @@ data/
|
||||
*.db
|
||||
*.diff
|
||||
*.orig
|
||||
code_quality.md
|
||||
.agents
|
||||
|
||||
# Playwright
|
||||
@@ -18,3 +21,7 @@ data/
|
||||
/test-results/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
|
||||
# Paraglide JS
|
||||
packages/webui/paraglide
|
||||
|
||||
|
||||
+3
-1
@@ -3,7 +3,9 @@ dist
|
||||
.bun
|
||||
src/generated
|
||||
packages/db/src/generated
|
||||
packages/core/src/generated
|
||||
src/ui/components/ui
|
||||
packages/webui/paraglide
|
||||
*.md
|
||||
**/*.md
|
||||
**/*.md
|
||||
docs/changelog.mdx
|
||||
|
||||
@@ -14,9 +14,10 @@ Complete the task on that branch.
|
||||
|
||||
After finishing the work and verifying that all checks pass:
|
||||
|
||||
1. Stage and commit your changes.
|
||||
2. Push the branch to `origin`.
|
||||
3. Open a pull request using the GitHub CLI.
|
||||
1. Update `CHANGELOG.md` under `## [Unreleased]` for user-facing changes (see [Changelog Guidelines](#changelog-guidelines)).
|
||||
2. Stage and commit your changes.
|
||||
3. Push the branch to `origin`.
|
||||
4. Open a pull request using the GitHub CLI.
|
||||
|
||||
```bash
|
||||
git add .
|
||||
@@ -61,6 +62,19 @@ https://www.conventionalcommits.org/en/v1.0.0/#summary
|
||||
|
||||
---
|
||||
|
||||
## Changelog Guidelines
|
||||
|
||||
We maintain `CHANGELOG.md` following [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
Before opening a pull request, add an entry under `## [Unreleased]` for any user-facing changes:
|
||||
|
||||
- **End-User Friendly**: Make entries easy to understand for end users. For new features, explain what they actually do in plain language without heavy technical jargon. For bug fixes, describe what the bug was in a friendly, relatable way rather than focusing on internal code mechanics, file paths, or private symbols.
|
||||
- **Formatting**: `- **<scope>**: <Description>` (e.g. `- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status`).
|
||||
- **No PR Numbers**: Do not include PR numbers or links; the release pipeline automatically appends the detailed PR list.
|
||||
- **Internal Changes**: Routine refactors, test additions, or internal chores without external behavior changes may omit changelog updates.
|
||||
|
||||
---
|
||||
|
||||
## Pull Request Template
|
||||
|
||||
```md
|
||||
@@ -78,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.
|
||||
@@ -90,7 +111,8 @@ Add any additional context, caveats, or follow-up work.
|
||||
- `bun run format`
|
||||
- `bun run typecheck`
|
||||
- `bun run test`
|
||||
- `bun run test:e2e`
|
||||
- `bun run test:e2e:app`
|
||||
- `bun run test:e2e:webui`
|
||||
- `bun run test:e2e:workflow`
|
||||
|
||||
- **Backend Testing Mandate**: Every backend feature, service method, workflow, and activity MUST be accompanied by comprehensive tests. Logic-heavy code without corresponding test coverage is considered incomplete.
|
||||
@@ -282,6 +304,13 @@ describe('Team API', () => {
|
||||
- **Mocking**: Mock ONLY AI API calls. Do not mock S3, databases, or media/transcode extraction services.
|
||||
- Mock the AI response by spying on `AgentHarness.prototype.prompt`:
|
||||
|
||||
### Web App E2E Tests
|
||||
|
||||
- Located in `apps/web/e2e/**/*.spec.ts`, organized by domain under `tests/<domain>/` (e.g. `auth`, `project`).
|
||||
- Run via `bun run test:e2e:app`.
|
||||
- **Fixtures**: Use the `owner`, `project`, and `file` fixtures for setup — they seed data through API calls/DB (no slow UI setup). You can add more fixtures if necessary.
|
||||
- **Documentation**: Every test case MUST be documented in [`apps/web/e2e/README.md`](apps/web/e2e/README.md). Add or update the corresponding entry in the README whenever you add, rename, or remove a spec.
|
||||
|
||||
## Prisma Configuration & Migrations
|
||||
|
||||
- Schema: `packages/db/prisma/schema.prisma`
|
||||
@@ -314,7 +343,8 @@ We use `prisma-json-types-generator` to enforce strict type-safety for Prisma `J
|
||||
|
||||
- Development: Use `bun --bun run prisma migrate dev` to create and apply migrations during development.
|
||||
- Production: Use `bun --bun run prisma migrate deploy` to apply pending migrations in production environments.
|
||||
- **No Manual Migration Creation**: Never create migration SQL files or directories manually by hand. Always use Prisma CLI commands (e.g. `bun --bun run prisma migrate dev --create-only` to generate a migration template, or `bun --bun run prisma migrate dev`) so Prisma correctly tracks migration metadata and checksums.
|
||||
- **No Manual DDL Creation**: Never hand-write **schema (DDL) migration** files or directories. Always generate them with Prisma CLI (`bun --bun run prisma migrate dev --create-only` to create a template, then edit it if needed, or `bun --bun run prisma migrate dev` to apply) so Prisma correctly tracks migration metadata and checksums.
|
||||
- **Data Migrations Are Allowed**: Pure **data migration** SQL (no schema change) may be written by hand, but it MUST live inside a migration generated via `bun --bun run prisma migrate dev --create-only` so it is tracked and applied automatically.
|
||||
- **No Automatic Dev DB Reset**: Do not run `prisma migrate reset --force` or commands that force-reset the database automatically. If migrations become out of sync or a reset is required, stop executing, report the situation to the user, and present suggested manual cleanup/reset steps for the user to execute.
|
||||
|
||||
### Commands
|
||||
|
||||
+799
@@ -0,0 +1,799 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
### Fixed
|
||||
|
||||
### Changed
|
||||
|
||||
## [0.5.2] - 2026-10-13
|
||||
|
||||
### Added
|
||||
|
||||
* **3d asset**: Add support for 3D model files (.glb, .gltf, .obj, .fbx, .stl, .dae, .usd, .usda, .usdc, .usdz) with automated turntable video rendering, hover sprite scrubbing, and an interactive 3D turntable viewer featuring 360° ruler scrubbing and degree-based markup comments
|
||||
* **kanban**: Related assets on a task are now clickable, taking you directly to that file or folder in its project
|
||||
* **settings**: Add an Integrations section to Team Settings with dedicated configuration for Gotenberg Document Converter, supporting connection testing and environment variable override protection
|
||||
|
||||
### Fixed
|
||||
|
||||
* **transcode**: Fix an issue where portrait photos from cameras and phones appeared sideways in thumbnails, previews, watermarked share links and annotated snapshots, and were listed with their width and height swapped
|
||||
|
||||
### Changed
|
||||
|
||||
## [0.5.1] - 2026-10-06
|
||||
|
||||
### Added
|
||||
|
||||
* **notification**: Notification cards are now clickable, taking you directly to the relevant file
|
||||
* **transcode**: Add hardware decoding and GPU scaling support for NVIDIA NVENC, Intel QuickSync Video (QSV), Rockchip (RKMPP), and VA-API (Intel and AMD GPUs), significantly speeding up video proxy and HLS rendition generation across supported platforms. Set `SHUMAI_HW_DECODE=false` to turn hardware decoding off
|
||||
* **transcode**: Add `dcraw_emu` fallback to generate WebP previews for camera RAW files without embedded JPEG previews
|
||||
|
||||
### Fixed
|
||||
|
||||
### Changed
|
||||
|
||||
|
||||
## [0.5.0] - 2026-10-02
|
||||
|
||||
### Added
|
||||
|
||||
* **transcode**: Add configurable target resolution ladders (480p, 720p, 1080p, 1440p, 2160p) for MP4 Multi Resolutions transcoding in team settings, with unified resolution matching and lowest-resolution fallback for both MP4 and HLS
|
||||
* **transcode**: Add HLS live streaming with fMP4/CMAF adaptive bitrate ladders (480p, 720p, 1080p, 1440p, 2160p), configurable in Transcode Settings, with automatic quality switching, manual resolution selection in the video viewer, seamless rendition switching, and full watermarking support for shared links
|
||||
* **transcode**: Add basic camera RAW image support for popular camera formats (including Sony ARW, Canon CR2/CR3, Nikon NEF, Adobe DNG, Fujifilm RAF, and Panasonic RW2), extracting high-quality embedded JPEG previews and automatically applying camera orientation for fast thumbnail and proxy generation
|
||||
|
||||
### Fixed
|
||||
|
||||
- **asset**: Fix an issue where media files remained stuck in a perpetual "Preparing..." state when transcoding failed, by displaying a clear failed status and error details in the file list and file viewer
|
||||
|
||||
* **transcode**: Fix an issue where videos or audio-only files containing attached cover art or picture streams could cause transcoding to fail during poster generation or select a single static image instead of the video
|
||||
|
||||
* **webui**: Fix inconsistent video resolution labels across download menus, mobile file headers, and the video player by correctly deriving resolutions from the video's short side, including portrait videos and 480p videos
|
||||
|
||||
* **trash**: Fix an issue where the "Empty Trash" confirmation dialog would close immediately instead of showing a loading state while files were being permanently deleted
|
||||
|
||||
### Changed
|
||||
|
||||
* **settings**: Redesign team Video Transcoding settings with dedicated cards for Transcode Policy, Hardware Acceleration, and FFmpeg Threads, clearly explaining MP4 and HLS playback vs download behavior and storage implications
|
||||
* **settings**: Rename AI Settings group to Team AI Settings in settings navigation
|
||||
|
||||
## [0.4.9] - 2026-09-28
|
||||
|
||||
### Added
|
||||
|
||||
- **notification**: You can now receive notifications via email, with batched digest emails and configurable team-level SMTP settings
|
||||
- **transcode**: Add VA-API hardware acceleration support for Linux hosts and Docker environments with Intel and AMD GPUs, featuring automatic DRI render node discovery, variable bitrate control, and structured transcoding observability logs
|
||||
- **transcode**: Add automatic fallback to software transcoding (libx264) when hardware-accelerated video encoding encounters GPU resolution constraints or runtime driver errors
|
||||
- **docker**: Add modular hardware-accelerated transcoding presets matching Immich's compose configuration via `hwaccel.transcoding.yaml` with support for NVENC, QuickSync, RKMPP, and VA-API
|
||||
|
||||
### Fixed
|
||||
|
||||
### Changed
|
||||
|
||||
- **transcode**: Improve video poster selection using intelligent scene detection and color variance filtering to automatically skip black frames, fade-ins, and blank intros in favor of representative video content
|
||||
- **transcode**: Optimize video sprite generation for large and long videos using a concurrent fast-seek pool and image compositing, avoiding full-video decoding while preserving instant single-pass generation for short clips
|
||||
|
||||
## [0.4.8] - 2026-09-24
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Add HDR video proxy support: HDR videos automatically generate HDR video proxies and preview videos preserving HDR color characteristics, tone-mapped SDR thumbnails and posters, and automatic HDR player playback on supported displays with hardware EDR acceleration
|
||||
- **docs**: Add a Changelog section to the documentation site so users can explore release notes and updates directly in Mintlify
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Only show the center play button and darkened tint on initial video open before playback starts; once played, pausing or scrubbing back to start keeps the video canvas clean and unobstructed for review
|
||||
- **transcode**: Fix an issue where videos with orientation or rotation metadata (such as smartphone vertical videos) were incorrectly displayed with stretched aspect ratios in the video player
|
||||
- **cli**: Only manage and check PID files in daemon mode, preventing stale PID files, crash-loop conflicts, or spurious process checks during normal foreground and Docker execution
|
||||
|
||||
### Changed
|
||||
|
||||
- **transcode**: Improve video proxy visual quality and disable B-frames for smoother frame-by-frame seeking and scrubbing
|
||||
|
||||
|
||||
## [0.4.7] - 2026-09-19
|
||||
|
||||
### Added
|
||||
|
||||
- **changelog**: Introduce Keep a Changelog support, historical release summaries, and automated release notes extraction
|
||||
- **release**: Automatically populate GitHub release bodies from CHANGELOG.md and promote unreleased notes during version bumps
|
||||
- **settings**: Add FFmpeg threads slider to team media processing settings
|
||||
- **asset**: Show previews of a folder's contents and a "days left" countdown for each item in Recently Deleted
|
||||
- **asset**: Show the poster and hover preview for a video in the file list while it is still transcoding, with a gently pulsing cover (or an animated waiting circle before the poster is ready), "Uploading..."/"Preparing..." labels, and the duration hidden until it is ready
|
||||
|
||||
### Fixed
|
||||
|
||||
- **asset**: Fix an issue where moving a video to trash while it was still transcoding could cause it to lose its trashed status
|
||||
- **transcode**: Immediately stop background video processing and transcoding when a file is permanently deleted from the trash
|
||||
- **asset**: Fix proxy download filename using original file extension instead of proxy extension
|
||||
- **asset**: Fix an issue where deleting or restoring a version stack from the file list did nothing
|
||||
- **webui**: Center breadcrumb file action popup menu on the chevron icon
|
||||
|
||||
## [0.4.6] - 2026-09-17
|
||||
|
||||
### Added
|
||||
|
||||
- **comment**: Add emoji reaction support for comments ([#405](https://github.com/shumaiOne/shumai/pull/405))
|
||||
- **premiere-uxp**: Introduce Adobe Premiere Pro UXP plugin for Shumai ([#407](https://github.com/shumaiOne/shumai/pull/407))
|
||||
- **settings**: Add team appearance setting to hide agent features ([#411](https://github.com/shumaiOne/shumai/pull/411))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **premiere-uxp**: Preserve remote cloud storage presigned URLs in asset resolution ([#408](https://github.com/shumaiOne/shumai/pull/408))
|
||||
- **premiere-uxp**: Scope sequence links by server endpoint and surface sync errors ([#409](https://github.com/shumaiOne/shumai/pull/409))
|
||||
- **api**: Enforce SHUMAI_DEMO_MODE for API token and CLI requests ([#413](https://github.com/shumaiOne/shumai/pull/413))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add NLE export and Premiere Pro UXP plugin documentation ([#412](https://github.com/shumaiOne/shumai/pull/412))
|
||||
|
||||
## [0.4.5] - 2026-09-13
|
||||
|
||||
### Added
|
||||
|
||||
- **core**: Export comments to FCP, Premiere, Media Composer, and Resolve ([#400](https://github.com/shumaiOne/shumai/pull/400))
|
||||
- **webui**: Add NLE comments export and migrate export API to POST ([#401](https://github.com/shumaiOne/shumai/pull/401))
|
||||
- **webui**: Add space key quick preview for files and folders ([#402](https://github.com/shumaiOne/shumai/pull/402))
|
||||
- **webui**: Show comments count badge in file card preview area ([#403](https://github.com/shumaiOne/shumai/pull/403))
|
||||
- **agent**: Use deterministic storage keys for preset avatars ([#404](https://github.com/shumaiOne/shumai/pull/404))
|
||||
|
||||
## [0.4.4] - 2026-09-09
|
||||
|
||||
### Added
|
||||
|
||||
- **upload**: S3 multipart upload with offline resume and wake lock ([#391](https://github.com/shumaiOne/shumai/pull/391))
|
||||
- **transcode**: Optimize video operations using ffmpeg http range requests ([#393](https://github.com/shumaiOne/shumai/pull/393))
|
||||
- **agent**: Enable read_asset tool for autofill agent ([#396](https://github.com/shumaiOne/shumai/pull/396))
|
||||
- **sandbox**: Abstract SandboxService and hot-reload allowed domains ([#398](https://github.com/shumaiOne/shumai/pull/398))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **s3**: Stream downloadToFile and putObject to prevent OOM on large files ([#392](https://github.com/shumaiOne/shumai/pull/392))
|
||||
- **agent**: Pass agent thinkingLevel to session name generation ([#395](https://github.com/shumaiOne/shumai/pull/395))
|
||||
- **agent**: Restrict pageCount and duration recommendations to matching media types ([#397](https://github.com/shumaiOne/shumai/pull/397))
|
||||
- **transcode**: Co-locate screenshots and derived artifacts in asset storage directory ([#399](https://github.com/shumaiOne/shumai/pull/399))
|
||||
|
||||
## [0.4.3] - 2026-09-06
|
||||
|
||||
### Added
|
||||
|
||||
- **asset**: Record and display agent provenance on assets and audit logs ([#380](https://github.com/shumaiOne/shumai/pull/380))
|
||||
- **agent**: Store preset avatars as real files in s3 storage ([#381](https://github.com/shumaiOne/shumai/pull/381))
|
||||
- **agent**: Add built-in image and video generation tools and settings ([#382](https://github.com/shumaiOne/shumai/pull/382))
|
||||
- **media-generation**: Add gemini-omni-1.1-flash video model and redesign settings UI ([#383](https://github.com/shumaiOne/shumai/pull/383))
|
||||
- **settings**: Redesign image/video settings to provider dialog with model toggles ([#385](https://github.com/shumaiOne/shumai/pull/385))
|
||||
- **agent**: Add asset management tools and CLI commands ([#387](https://github.com/shumaiOne/shumai/pull/387))
|
||||
- **cli**: Control asset deletion via SHUMAI_ALLOW_DELETE env var ([#388](https://github.com/shumaiOne/shumai/pull/388))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Clamp file card creation info to 2 lines and show tooltip on hover ([#390](https://github.com/shumaiOne/shumai/pull/390))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **agents**: Add documentation for image and video generation settings ([#389](https://github.com/shumaiOne/shumai/pull/389))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **deps**: Upgrade bun to 1.4.2 and update packages ([#384](https://github.com/shumaiOne/shumai/pull/384))
|
||||
- **i18n**: Update paraglide-js to 2.25.0 and stop checking in generated code ([#386](https://github.com/shumaiOne/shumai/pull/386))
|
||||
|
||||
## [0.4.2] - 2026-09-03
|
||||
|
||||
### Added
|
||||
|
||||
- **chat**: Support markups, attachments, and timestamps in agent 1-to-1 chat ([#368](https://github.com/shumaiOne/shumai/pull/368))
|
||||
- **agent**: Move thread metadata to structured context XML ([#373](https://github.com/shumaiOne/shumai/pull/373))
|
||||
- **agent**: Improve timestamp precision and proxy selection for video screenshots ([#374](https://github.com/shumaiOne/shumai/pull/374))
|
||||
- **agent**: Support dynamic annotationId resolution across chat and comments ([#375](https://github.com/shumaiOne/shumai/pull/375))
|
||||
- **agent**: Consolidate media tools into read_asset and add S3 key support to download_asset ([#376](https://github.com/shumaiOne/shumai/pull/376))
|
||||
- **provider**: Optimize provider and model configuration management ([#377](https://github.com/shumaiOne/shumai/pull/377))
|
||||
- **provider**: Add provider and model sync feature with vendored generator ([#378](https://github.com/shumaiOne/shumai/pull/378))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **agent**: Set empty details in asset tool results to avoid data duplication ([#370](https://github.com/shumaiOne/shumai/pull/370))
|
||||
- **webui**: Strip styles and preserve multiline text on paste in chat input ([#371](https://github.com/shumaiOne/shumai/pull/371))
|
||||
- **agent**: Hide main comment sessions in dashboard sessions list ([#372](https://github.com/shumaiOne/shumai/pull/372))
|
||||
|
||||
### Changed
|
||||
|
||||
- **webui**: Use semantic system colors in notification settings ([#379](https://github.com/shumaiOne/shumai/pull/379))
|
||||
|
||||
## [0.4.1] - 2026-08-30
|
||||
|
||||
### Added
|
||||
|
||||
- **webui**: Add manage versions option to file card context menu ([#364](https://github.com/shumaiOne/shumai/pull/364))
|
||||
- **agent**: Refactor message context into unified shumai_message ([#365](https://github.com/shumaiOne/shumai/pull/365))
|
||||
- **webui**: Redesign comment attachment display into compact rows ([#366](https://github.com/shumaiOne/shumai/pull/366))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **asset,webui**: Disallow dropping version stacks onto files and version stacks ([#363](https://github.com/shumaiOne/shumai/pull/363))
|
||||
- **webui**: Prevent empty folder flash during initial loading ([#367](https://github.com/shumaiOne/shumai/pull/367))
|
||||
|
||||
### Changed
|
||||
|
||||
- **agent**: Remove executeAgentToolWorkflow and invoke core services directly ([#362](https://github.com/shumaiOne/shumai/pull/362))
|
||||
|
||||
## [0.4.0] - 2026-08-28
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Add hardware-accelerated video transcoding support ([#352](https://github.com/shumaiOne/shumai/pull/352))
|
||||
- **webui**: Truncate long file names with 100ms hover tooltip ([#355](https://github.com/shumaiOne/shumai/pull/355))
|
||||
- **webui**: Add simplified mobile-friendly layout for file and share lists ([#356](https://github.com/shumaiOne/shumai/pull/356))
|
||||
- **webui**: Add mobile friendly file detail and public share view ([#359](https://github.com/shumaiOne/shumai/pull/359))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **transcode**: Apply team hardware acceleration and source bitrate capping to watermark transcoding ([#353](https://github.com/shumaiOne/shumai/pull/353))
|
||||
- **share**: Hide and soft-delete symlinks when target assets are trashed ([#354](https://github.com/shumaiOne/shumai/pull/354))
|
||||
- **webui**: Fix breadcrumb file dropdown trigger stretching and alignment ([#360](https://github.com/shumaiOne/shumai/pull/360))
|
||||
- **webui**: Align mobile comment cards and thread vertical indicator ([#361](https://github.com/shumaiOne/shumai/pull/361))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Add SECURITY.md with a private disclosure path ([#357](https://github.com/shumaiOne/shumai/pull/357))
|
||||
|
||||
## [0.3.11] - 2026-08-25
|
||||
|
||||
### Added
|
||||
|
||||
- **auth**: Add admin password reset CLI command and reset password web UI ([#347](https://github.com/shumaiOne/shumai/pull/347))
|
||||
- **project**: Add recent viewed files section to project folder tree ([#348](https://github.com/shumaiOne/shumai/pull/348))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Prevent left carousel remounting and scroll jump on file selection ([#351](https://github.com/shumaiOne/shumai/pull/351))
|
||||
|
||||
## [0.3.10] - 2026-08-23
|
||||
|
||||
### Added
|
||||
|
||||
- **agentic kanban**: Phase 1 not-agentic kanban board ([#330](https://github.com/shumaiOne/shumai/pull/330))
|
||||
- **kanban**: Resolve latest version for linked version stack assets and update demo login text ([#342](https://github.com/shumaiOne/shumai/pull/342))
|
||||
- **kanban**: Update task status permissions, reporter defaults, and participant access ([#345](https://github.com/shumaiOne/shumai/pull/345))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **kanban**: Use true thumbnail and poster for task asset previews ([#343](https://github.com/shumaiOne/shumai/pull/343))
|
||||
- **webui**: Sidebar selection styling, kanban active state, pointer cursors, and owner dashboard ([#344](https://github.com/shumaiOne/shumai/pull/344))
|
||||
- **kanban**: Improve drag-drop to column bottom, remove empty drop line, and fix timeline alignment ([#346](https://github.com/shumaiOne/shumai/pull/346))
|
||||
|
||||
## [0.3.9] - 2026-08-18
|
||||
|
||||
### Added
|
||||
|
||||
- **agent**: Add permission controls for chat agents ([#313](https://github.com/shumaiOne/shumai/pull/313))
|
||||
- **authz**: Enforce project-aware roles for agent/skill/mcp permissions ([#314](https://github.com/shumaiOne/shumai/pull/314))
|
||||
- **webui**: Use project members for asset comment mentions ([#315](https://github.com/shumaiOne/shumai/pull/315))
|
||||
- **quota**: Add 2-level database-backed resource quota system ([#318](https://github.com/shumaiOne/shumai/pull/318))
|
||||
- **settings**: Reorganize settings into personal, team, and AI sections ([#324](https://github.com/shumaiOne/shumai/pull/324))
|
||||
- **quota**: Move usage monitoring to team dashboard ([#327](https://github.com/shumaiOne/shumai/pull/327))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Preserve selected chatbot agent preference on reload ([#323](https://github.com/shumaiOne/shumai/pull/323))
|
||||
- **quota**: Exclude agents from quota rules and usage records ([#325](https://github.com/shumaiOne/shumai/pull/325))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **team-settings**: Add resource quotas documentation and update readme features ([#326](https://github.com/shumaiOne/shumai/pull/326))
|
||||
|
||||
## [0.3.8] - 2026-08-15
|
||||
|
||||
### Added
|
||||
|
||||
- **webui**: Replace legacy markdown editor with new lexical wysiwyg editor ([#308](https://github.com/shumaiOne/shumai/pull/308))
|
||||
- **agent**: Add nested agents.md support across backend and webui ([#309](https://github.com/shumaiOne/shumai/pull/309))
|
||||
- **webui**: Improve AGENTS.md editor placeholder and read-only notice ([#310](https://github.com/shumaiOne/shumai/pull/310))
|
||||
- **version-stack**: Add manage versions dialog and version removal ([#311](https://github.com/shumaiOne/shumai/pull/311))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **core**: Rename latest version child record on version stack rename ([#312](https://github.com/shumaiOne/shumai/pull/312))
|
||||
|
||||
## [0.3.7] - 2026-08-14
|
||||
|
||||
### Added
|
||||
|
||||
- **metadata**: Replace aiAutofill boolean with autofillSource enum ([#302](https://github.com/shumaiOne/shumai/pull/302))
|
||||
- **agent**: Type-safe CREATION_CONTEXT metadata on create_file/create_version ([#303](https://github.com/shumaiOne/shumai/pull/303))
|
||||
- **sandbox**: Default Network Sandbox to off and add settings toggle switch ([#304](https://github.com/shumaiOne/shumai/pull/304))
|
||||
- **webui**: Redesign select metadata fields and improve long text field widget ([#305](https://github.com/shumaiOne/shumai/pull/305))
|
||||
- **agent**: Support dynamic newOption in select and selectMulti metadata fields ([#306](https://github.com/shumaiOne/shumai/pull/306))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Fix select field height and multi-select overflow/interaction issues ([#307](https://github.com/shumaiOne/shumai/pull/307))
|
||||
|
||||
## [0.3.6] - 2026-08-12
|
||||
|
||||
### Added
|
||||
|
||||
- **mcp**: Add MCP server support with proxy tool and OAuth flow ([#289](https://github.com/shumaiOne/shumai/pull/289))
|
||||
- **mcp**: Support tool-level directTools array and 3-state UI configuration ([#297](https://github.com/shumaiOne/shumai/pull/297))
|
||||
- **webui**: Direct canvas PDF rendering with selectable text ([#299](https://github.com/shumaiOne/shumai/pull/299))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **agent**: Prevent agents from accessing disabled skills ([#292](https://github.com/shumaiOne/shumai/pull/292))
|
||||
- **agent**: Resolve version stack name and size in list_assets ([#296](https://github.com/shumaiOne/shumai/pull/296))
|
||||
- **webui**: Content-only pinch-zoom and two-finger pan in media viewers ([#298](https://github.com/shumaiOne/shumai/pull/298))
|
||||
- **i18n**: Update Chinese translation for dashboard to 仪表板 ([#301](https://github.com/shumaiOne/shumai/pull/301))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **mcp**: Add MCP support documentation to README and docs ([#300](https://github.com/shumaiOne/shumai/pull/300))
|
||||
|
||||
## [0.3.5] - 2026-08-09
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Add Gotenberg support for Office, HTML, CSV, and Markdown PDF proxies ([#283](https://github.com/shumaiOne/shumai/pull/283))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Resolve upload card freeze for unsupported files ([#284](https://github.com/shumaiOne/shumai/pull/284))
|
||||
- **webui**: Exclude file extension when selecting file name during inline rename ([#285](https://github.com/shumaiOne/shumai/pull/285))
|
||||
- Use renamed asset name in download Content-Disposition ([#286](https://github.com/shumaiOne/shumai/pull/286))
|
||||
- **webui**: Batch download no longer flashes a tab per file ([#287](https://github.com/shumaiOne/shumai/pull/287))
|
||||
- **webui**: Enable rename and delete actions in file detail top bar breadcrumb ([#288](https://github.com/shumaiOne/shumai/pull/288))
|
||||
|
||||
## [0.3.4] - 2026-08-08
|
||||
|
||||
### Added
|
||||
|
||||
- **sharelink**: Add sharelink watermark support ([#270](https://github.com/shumaiOne/shumai/pull/270))
|
||||
- **webui**: Remove original-file display fallbacks, use proxies only ([#273](https://github.com/shumaiOne/shumai/pull/273))
|
||||
- **share**: Add allow download config to share links ([#275](https://github.com/shumaiOne/shumai/pull/275))
|
||||
- **transcode**: Update preview thumbnail resolution to 300p with max length constraint ([#281](https://github.com/shumaiOne/shumai/pull/281))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **share**: Resolve symlink asset downloads in public share pages ([#274](https://github.com/shumaiOne/shumai/pull/274))
|
||||
- **webui**: Persist project sorting and prevent full page flash ([#276](https://github.com/shumaiOne/shumai/pull/276))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **share-links**: Document allow download and lazy watermark settings ([#278](https://github.com/shumaiOne/shumai/pull/278))
|
||||
- **agent**: Clarify create_file/create_version context param guidance ([#282](https://github.com/shumaiOne/shumai/pull/282))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **e2e**: Watermarked download-disabled share link coverage (image + video) ([#277](https://github.com/shumaiOne/shumai/pull/277))
|
||||
- **e2e**: Stabilize watermark share spec on Firefox ([#279](https://github.com/shumaiOne/shumai/pull/279))
|
||||
- Split e2e scripts into app and webui targets ([#280](https://github.com/shumaiOne/shumai/pull/280))
|
||||
|
||||
## [0.3.3] - 2026-08-05
|
||||
|
||||
### Added
|
||||
|
||||
- **agent**: Enable LLM API call retries in AgentHarness ([#250](https://github.com/shumaiOne/shumai/pull/250))
|
||||
- **audit**: Add audit log support for APIs and WebUI dashboard ([#251](https://github.com/shumaiOne/shumai/pull/251))
|
||||
- **webui**: Persist agent preference in localStorage ([#254](https://github.com/shumaiOne/shumai/pull/254))
|
||||
- **e2e**: Add file domain comment and draw tests ([#260](https://github.com/shumaiOne/shumai/pull/260))
|
||||
- **agent**: Restrict bash access for non-owner users ([#262](https://github.com/shumaiOne/shumai/pull/262))
|
||||
- **agent**: Allow create_file tool to create files directly from content ([#263](https://github.com/shumaiOne/shumai/pull/263))
|
||||
- **agent**: Propagate autofill context from chat to autofill workflow ([#264](https://github.com/shumaiOne/shumai/pull/264))
|
||||
- **webui**: Render select options in field creation mode and pick random option color ([#265](https://github.com/shumaiOne/shumai/pull/265))
|
||||
- **project**: Include team-scoped members in project member list and add 3-section dialog layout ([#267](https://github.com/shumaiOne/shumai/pull/267))
|
||||
- **webui**: Disable role dropdown for project-scoped members in team view ([#269](https://github.com/shumaiOne/shumai/pull/269))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Mention popup avatars, keyboard auto-scroll, and non-sticky section headers ([#256](https://github.com/shumaiOne/shumai/pull/256))
|
||||
- **webui**: Persist field order on drag and drop ([#266](https://github.com/shumaiOne/shumai/pull/266))
|
||||
|
||||
### Changed
|
||||
|
||||
- **agent**: Load models directly from database without pi fallback ([#253](https://github.com/shumaiOne/shumai/pull/253))
|
||||
- **core**: Replace generated provider files with pi-ai dynamic methods ([#255](https://github.com/shumaiOne/shumai/pull/255))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **core**: Add missing tests for methods introduced in 97069042 ([#252](https://github.com/shumaiOne/shumai/pull/252))
|
||||
- **e2e**: Add domain-based auth and project web app e2e tests ([#257](https://github.com/shumaiOne/shumai/pull/257))
|
||||
- **e2e**: Add file, share, and collection web app e2e tests ([#258](https://github.com/shumaiOne/shumai/pull/258))
|
||||
- **e2e**: Add project-level invite and file-move e2e tests ([#259](https://github.com/shumaiOne/shumai/pull/259))
|
||||
- **e2e**: Add search in file list and save-search-as-collection cases ([#261](https://github.com/shumaiOne/shumai/pull/261))
|
||||
- **e2e**: Add member permission change tests ([#268](https://github.com/shumaiOne/shumai/pull/268))
|
||||
|
||||
## [0.3.2] - 2026-07-30
|
||||
|
||||
### Added
|
||||
|
||||
- **agent**: Add output truncation and streaming limits to sandboxed bash tool ([#248](https://github.com/shumaiOne/shumai/pull/248))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **agent**: Download original document asset instead of pdf proxy ([#247](https://github.com/shumaiOne/shumai/pull/247))
|
||||
- **webui**: Persist chatbot sidebar input text across route navigation ([#249](https://github.com/shumaiOne/shumai/pull/249))
|
||||
|
||||
## [0.3.1] - 2026-07-30
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Trigger ai metadata autofill post transcode ([#234](https://github.com/shumaiOne/shumai/pull/234))
|
||||
- **dashboard**: Add agent sessions view for team owners ([#237](https://github.com/shumaiOne/shumai/pull/237))
|
||||
- **db**: Preserve agent sessions on asset deletion by setting onDelete to SetNull ([#240](https://github.com/shumaiOne/shumai/pull/240))
|
||||
- **agent**: Add download_asset tool and prompt instructions ([#242](https://github.com/shumaiOne/shumai/pull/242))
|
||||
- **db**: Update Asset.sizeByte and AiUsage token fields to BigInt ([#244](https://github.com/shumaiOne/shumai/pull/244))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **agent**: Include select option labels and field name in autofill schema ([#235](https://github.com/shumaiOne/shumai/pull/235))
|
||||
- **agent**: Scope agent comment sessions to thread sessions anchored at root comments ([#239](https://github.com/shumaiOne/shumai/pull/239))
|
||||
- **agent**: Disable tools for session naming and make naming non-blocking ([#241](https://github.com/shumaiOne/shumai/pull/241))
|
||||
- **webui**: Update file size formatting to SI decimal standard ([#245](https://github.com/shumaiOne/shumai/pull/245))
|
||||
- **s3**: Enforce property syntax in S3Service interface and fix ReadableStream handling in S3StorageService ([#246](https://github.com/shumaiOne/shumai/pull/246))
|
||||
|
||||
## [0.3.0] - 2026-07-28
|
||||
|
||||
### Added
|
||||
|
||||
- **file-browser**: Add copy name and path option to context menu ([#225](https://github.com/shumaiOne/shumai/pull/225))
|
||||
- **agent**: Inject user name and role into chat context ([#226](https://github.com/shumaiOne/shumai/pull/226))
|
||||
- **agent**: Refactor database session storage to normalized DAG entries and lazy thread sync ([#229](https://github.com/shumaiOne/shumai/pull/229))
|
||||
- **agent**: Support ENABLE_WEAKER_NESTED_SANDBOX environment variable ([#233](https://github.com/shumaiOne/shumai/pull/233))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **agent**: Ensure atomic appendEntry and persist leaf entries in DatabaseSessionStorage ([#224](https://github.com/shumaiOne/shumai/pull/224))
|
||||
- Sharp version mismatch bug ([#230](https://github.com/shumaiOne/shumai/pull/230))
|
||||
- **agent**: Resolve S3 MIME type detection and prompt parameter in image analysis ([#232](https://github.com/shumaiOne/shumai/pull/232))
|
||||
|
||||
### Changed
|
||||
|
||||
- **agent**: Remove implicit agent mention trigger in comment threads ([#227](https://github.com/shumaiOne/shumai/pull/227))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **workflow**: Add docker compose deployment verification job ([#231](https://github.com/shumaiOne/shumai/pull/231))
|
||||
|
||||
## [0.2.3] - 2026-07-25
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Show right sidebar by default on file detail page ([#219](https://github.com/shumaiOne/shumai/pull/219))
|
||||
- **webui**: Refresh file list and detail when agent executes asset creation tools ([#220](https://github.com/shumaiOne/shumai/pull/220))
|
||||
- **webui**: Fix space key drag overlay and shift range selection for version stacks ([#221](https://github.com/shumaiOne/shumai/pull/221))
|
||||
- **transcode**: Handle timestamp rounding tolerance for screenshot annotations ([#223](https://github.com/shumaiOne/shumai/pull/223))
|
||||
|
||||
### Changed
|
||||
|
||||
- **e2e**: Split transcode workflow E2E tests into per-workflow test files ([#222](https://github.com/shumaiOne/shumai/pull/222))
|
||||
|
||||
## [0.2.2] - 2026-07-23
|
||||
|
||||
### Added
|
||||
|
||||
- **webui**: Integrate AI usage API into dashboard page ([#216](https://github.com/shumaiOne/shumai/pull/216))
|
||||
- **ai-usage**: Add team and member token usage tracking and APIs ([#215](https://github.com/shumaiOne/shumai/pull/215))
|
||||
- **transcode**: Add PSD support via ImageMagick and enforce sRGB conversion ([#217](https://github.com/shumaiOne/shumai/pull/217))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **search**: Fix buildSqlCondition date range, numeric metadata, and string parsing bugs ([#213](https://github.com/shumaiOne/shumai/pull/213))
|
||||
- **webui**: Prevent horizontal overflow in search dialog result rows ([#214](https://github.com/shumaiOne/shumai/pull/214))
|
||||
- **webui**: Invalidate upload tasks query when upload task starts and completes ([#218](https://github.com/shumaiOne/shumai/pull/218))
|
||||
|
||||
## [0.2.1] - 2026-07-22
|
||||
|
||||
### Added
|
||||
|
||||
- **skill**: Add team owner skill permission control ([#209](https://github.com/shumaiOne/shumai/pull/209))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **agent**: Handle non-builtin models in getModelFromDb and upgrade pi-ai ([#211](https://github.com/shumaiOne/shumai/pull/211))
|
||||
- **provider**: Preserve model ids on provider update ([#212](https://github.com/shumaiOne/shumai/pull/212))
|
||||
|
||||
### Changed
|
||||
|
||||
- **core**: Split generated providers into per-provider files ([#210](https://github.com/shumaiOne/shumai/pull/210))
|
||||
|
||||
## [0.2.0] - 2026-07-21
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Add PDF preview, sprite generation, and annotation support ([#193](https://github.com/shumaiOne/shumai/pull/193))
|
||||
- **web**: Register pdf.worker route in production ([#195](https://github.com/shumaiOne/shumai/pull/195))
|
||||
- **agent**: Add read_pdf_pages tool and PDF page context support ([#196](https://github.com/shumaiOne/shumai/pull/196))
|
||||
- **transcode**: Split monolithic transcodeMedia into focused workflows ([#197](https://github.com/shumaiOne/shumai/pull/197))
|
||||
- **transcode**: Add PDF proxy support for TXT and CSV files ([#199](https://github.com/shumaiOne/shumai/pull/199))
|
||||
- **asset**: Replace mediaType/mimeType logic with proxyType ([#200](https://github.com/shumaiOne/shumai/pull/200))
|
||||
- **docker**: Install fonts-noto-cjk in runner stage ([#202](https://github.com/shumaiOne/shumai/pull/202))
|
||||
- **transcode**: Add markdown file to pdf proxy support ([#203](https://github.com/shumaiOne/shumai/pull/203))
|
||||
- **chat**: Track context asset changes and update agent context ([#204](https://github.com/shumaiOne/shumai/pull/204))
|
||||
- **agent**: Refactor media tools to static injection with mandatory assetId and authz ([#208](https://github.com/shumaiOne/shumai/pull/208))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **transcode**: Mark pdfkit as external and extract for docker runtime ([#201](https://github.com/shumaiOne/shumai/pull/201))
|
||||
- **agent**: Include skill id in formatSkillsForPrompt ([#205](https://github.com/shumaiOne/shumai/pull/205))
|
||||
- **asset**: Exclude soft-deleted children from latestChildren preview ([#206](https://github.com/shumaiOne/shumai/pull/206))
|
||||
- **agent**: Pass latest version asset from version stack to prompt builder ([#207](https://github.com/shumaiOne/shumai/pull/207))
|
||||
|
||||
## [0.1.10] - 2026-07-16
|
||||
|
||||
### Added
|
||||
|
||||
- **workflow-e2e**: Add E2E tests for agentAutofillMedia workflow ([#188](https://github.com/shumaiOne/shumai/pull/188))
|
||||
- **comments**: Support comment deletion and video player shortcuts ([#191](https://github.com/shumaiOne/shumai/pull/191))
|
||||
- **agent**: Support disabling specific tools for agents ([#192](https://github.com/shumaiOne/shumai/pull/192))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **e2e**: Add E2E workflow tests for remaining agent and transcode services ([#189](https://github.com/shumaiOne/shumai/pull/189))
|
||||
|
||||
## [0.1.9] - 2026-07-14
|
||||
|
||||
### Added
|
||||
|
||||
- **e2e**: Set up fullstack app-level e2e test framework and signup test case ([#184](https://github.com/shumaiOne/shumai/pull/184))
|
||||
- **chat**: Chatbot UI ([#185](https://github.com/shumaiOne/shumai/pull/185))
|
||||
- **agent**: Support aborting agent execution ([#186](https://github.com/shumaiOne/shumai/pull/186))
|
||||
|
||||
### Changed
|
||||
|
||||
- **api/chat**: Remove direct Prisma query from API layer ([#187](https://github.com/shumaiOne/shumai/pull/187))
|
||||
|
||||
## [0.1.8] - 2026-07-10
|
||||
|
||||
### Added
|
||||
|
||||
- **chatbot**: Implement type-safe Chat APIs with compaction support ([#180](https://github.com/shumaiOne/shumai/pull/180))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Enable build splitting and code-split all page routes ([#183](https://github.com/shumaiOne/shumai/pull/183))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **readme**: Clarify displayed file size represents original file size ([#182](https://github.com/shumaiOne/shumai/pull/182))
|
||||
|
||||
## [0.1.7] - 2026-07-06
|
||||
|
||||
### Added
|
||||
|
||||
- **audio**: Support frame-accurate audio playback, comments, and AI safeguards ([#175](https://github.com/shumaiOne/shumai/pull/175))
|
||||
- **i18n**: Localize members dialog, notifications, uploads, user menus, dates, and players ([#178](https://github.com/shumaiOne/shumai/pull/178))
|
||||
- **comments**: Allow marking comments as complete or incomplete ([#179](https://github.com/shumaiOne/shumai/pull/179))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **upload**: Resolve empty and generic MIME types in confirmFileUpload ([#176](https://github.com/shumaiOne/shumai/pull/176))
|
||||
|
||||
### Changed
|
||||
|
||||
- **webui**: Modularize file viewer components into registry-driven architecture ([#174](https://github.com/shumaiOne/shumai/pull/174))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Improve documentation and examples for S3 compatible storage ([#177](https://github.com/shumaiOne/shumai/pull/177))
|
||||
|
||||
## [0.1.6] - 2026-07-04
|
||||
|
||||
### Added
|
||||
|
||||
- **file-browser**: Show video duration on file card preview ([#170](https://github.com/shumaiOne/shumai/pull/170))
|
||||
- **webui**: Compare versions view for version stacks ([#171](https://github.com/shumaiOne/shumai/pull/171))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Resolve conditional hooks and setState-in-render errors ([#167](https://github.com/shumaiOne/shumai/pull/167))
|
||||
- **webui**: Resolve video player total frames mismatch ([#172](https://github.com/shumaiOne/shumai/pull/172))
|
||||
- **version-stack**: Resolve correct latest version ID of version stack ([#173](https://github.com/shumaiOne/shumai/pull/173))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **webui**: Video player e2e framework + Safari playhead fix ([#166](https://github.com/shumaiOne/shumai/pull/166))
|
||||
- **webui**: Add frame-accurate comment seek roundtrip e2e ([#168](https://github.com/shumaiOne/shumai/pull/168))
|
||||
- **webui**: Verify video player restarts playback after end ([#169](https://github.com/shumaiOne/shumai/pull/169))
|
||||
|
||||
## [0.1.5] - 2026-07-02
|
||||
|
||||
### Changed
|
||||
|
||||
- **storage**: Use original filenames for stored files ([#165](https://github.com/shumaiOne/shumai/pull/165))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **release**: Add Aliyun ACR push to release workflow ([#164](https://github.com/shumaiOne/shumai/pull/164))
|
||||
|
||||
## [0.1.4] - 2026-07-01
|
||||
|
||||
### Added
|
||||
|
||||
- **transcode**: Change video poster resolution to 480p ([#161](https://github.com/shumaiOne/shumai/pull/161))
|
||||
- **auth**: Allow setting user locale on signup ([#163](https://github.com/shumaiOne/shumai/pull/163))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Preserve video ended state by skipping playhead snap on ended ([#162](https://github.com/shumaiOne/shumai/pull/162))
|
||||
|
||||
## [0.1.3] - 2026-06-30
|
||||
|
||||
### Added
|
||||
|
||||
- **webui**: Add i18n support using paraglide-js ([#156](https://github.com/shumaiOne/shumai/pull/156))
|
||||
- **video**: Add frame-accurate video player, SMPTE timecodes, and format switcher ([#157](https://github.com/shumaiOne/shumai/pull/157))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Align video timeline duration and formatting with frameio ([#158](https://github.com/shumaiOne/shumai/pull/158))
|
||||
- **webui**: Fix missing left sidebar for nested folders ([#159](https://github.com/shumaiOne/shumai/pull/159))
|
||||
- **api**: Fix update team settings and make request schema type-safe ([#160](https://github.com/shumaiOne/shumai/pull/160))
|
||||
|
||||
## [0.1.2] - 2026-06-25
|
||||
|
||||
### Changed
|
||||
|
||||
- **s3**: Remove automatic port appending to AWS_ENDPOINT_URL_S3 ([#155](https://github.com/shumaiOne/shumai/pull/155))
|
||||
|
||||
## [0.1.1] - 2026-06-23
|
||||
|
||||
### Added
|
||||
|
||||
- **docker**: Add root entrypoint with privilege dropping for data volumes ([#151](https://github.com/shumaiOne/shumai/pull/151))
|
||||
|
||||
## [0.1.0] - 2026-06-22
|
||||
|
||||
### Added
|
||||
|
||||
- **share**: Secure share info API and fix wrong password feedback ([#150](https://github.com/shumaiOne/shumai/pull/150))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Truncate long folder, collection, and share link names in sidebar ([#149](https://github.com/shumaiOne/shumai/pull/149))
|
||||
|
||||
## [0.0.11] - 2026-06-22
|
||||
|
||||
### Added
|
||||
|
||||
- **cli**: Add shumai-cli and token authentication ([#144](https://github.com/shumaiOne/shumai/pull/144))
|
||||
- **settings**: Use singular headers and remove collapse/counters for single agent types ([#145](https://github.com/shumaiOne/shumai/pull/145))
|
||||
- **folders**: Auto expand folder tree in left sidebar on navigation ([#146](https://github.com/shumaiOne/shumai/pull/146))
|
||||
- **metadata**: Add single user and multiple user custom fields ([#147](https://github.com/shumaiOne/shumai/pull/147))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **cli**: Rename npm package to @shumai-one/shumai-cli ([#148](https://github.com/shumaiOne/shumai/pull/148))
|
||||
|
||||
## [0.0.10] - 2026-06-21
|
||||
|
||||
### Changed
|
||||
|
||||
- **web**: Dynamically register production HTML bundle routes ([#142](https://github.com/shumaiOne/shumai/pull/142))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **readme**: Polish structure, correct grammar, and add dependencies table ([#143](https://github.com/shumaiOne/shumai/pull/143))
|
||||
|
||||
## [0.0.9] - 2026-06-20
|
||||
|
||||
### Added
|
||||
|
||||
- **webui**: Show app version in avatar menu ([#139](https://github.com/shumaiOne/shumai/pull/139))
|
||||
- **cli**: Add background daemonization and subcommands ([#141](https://github.com/shumaiOne/shumai/pull/141))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- **release**: Add smoke tests to local release stage ([#140](https://github.com/shumaiOne/shumai/pull/140))
|
||||
|
||||
## [0.0.8] - 2026-06-19
|
||||
|
||||
### Added
|
||||
|
||||
- **api**: Implement read-only mode for reviewers ([#122](https://github.com/shumaiOne/shumai/pull/122))
|
||||
- **server**: Allow customizing server port via SHUMAI_SERVER_PORT ([#124](https://github.com/shumaiOne/shumai/pull/124))
|
||||
- **embedding**: Defer embedding workflow, use transcoded assets, and execute chunks in separate activities ([#125](https://github.com/shumaiOne/shumai/pull/125))
|
||||
- **webui**: Add external drag-and-drop file and folder upload support ([#126](https://github.com/shumaiOne/shumai/pull/126))
|
||||
- **agent**: Implement overlapping video chunks for semantic search ([#127](https://github.com/shumaiOne/shumai/pull/127))
|
||||
- **webui**: Support jumping to video timestamp from search results ([#128](https://github.com/shumaiOne/shumai/pull/128))
|
||||
- **auth**: Add demo mode support ([#131](https://github.com/shumaiOne/shumai/pull/131))
|
||||
- **auth**: Refine demo mode support ([#132](https://github.com/shumaiOne/shumai/pull/132))
|
||||
- **webui**: Default right sidebar to collapsed for new users ([#133](https://github.com/shumaiOne/shumai/pull/133))
|
||||
- **webui**: Use Shadcn Switch in toggle field and Rating component in search filter panel ([#137](https://github.com/shumaiOne/shumai/pull/137))
|
||||
- **upload**: Track byte-level progress with XMLHttpRequest ([#138](https://github.com/shumaiOne/shumai/pull/138))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **transcode**: Handle high-precision FPS using rational fractions ([#123](https://github.com/shumaiOne/shumai/pull/123))
|
||||
- **db**: Automatically update project updatedAt on asset modification ([#129](https://github.com/shumaiOne/shumai/pull/129))
|
||||
- **webui**: Use system colors for fields and improve search filter select options ([#130](https://github.com/shumaiOne/shumai/pull/130))
|
||||
- **search**: Fix hasAny and hasNone operators on metadata filter ([#134](https://github.com/shumaiOne/shumai/pull/134))
|
||||
- **webui**: Resolve folder tree sync, search dialog reset, and sidebar actions issues ([#136](https://github.com/shumaiOne/shumai/pull/136))
|
||||
|
||||
### Changed
|
||||
|
||||
- **webui**: Fix search dialog layout height, scroll areas, and restrict filter toggle click ([#135](https://github.com/shumaiOne/shumai/pull/135))
|
||||
|
||||
## [0.0.7] - 2026-06-17
|
||||
|
||||
### Added
|
||||
|
||||
- **workflow**: Configure transcode and agent concurrency via environment variables ([#116](https://github.com/shumaiOne/shumai/pull/116))
|
||||
- **webui**: Replace hardcoded colors with system tokens ([#119](https://github.com/shumaiOne/shumai/pull/119))
|
||||
- **webui**: Replace native overflow with shadcn ScrollArea in settings ([#120](https://github.com/shumaiOne/shumai/pull/120))
|
||||
- **api**: Use enum for API protocol in provider config ([#121](https://github.com/shumaiOne/shumai/pull/121))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **webui**: Reload video player and reset state when switching assets ([#114](https://github.com/shumaiOne/shumai/pull/114))
|
||||
|
||||
### Changed
|
||||
|
||||
- **transcode**: Relocate TranscodeService to core and flatten API package ([#115](https://github.com/shumaiOne/shumai/pull/115))
|
||||
|
||||
### Documentation
|
||||
|
||||
- Improve and restructure shumai documentation ([#118](https://github.com/shumaiOne/shumai/pull/118))
|
||||
|
||||
## [0.0.6] - 2026-06-15
|
||||
|
||||
### Added
|
||||
|
||||
- **sandbox**: Add pending domains support for network sandbox ([#109](https://github.com/shumaiOne/shumai/pull/109))
|
||||
- **webui**: Always show right sidebar and implement left vertical carousel ([#111](https://github.com/shumaiOne/shumai/pull/111))
|
||||
|
||||
### Fixed
|
||||
|
||||
- **build**: Propagate termination signals to active child process in wrappers ([#102](https://github.com/shumaiOne/shumai/pull/102))
|
||||
- **transcode**: Make deterministic transcode activity failures non-retryable in Temporal ([#104](https://github.com/shumaiOne/shumai/pull/104))
|
||||
- **player**: Implement seekbar dragging and match hover highlight color ([#108](https://github.com/shumaiOne/shumai/pull/108))
|
||||
- **webui**: Avoid refetching all pages on file/folder reorder ([#112](https://github.com/shumaiOne/shumai/pull/112))
|
||||
- **webui**: Force video-player mime type to video/mp4 ([#113](https://github.com/shumaiOne/shumai/pull/113))
|
||||
|
||||
### Changed
|
||||
|
||||
- **webui**: Use system color design tokens in video player components ([#106](https://github.com/shumaiOne/shumai/pull/106))
|
||||
- **webui**: Use requestAnimationFrame for smooth video progress bar updates ([#107](https://github.com/shumaiOne/shumai/pull/107))
|
||||
- **webui**: Fetch agents in mention input list dynamically ([#110](https://github.com/shumaiOne/shumai/pull/110))
|
||||
|
||||
### Documentation
|
||||
|
||||
- **readme**: Add comprehensive README.md ([#103](https://github.com/shumaiOne/shumai/pull/103))
|
||||
- **readme**: Improve remote deployment and temporal execution instructions ([#105](https://github.com/shumaiOne/shumai/pull/105))
|
||||
|
||||
## [0.0.5] - 2026-06-13
|
||||
|
||||
### Added
|
||||
|
||||
- **npm**: Auto deploy database migrations on package start ([#101](https://github.com/shumaiOne/shumai/pull/101))
|
||||
|
||||
## [0.0.4] - 2026-06-12
|
||||
|
||||
### Fixed
|
||||
|
||||
- **cli/docker**: Resolve global CLI external dependencies and fix Docker 404 error ([#100](https://github.com/shumaiOne/shumai/pull/100))
|
||||
|
||||
## [0.0.3] - 2026-06-12
|
||||
|
||||
### Fixed
|
||||
|
||||
- **cli**: Resolve platform binary path resolution under nested node_modules ([#99](https://github.com/shumaiOne/shumai/pull/99))
|
||||
|
||||
## [0.0.2] - 2026-06-12
|
||||
|
||||
### Fixed
|
||||
|
||||
- **npm**: Add repository metadata to package.json for provenance verification ([#98](https://github.com/shumaiOne/shumai/pull/98))
|
||||
|
||||
### Maintenance
|
||||
|
||||
- Add release-npm.yaml workflow ([#97](https://github.com/shumaiOne/shumai/pull/97))
|
||||
|
||||
## [0.0.1] - 2026-06-12
|
||||
|
||||
### Added
|
||||
|
||||
- Initial release of Shumai
|
||||
+29
-9
@@ -1,6 +1,6 @@
|
||||
#syntax=docker/dockerfile:1.7-labs
|
||||
# Stage 1: Builder
|
||||
FROM oven/bun:1 AS builder
|
||||
FROM oven/bun:1.4.2 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
@@ -8,6 +8,7 @@ WORKDIR /app
|
||||
COPY package.json bun.lock ./
|
||||
COPY --parents packages/*/package.json ./
|
||||
COPY --parents apps/*/package.json ./
|
||||
COPY patches/ ./patches/
|
||||
|
||||
# Install dependencies (including devDependencies for build tools)
|
||||
RUN bun install --frozen-lockfile
|
||||
@@ -17,6 +18,9 @@ RUN ls -la packages/transcode/node_modules
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Compile i18n
|
||||
RUN bun run i18n:compile
|
||||
|
||||
# Build API and Worker
|
||||
RUN bun run build.ts
|
||||
|
||||
@@ -24,13 +28,9 @@ RUN bun run build.ts
|
||||
RUN bun run scripts/extract-runtime-deps.ts
|
||||
|
||||
# Stage 2: Runner
|
||||
FROM oven/bun:1 AS runner
|
||||
FROM oven/bun:1.4.2 AS runner
|
||||
|
||||
# Install ffmpeg/ffprobe
|
||||
COPY --from=mwader/static-ffmpeg:8.1 /ffmpeg /usr/local/bin/
|
||||
COPY --from=mwader/static-ffmpeg:8.1 /ffprobe /usr/local/bin/
|
||||
|
||||
# Install system dependencies for sandbox runtime and agent
|
||||
# Install system dependencies and Jellyfin-FFmpeg (with VA-API support)
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
python3 \
|
||||
make \
|
||||
@@ -52,11 +52,26 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
poppler-utils \
|
||||
imagemagick \
|
||||
fonts-noto-cjk \
|
||||
libraw-bin \
|
||||
libimage-exiftool-perl \
|
||||
&& . /etc/os-release \
|
||||
&& TARGETARCH=$(dpkg --print-architecture) \
|
||||
&& FFMPEG_VERSION="8.1.2-5" \
|
||||
&& curl -fsSL -o /tmp/jellyfin-ffmpeg.deb "https://github.com/jellyfin/jellyfin-ffmpeg/releases/download/v${FFMPEG_VERSION}/jellyfin-ffmpeg8_${FFMPEG_VERSION}-${VERSION_CODENAME}_${TARGETARCH}.deb" \
|
||||
&& apt-get install -y --no-install-recommends /tmp/jellyfin-ffmpeg.deb \
|
||||
&& rm -f /tmp/jellyfin-ffmpeg.deb \
|
||||
&& ldconfig /usr/lib/jellyfin-ffmpeg/lib \
|
||||
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/local/bin/ffmpeg \
|
||||
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffprobe /usr/local/bin/ffprobe \
|
||||
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffmpeg /usr/bin/ffmpeg \
|
||||
&& ln -sf /usr/lib/jellyfin-ffmpeg/ffprobe /usr/bin/ffprobe \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set up working directory and make it owned by the bun user
|
||||
RUN mkdir -p /app/data && chown -R bun:bun /app
|
||||
# Set up working directory and make it owned by the bun user, ensure video/render group access
|
||||
RUN usermod -a -G video,render bun 2>/dev/null || true \
|
||||
&& mkdir -p /app/data \
|
||||
&& chown -R bun:bun /app
|
||||
|
||||
# Switch to the non-root bun user
|
||||
USER bun
|
||||
@@ -79,6 +94,11 @@ USER root
|
||||
COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||||
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
||||
|
||||
# Expose "bun index.js" as "shumai" CLI command (and alias "shuami")
|
||||
RUN printf '#!/bin/sh\nexec bun /app/index.js "$@"\n' > /usr/local/bin/shumai \
|
||||
&& chmod +x /usr/local/bin/shumai \
|
||||
&& ln -s /usr/local/bin/shumai /usr/local/bin/shuami
|
||||
|
||||
ENTRYPOINT ["docker-entrypoint.sh"]
|
||||
|
||||
# Default command: run migrations and start API server
|
||||
|
||||
@@ -5,34 +5,67 @@
|
||||
<h1 align="center">Shumai</h1>
|
||||
|
||||
<p align="center">
|
||||
<strong>An open-source platform for all your creative work.</strong>
|
||||
<strong>The best open-source Frame.io alternative for all your creative work.</strong>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://shumai.one/">Website</a> | <a target="_blank" href="https://docs.shumai.one/introduction">Docs</a> | <a target="_blank" href="https://staging.shumai.one">Demo</a> | <a target="_blank" href="https://discord.gg/sUzhujK6DD">Discord</a> | <a target="_blank" href="README_CN.md">中文</a>
|
||||
<a href="https://hub.docker.com/r/shumaione/shumai"><img alt="Docker pulls" src="https://img.shields.io/docker/pulls/shumaione/shumai" /></a>
|
||||
<a href="https://github.com/shumaiOne/shumai/releases"><img alt="GitHub latest release" src="https://img.shields.io/github/v/release/shumaiOne/shumai" /></a>
|
||||
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
||||
<a target="_blank" href="https://deepwiki.com/shumaiOne/shumai"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://shumai.one/">Website</a> | <a target="_blank" href="https://docs.shumai.one/getting-started/overview">Docs</a> | <a target="_blank" href="https://staging.shumai.one">Demo</a> | <a target="_blank" href="https://discord.gg/sUzhujK6DD">Discord</a> | <a target="_blank" href="README_CN.md">中文</a>
|
||||
</p>
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
||||
- **S3-Compatible & Local Storage**: Securely store and serve your creative assets using a local filesystem or any S3-compatible cloud storage (AWS S3, Cloudflare R2, MinIO, etc.).
|
||||
- **Frame-by-Frame Annotations & Comments**: Give precise feedback using frame-specific drawing tools and timestamped comments directly on video and image assets.
|
||||
- **Secure Sharing & Collections**: Create secure public share links and curated media collections to collaborate with clients and stakeholders.
|
||||
- **Granular Access Control**: Manage workspace permissions using team-level and project-level role-based access controls.
|
||||
- **Distributed Transcoding via Temporal**: Offload resource-heavy video transcoding to a background worker pool orchestrated by Temporal.
|
||||
- **Custom Asset Metadata**: Define and customize dynamic metadata fields tailored to your production pipeline.
|
||||
Shumai is an open-source Frame.io alternative built for creative teams to collaborate and share media with ease:
|
||||
|
||||
* **S3-Compatible & Local Storage**: Store and serve creative assets securely using the local filesystem or any S3-compatible storage service, including AWS S3, Cloudflare R2, and MinIO.
|
||||
* **Frame-by-Frame Annotations & Comments**: Leave precise feedback with frame-specific drawing tools and timestamped comments on both video and image assets.
|
||||
* **Secure Sharing & Collections**: Create private share links and curated media collections for clients, stakeholders, and collaborators.
|
||||
* **Granular Access Control**: Manage workspace permissions with team-level and project-level role-based access control.
|
||||
* **Distributed Transcoding via Temporal**: Offload resource-intensive video transcoding to a background worker pool orchestrated by Temporal.
|
||||
* **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).
|
||||
|
||||
But Shumai goes beyond being a Frame.io alternative. With modern models like GPT-Image-2 and Seedance 2.5, AI can already handle a surprising amount of creative work. That means you can create or update videos and images from a simple prompt without having to jump back into Photoshop, Premiere or Houdini. That is why Shumai includes a powerful agent system:
|
||||
|
||||
> **AI is optional.** You can use Shumai as a traditional Frame.io alternative and completely ignore the AI features if they aren't useful for your team.
|
||||
|
||||
* **Agent as a Team Member**: Mention a context-aware AI agent with `@mentions` directly in asset comments, just like a real teammate.
|
||||
* **Agent as a One-to-One Assistant**: Chat privately with the agent and ask it to help with tasks.
|
||||
* **Custom Skills & Tools**: Extend the agent by registering custom scripts, tools, and automation skills.
|
||||
* **Model Context Protocol (MCP)**: Connect agents to external tools and APIs through remote MCP servers, with OAuth authentication and per-agent MCP access.
|
||||
* **Isolated Sandbox Execution**: Run agent-submitted scripts safely in a sandboxed environment.
|
||||
* **AI Metadata Autofill**: Automatically fill in custom metadata for new assets.
|
||||
* **Semantic Search**: Find assets by visual or conceptual meaning using vector embeddings (Gemini Embedding 2).
|
||||
* **Resource Quotas**: Set usage limits on AI tokens, costs, and tool execution per member, role, or team-wide, with real-time tracking.
|
||||
|
||||
Here is a short demo video showing what the Shumai agent can do:
|
||||
|
||||
|
||||
|
||||
https://github.com/user-attachments/assets/1186067a-72c0-41b9-836f-987438f2332a
|
||||
|
||||
Shumai also brings project management into the creative workflow. A built-in Kanban board helps teams organize tasks, track progress, and collaborate in one place.
|
||||
|
||||
The ultimate goal is an **agentic Kanban**, where agents and team members can work together on tasks. This is still a **work in progress**: you can already create tasks for AI agents, but agents cannot act on those tasks yet.
|
||||
|
||||
<img width="2880" height="2160" alt="localhost_3000_teams_01M0HQR3EEBS0B46K4FK39X2C8_kanban(1080p-2) (1)" src="https://github.com/user-attachments/assets/cd0648d0-c69a-4398-958b-8d15a33378b0" />
|
||||
|
||||
#### Shumai Agent
|
||||
|
||||
- **Collaborative AI Chat**: Converse with a context-aware AI agent by using `@mentions` directly within the file's comments area.
|
||||
- **Custom Skills & Tools**: Extend the agent's capabilities by registering custom scripts, tools, and automation skills.
|
||||
- **Isolated Sandbox Execution**: Run agent-submitted scripts securely within a sandboxed environment.
|
||||
- **AI Metadata Autofill**: Automatically autofill custom metadata for new assets.
|
||||
- **Semantic Search**: Find assets based on visual or conceptual search queries using vector embeddings(Gemini Embedding 2).
|
||||
|
||||
> [!NOTE]
|
||||
> **Media Processing & Storage:** When uploading media, Shumai always preserves and stores your original raw file. Note that the file size shown in the system represents the original file size and does not include the size of any transcoded files. For all media types (both images and videos), Shumai creates a 480p WebP poster image to serve as the preview in the file list view. Additionally:
|
||||
> **Media Processing & Storage:** When uploading media, Shumai always preserves and stores your original raw file. Note that the file size shown in the system represents the original file size and does not include the size of any transcoded files. For all media types (both images and videos), Shumai creates a 300p WebP poster image to serve as the preview in the file list view. Additionally:
|
||||
> * **For Images:** Shumai generates a high-quality WebP proxy at the exact same resolution as your original file for optimized viewing.
|
||||
> * **For Videos:** It generates at least one proxy video (depending on your transcoding settings), alongside a sprite image and a small preview video (capped at 1600 frames) to enable fast timeline scrubbing and lightning-quick previews.
|
||||
|
||||
@@ -54,6 +87,9 @@ Docker Compose is the fastest way to get Shumai running. You do not need to clon
|
||||
```bash
|
||||
curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/docker-compose.yaml
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> By default, the standard `docker-compose.yaml` uses CPU software transcoding. If your server has a GPU (NVIDIA NVENC, Intel QuickSync, AMD/Intel VA-API, or Rockchip RKMPP) and you want to enable GPU hardware acceleration, check the [Hardware Transcoding Guide](https://docs.shumai.one/configuration/hardware-transcoding).
|
||||
3. Configure environment variables (optional):
|
||||
|
||||
* `SHUMAI_SERVER_PORT` controls the port the Shumai server listens on. The default is `3000`.
|
||||
@@ -127,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]
|
||||
@@ -166,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
|
||||
```
|
||||
|
||||
---
|
||||
@@ -231,11 +269,14 @@ BETTER_AUTH_SECRET=ySxs7DxzHDZBbeeHNPEwBuspYwipBqz5Gk5XdBjNhWw=
|
||||
STORAGE_BACKEND=local
|
||||
SHUMAI_SERVER_PORT=3000
|
||||
AWS_ENDPOINT_URL_S3=http://localhost:3000
|
||||
# Optional: base URL for MCP OAuth redirects (defaults to BETTER_AUTH_URL)
|
||||
MCP_OAUTH_REDIRECT_BASE_URL=http://localhost:3000
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> `SHUMAI_SERVER_PORT` sets the port the server starts on, while `AWS_ENDPOINT_URL_S3` is used by the browser to build file upload URLs.
|
||||
> If deploying on a remote server (e.g. `http://123.456.7.8`) with a mapped port (e.g. `12345:3000` in docker-compose), set `AWS_ENDPOINT_URL_S3` to `http://123.456.7.8:12345`.
|
||||
> `MCP_OAUTH_REDIRECT_BASE_URL` is only needed when MCP servers use OAuth: the authorization redirect URI defaults to `{BETTER_AUTH_URL}/api/mcp/oauth/callback`; set it to an externally reachable URL if the app is served behind a proxy.
|
||||
|
||||
#### Step 6: Run Shumai
|
||||
|
||||
@@ -283,11 +324,17 @@ To set up Shumai locally for development:
|
||||
```
|
||||
2. Start the `pgvector` database container (as described in **Option 2, Step 1**).
|
||||
3. Create a `.env` file at the root of the workspace using the configuration from **Option 2, Step 5**.
|
||||
4. Apply the database schema migrations:
|
||||
4. Generate i18n translation files:
|
||||
```bash
|
||||
bun run i18n:compile
|
||||
```
|
||||
> [!TIP]
|
||||
> During frontend development, you can run `bun run i18n:watch` in a separate terminal to automatically recompile translation files whenever you edit strings in `packages/webui/messages/`.
|
||||
5. Apply the database schema migrations:
|
||||
```bash
|
||||
bun run db:migrate
|
||||
```
|
||||
5. Start the local development server:
|
||||
6. Start the local development server:
|
||||
```bash
|
||||
bun run dev
|
||||
```
|
||||
|
||||
+79
-27
@@ -9,31 +9,58 @@
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://shumai.one/">官方网站</a> | <a target="_blank" href="https://docs.shumai.one/introduction">文档</a> | <a target="_blank" href="https://staging.shumai.one">在线演示</a> | <a target="_blank" href="README.md">English</a>
|
||||
<a href="https://hub.docker.com/r/shumaione/shumai"><img alt="Docker pulls" src="https://img.shields.io/docker/pulls/shumaione/shumai" /></a>
|
||||
<a href="https://github.com/shumaiOne/shumai/releases"><img alt="GitHub latest release" src="https://img.shields.io/github/v/release/shumaiOne/shumai" /></a>
|
||||
<a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-blue" /></a>
|
||||
<a target="_blank" href="https://deepwiki.com/shumaiOne/shumai"><img alt="Ask DeepWiki" src="https://deepwiki.com/badge.svg" /></a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a target="_blank" href="https://shumai.one/">官方网站</a> | <a target="_blank" href="https://docs.shumai.one/getting-started/overview">文档</a> | <a target="_blank" href="https://staging.shumai.one">在线演示</a> | <a target="_blank" href="README.md">English</a>
|
||||
</p>
|
||||
|
||||

|
||||
|
||||
## 功能特性
|
||||
## 功能
|
||||
|
||||
- **兼容 S3 与本地存储**:支持使用本地文件系统或任意兼容 S3 协议的对象存储(AWS S3、Cloudflare R2、MinIO 等)安全存储和访问你的创意资产。
|
||||
- **逐帧标注与评论**:可直接在图片和视频上进行逐帧绘制标注,并结合时间戳评论,实现精准反馈与协作。
|
||||
- **安全分享与媒体合集**:支持创建安全的公开分享链接和精心组织的媒体合集,方便与客户及团队成员协同沟通。
|
||||
- **细粒度权限控制**:基于团队和项目两级角色权限(RBAC),灵活管理工作区访问权限。
|
||||
- **基于 Temporal 的分布式转码**:将高负载的视频转码任务交由 Temporal 调度的后台 Worker 集群处理,提升系统扩展性与处理效率。
|
||||
- **自定义资产元数据**:支持定义和扩展动态元数据字段,灵活适配你的制作流程。
|
||||
Shumai 是一个开源的 Frame.io 替代方案,专为创意团队打造,让大家能更轻松地协作、审片和分享素材:
|
||||
|
||||
#### Shumai Agent
|
||||
* **支持 S3 和本地存储**:你可以把创意素材安全地存到本地文件系统,或者任意兼容 S3 的存储服务里,比如 AWS S3、Cloudflare R2、MinIO 等。
|
||||
* **逐帧标注和评论**:支持按帧进行精确反馈,可以直接在视频和图片素材上画重点、写评论,还能留下时间戳。
|
||||
* **安全分享和合集管理**:可以生成私密分享链接,也能整理成精选合集,方便给客户、同事和合作方查看。
|
||||
* **细粒度权限控制**:支持按团队、项目设置角色权限,方便管理不同成员的访问范围。
|
||||
* **基于 Temporal 的分布式转码**:把吃资源的视频转码任务交给后台 worker 池处理,由 Temporal 统一调度。
|
||||
* **自定义素材元数据**:可以按你的制作流程,自由定义动态元数据字段。
|
||||
* **分享链接水印**:通过可自定义的文字和图片水印保护共享媒体,并将水印配置保存为模板以便重复使用。
|
||||
* **丰富的文件格式支持**:支持预览常见创意文件格式,包括图片(支持 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)。
|
||||
|
||||
但 Shumai 不仅仅只满足于 Frame.io 的开源替代。随着 GPT-Image-2、Seedance 2.5 这类强大模型的问世,AI已经生成产品级的图片/视频。很多时候,你只要给一句提示词,就能直接生成或修改图片和视频,而不用再打开 Photoshop、Premiere 或者 Houdini。也正因为这样,Shumai 才把 AI Agent 做成了核心能力:
|
||||
|
||||
* **Agent 就像团队成员**:你可以在素材评论区里直接用 `@` 提到 AI Agent,像拉一个真实同事进来一起看稿一样。
|
||||
* **Agent 也能当你的私聊助手**:你可以单独和它聊天,让它帮你查东西、做任务。
|
||||
* **自定义技能和工具**:你可以给 Agent 接上自己的脚本、工具和自动化能力。
|
||||
* **Model Context Protocol (MCP) 支持**:通过远程 MCP 服务端为 Agent 接入外部工具与 API,支持 OAuth 鉴权与按 Agent 独立分配访问权限。
|
||||
* **沙箱隔离执行**:Agent 生成的脚本会在隔离环境里运行,更安全。
|
||||
* **AI 自动补全元数据**:新素材上传后,系统可以自动帮你补一些元数据。
|
||||
* **语义搜索**:支持按画面内容或语义找素材,底层用的是向量 embedding(Gemini Embedding 2)。
|
||||
* **资源配额**:支持按成员、角色或全团队对 AI Token、成本和工具调用设置使用上限与实时用量监控。
|
||||
|
||||
下面是一个简短的 demo 视频,展示了 Shumai Agent 能做什么:
|
||||
|
||||
https://github.com/user-attachments/assets/1186067a-72c0-41b9-836f-987438f2332a
|
||||
|
||||
Shumai 也将项目管理融入了创意工作流程。 内置的看板可以帮助团队整理任务以及跟踪进度。
|
||||
|
||||
最终目标是打造一个 Agentic看板,让 Agent 和团队成员能够围绕同一个目标协同工作。目前这一功能仍在开发中: 你已经可以在看板中为 Agent 创建任务,但 Agent 目前还无法自动执行这些任务。
|
||||
|
||||
<img width="2880" height="2160" alt="localhost_3000_teams_01M0HQR3EEBS0B46K4FK39X2C8_kanban(1080p-2) (1)" src="https://github.com/user-attachments/assets/29ff1db1-2d65-4e3c-b467-754b777b406f" />
|
||||
|
||||
- **协作式 AI 对话**:在文件评论区通过 `@mention` 即可唤起具备上下文感知能力的 AI Agent,参与讨论与协作。
|
||||
- **自定义技能与工具**:支持为 Agent 注册自定义脚本、工具和自动化技能,扩展其能力边界。
|
||||
- **隔离沙箱执行**:Agent 提交的脚本会在安全隔离的沙箱环境中运行,保障执行安全。
|
||||
- **AI 自动填充元数据**:为新上传的资产自动生成并填写自定义元数据。
|
||||
- **语义搜索**:基于向量进行搜索(Gemini Embedding 2),支持按视觉内容或语义概念搜索资产。
|
||||
|
||||
> [!NOTE]
|
||||
> **媒体处理与存储机制:** 上传媒体文件后,Shumai 始终会保留并存储原始文件。请注意,系统中显示的文件大小为原始文件的大小,不包含转码后生成的代理文件大小。无论图片还是视频,都会额外生成一张 480p 的 WebP 封面图,作为文件列表中的预览图。此外:
|
||||
> **媒体处理与存储机制:** 上传媒体文件后,Shumai 始终会保留并存储原始文件。请注意,系统中显示的文件大小为原始文件的大小,不包含转码后生成的代理文件大小。无论图片还是视频,都会额外生成一张 300p 的 WebP 封面图,作为文件列表中的预览图。此外:
|
||||
>
|
||||
> * **图片:** 会生成一份与原图分辨率完全一致的高质量 WebP 转码版本,在保证画质的同时提升浏览性能。
|
||||
> * **视频:** 会根据转码配置生成至少一个代理视频,同时生成雪碧图(Sprite)和一段最长 1600 帧的低分辨率转码视频,用于实现快速拖动时间轴和即时视频预览。
|
||||
@@ -45,6 +72,24 @@
|
||||
以下是使用本地存储运行 Shumai 的快速上手指南。如需了解高级配置(包括 S3 兼容存储配置、Temporal 工作流编排等),请参阅我们的[官方文档](https://docs.shumai.one/getting-started/overview)。
|
||||
|
||||
### 方案一:使用 Docker Compose(推荐)
|
||||
<details>
|
||||
|
||||
<summary>复制这个提示词,让agent帮你安装</summary>
|
||||
|
||||
```
|
||||
请帮我在本机使用 Docker Compose 一键部署 Shumai。
|
||||
|
||||
请严格参考官方文档:
|
||||
https://gh-proxy.com/https://raw.githubusercontent.com/shumaiOne/shumai/main/README_CN.md
|
||||
|
||||
要求:
|
||||
|
||||
1. 只能使用 Docker Compose local方式部署,不要使用其他部署方式。
|
||||
2. 部署前请先检查本机是否已安装并可正常使用 Docker 和 Docker Compose。
|
||||
3. 如果本机未安装 Docker,请立即提醒用户先安装 Docker,并停止后续部署操作。不要自行安装 Docker,也不要采用其他方式部署。
|
||||
4. 获取 `docker-compose-aliyun.yaml` 文件内容时,必须通过 `https://gh-proxy.com` 加速访问,不要直接访问 GitHub Raw 地址。
|
||||
```
|
||||
</details>
|
||||
|
||||
使用 Docker Compose 是运行 Shumai 最快的方式。您无需克隆仓库,也不需要手动安装依赖包。请确保电脑上已安装 [Docker](https://docs.docker.com/get-docker/) 和 [Docker Compose](https://docs.docker.com/compose/install/),然后按照以下步骤操作:
|
||||
|
||||
@@ -57,9 +102,11 @@
|
||||
2. 下载 `docker-compose.yaml` 配置文件:
|
||||
```bash
|
||||
curl -o docker-compose.yaml https://raw.githubusercontent.com/shumaiOne/shumai/main/docker-compose/local/docker-compose-aliyun.yaml
|
||||
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> 默认的 Docker Compose 配置使用基于 CPU 的软件转码。如果您的服务器配备了支持的显卡(NVIDIA NVENC、Intel QuickSync、AMD/Intel VA-API 或 Rockchip RKMPP)并需要开启 GPU 硬件加速转码,请参考 [硬件加速转码配置文档](https://docs.shumai.one/configuration/hardware-transcoding)。
|
||||
|
||||
|
||||
3. 配置环境变量(可选):
|
||||
* `SHUMAI_SERVER_PORT` 用于控制 Shumai 服务监听的端口,默认值为 `3000`。
|
||||
@@ -141,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]
|
||||
@@ -169,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`权限。
|
||||
|
||||
---
|
||||
|
||||
@@ -180,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
|
||||
```
|
||||
|
||||
---
|
||||
@@ -315,17 +364,20 @@ bun install
|
||||
|
||||
2. 启动 `pgvector` 数据库容器(参考**方案二中的第一步**)。
|
||||
3. 参照**方案二中的第五步**,在项目根目录下创建一个 `.env` 文件。
|
||||
4. 执行数据库结构迁移:
|
||||
4. 生成多语言国际化(i18n)代码:
|
||||
```bash
|
||||
bun run i18n:compile
|
||||
```
|
||||
> [!TIP]
|
||||
> 在前端开发过程中,可以在单独的终端窗口中运行 `bun run i18n:watch`,在修改 `packages/webui/messages/` 下的翻译文案时自动重新编译。
|
||||
|
||||
5. 执行数据库结构迁移:
|
||||
```bash
|
||||
bun run db:migrate
|
||||
|
||||
```
|
||||
|
||||
|
||||
5. 启动本地开发服务器:
|
||||
6. 启动本地开发服务器:
|
||||
```bash
|
||||
bun run dev
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
# Security Policy
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please report security vulnerabilities **privately**. Do not open a public issue,
|
||||
pull request or Discord message for a suspected vulnerability, as that discloses it
|
||||
to everyone before a fix exists.
|
||||
|
||||
Use **[GitHub private vulnerability reporting](https://github.com/shumaiOne/shumai/security/advisories/new)**
|
||||
(the "Report a vulnerability" button on the Security tab). If that is unavailable,
|
||||
contact the maintainer directly rather than in a public channel.
|
||||
|
||||
Please include:
|
||||
|
||||
- What the issue is, and the impact you believe it has
|
||||
- The version or commit you tested (`git rev-parse HEAD`, or the image digest)
|
||||
- Steps to reproduce, ideally minimal
|
||||
- Your deployment shape: storage backend, whether the agent feature is enabled,
|
||||
and whether the instance is internet-reachable
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Shumai is pre-1.0 and moves quickly. Security fixes are made against the **latest
|
||||
release**. Users are encouraged to track releases rather than pin indefinitely.
|
||||
|
||||
## Scope
|
||||
|
||||
**In scope** — the application, its API, the shipped Docker images, and the
|
||||
deployment manifests under `docker-compose/`.
|
||||
|
||||
Deployment manifests are explicitly in scope. A default that is unsafe when
|
||||
followed as documented is a real finding, because the documented quickstart is what
|
||||
most operators actually run.
|
||||
|
||||
**Out of scope**
|
||||
|
||||
- Vulnerabilities in third-party dependencies, unless Shumai's use of them is what
|
||||
creates the exposure. Report those upstream.
|
||||
- Findings that require an already-compromised host or database.
|
||||
- Configurations that deviate from the documented deployment.
|
||||
|
||||
## Operator guidance
|
||||
|
||||
Shumai is self-hosted, so several controls belong to the operator rather than to the
|
||||
project:
|
||||
|
||||
- **Set `BETTER_AUTH_SECRET` per deployment.** It signs sessions and, in local
|
||||
storage mode, upload URLs. Never reuse a value from documentation or an example.
|
||||
- **Do not expose the instance to the public internet without a reverse proxy**
|
||||
terminating TLS and applying your own access policy.
|
||||
- **Do not publish the database port.** Set a real database password.
|
||||
- **Treat the agent feature as a code-execution surface.** If you enable it, run it
|
||||
where a compromise is survivable, and review the sandbox network policy.
|
||||
|
||||
## Disclosure
|
||||
|
||||
Please allow a reasonable period for a fix before public disclosure. The maintainer
|
||||
will acknowledge reports and keep reporters informed of progress.
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/agent-app",
|
||||
"version": "0.2.2",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -4,6 +4,7 @@ loadEnvConfig(process.cwd(), process.env.NODE_ENV !== 'production')
|
||||
import { workflowService } from '@shumai/workflow-core'
|
||||
import { TaskQueueAgent } from '@shumai/workflow-core'
|
||||
import { initAgentWorkflows } from '@shumai/agent'
|
||||
import { sandboxService } from '@shumai/core'
|
||||
import { handleDaemonCommands } from '@shumai/core/src/utils/daemon'
|
||||
|
||||
if (process.argv.includes('--check')) {
|
||||
@@ -14,6 +15,9 @@ if (process.argv.includes('--check')) {
|
||||
async function run() {
|
||||
// Initialize workflows and activities
|
||||
initAgentWorkflows()
|
||||
await sandboxService.ensureInitialized().catch((err) => {
|
||||
console.error('Failed to eagerly initialize sandbox in agent worker:', err)
|
||||
})
|
||||
|
||||
console.log('🚀 Starting Agent Worker...')
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from '@shumai/agent/src/workflows/agent-autofill'
|
||||
export * from '@shumai/agent/src/workflows/agent-chat'
|
||||
export * from '@shumai/agent/src/workflows/agent-embedding'
|
||||
export * from '@shumai/agent/src/workflows/agent-tool-call'
|
||||
export * from '@shumai/agent/src/workflows/query-embedding-for-search'
|
||||
|
||||
@@ -20,6 +20,9 @@ export SHUMAI_API_SERVER="http://localhost:3000"
|
||||
|
||||
# Your personal API Token (Generate this in the WebUI via Settings -> Developer tab)
|
||||
export SHUMAI_API_KEY="your-developer-api-token"
|
||||
|
||||
# Optional: Enable asset deletion capability (disabled by default for safety)
|
||||
export SHUMAI_ALLOW_DELETE="true"
|
||||
```
|
||||
|
||||
---
|
||||
@@ -89,6 +92,37 @@ shumai-cli create-version <localFilePath> -p <parentAssetId>
|
||||
- **Options:**
|
||||
- `-p`, `--parent <id>`: The parent asset ID (file or version stack) to version (required).
|
||||
|
||||
#### 6. Rename an Asset
|
||||
|
||||
Rename an existing file or folder in Shumai.
|
||||
|
||||
```bash
|
||||
shumai-cli rename <assetId> <newName>
|
||||
```
|
||||
|
||||
#### 7. Move Assets
|
||||
|
||||
Move one or more assets (files or folders) to a destination parent folder. Note that all assets to be moved must belong to the same current parent folder.
|
||||
|
||||
```bash
|
||||
shumai-cli move <assetId...> -p <parentId>
|
||||
# or using the short alias:
|
||||
shumai-cli mv <assetId...> -p <parentId>
|
||||
```
|
||||
|
||||
- **Options:**
|
||||
- `-p`, `--parent <id>`: The destination parent folder ID (required).
|
||||
|
||||
#### 8. Delete an Asset
|
||||
|
||||
Delete a single file or folder by moving it to the Trash bin. For safety, this command only deletes one asset at a time and requires the `SHUMAI_ALLOW_DELETE="true"` environment variable to be set in your environment.
|
||||
|
||||
```bash
|
||||
shumai-cli delete <assetId>
|
||||
# or using the short alias:
|
||||
shumai-cli rm <assetId>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Development
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/cli",
|
||||
"version": "0.2.2",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
@@ -11,7 +11,7 @@
|
||||
"@shumai/core": "workspace:*",
|
||||
"@shumai/dtos": "workspace:*",
|
||||
"@shumai/tableprinter": "workspace:*",
|
||||
"hono": "4.12.23",
|
||||
"ulid": "^3.0.2"
|
||||
"hono": "4.13.5",
|
||||
"ulid": "3.0.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ import { mkdir } from './mkdir'
|
||||
import { getClient } from '../client'
|
||||
import { upload } from './upload'
|
||||
import { createVersion } from './create-version'
|
||||
import { rename } from './rename'
|
||||
import { move } from './move'
|
||||
import { deleteAsset } from './delete'
|
||||
import fs from 'node:fs'
|
||||
import http from 'node:http'
|
||||
|
||||
@@ -34,17 +37,29 @@ describe('CLI Commands', () => {
|
||||
$get: vi.fn(),
|
||||
':projectId': {
|
||||
$get: vi.fn(),
|
||||
reparent: {
|
||||
$post: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
folders: {
|
||||
$post: vi.fn(),
|
||||
$delete: vi.fn(),
|
||||
':folderId': {
|
||||
$get: vi.fn(),
|
||||
$put: vi.fn(),
|
||||
children: {
|
||||
$get: vi.fn(),
|
||||
},
|
||||
},
|
||||
},
|
||||
files: {
|
||||
$delete: vi.fn(),
|
||||
':fileId': {
|
||||
$get: vi.fn(),
|
||||
$put: vi.fn(),
|
||||
},
|
||||
},
|
||||
teams: {
|
||||
':teamId': {
|
||||
upload: {
|
||||
@@ -60,6 +75,8 @@ describe('CLI Commands', () => {
|
||||
},
|
||||
}
|
||||
|
||||
const originalAllowDelete = process.env.SHUMAI_ALLOW_DELETE
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks()
|
||||
logSpy = vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
@@ -79,6 +96,11 @@ describe('CLI Commands', () => {
|
||||
writeSpy.mockRestore()
|
||||
errorSpy.mockRestore()
|
||||
exitSpy.mockRestore()
|
||||
if (originalAllowDelete !== undefined) {
|
||||
process.env.SHUMAI_ALLOW_DELETE = originalAllowDelete
|
||||
} else {
|
||||
delete process.env.SHUMAI_ALLOW_DELETE
|
||||
}
|
||||
})
|
||||
|
||||
describe('project ls', () => {
|
||||
@@ -361,4 +383,192 @@ describe('CLI Commands', () => {
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('rename', () => {
|
||||
it('exits with error when assetId or newName is missing', async () => {
|
||||
await expect(rename('', 'new-name')).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Asset ID is required'))
|
||||
|
||||
await expect(rename('asset-1', '')).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('New name is required'))
|
||||
})
|
||||
|
||||
it('renames a folder when asset type is folder', async () => {
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'f-1', type: 'folder' }),
|
||||
} as unknown as Response)
|
||||
mockClient.api.folders[':folderId'].$put.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'f-1', name: 'Renamed Folder' }),
|
||||
} as unknown as Response)
|
||||
|
||||
await rename('f-1', 'Renamed Folder')
|
||||
|
||||
expect(mockClient.api.folders[':folderId'].$put).toHaveBeenCalledWith({
|
||||
param: { folderId: 'f-1' },
|
||||
json: { name: 'Renamed Folder' },
|
||||
})
|
||||
expect(logSpy).toHaveBeenCalledWith('Renamed asset f-1 to "Renamed Folder"')
|
||||
})
|
||||
|
||||
it('renames a file when asset type is file', async () => {
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'file-1', type: 'file' }),
|
||||
} as unknown as Response)
|
||||
mockClient.api.files[':fileId'].$put.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'file-1', name: 'new.mp4' }),
|
||||
} as unknown as Response)
|
||||
|
||||
await rename('file-1', 'new.mp4')
|
||||
|
||||
expect(mockClient.api.files[':fileId'].$put).toHaveBeenCalledWith({
|
||||
param: { fileId: 'file-1' },
|
||||
json: { name: 'new.mp4' },
|
||||
})
|
||||
expect(logSpy).toHaveBeenCalledWith('Renamed asset file-1 to "new.mp4"')
|
||||
})
|
||||
|
||||
it('exits with error when asset fetch fails', async () => {
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: false,
|
||||
json: async () => ({ error: 'Asset not found' }),
|
||||
} as unknown as Response)
|
||||
|
||||
await expect(rename('unknown-id', 'name')).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith('Error: Asset not found')
|
||||
})
|
||||
})
|
||||
|
||||
describe('move', () => {
|
||||
it('exits with error when assetIds or parentId is missing', async () => {
|
||||
await expect(move([], 'parent-1')).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('At least one asset ID is required'),
|
||||
)
|
||||
|
||||
await expect(move(['a-1'], '')).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
expect.stringContaining('Option -p/--parent <parentId> is required'),
|
||||
)
|
||||
})
|
||||
|
||||
it('successfully moves assets', async () => {
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'parent-1', projectId: 'proj-1' }),
|
||||
} as unknown as Response)
|
||||
mockClient.api.projects[':projectId'].reparent.$post.mockResolvedValue({
|
||||
ok: true,
|
||||
} as unknown as Response)
|
||||
|
||||
await move(['a-1', 'a-2'], 'parent-1')
|
||||
|
||||
expect(mockClient.api.projects[':projectId'].reparent.$post).toHaveBeenCalledWith({
|
||||
param: { projectId: 'proj-1' },
|
||||
json: {
|
||||
assetIds: ['a-1', 'a-2'],
|
||||
newParentId: 'parent-1',
|
||||
},
|
||||
})
|
||||
expect(logSpy).toHaveBeenCalledWith('Moved 2 asset(s) to parent parent-1')
|
||||
})
|
||||
|
||||
it('exits with error when destination parent is not found', async () => {
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: false,
|
||||
json: async () => ({ error: 'Folder not found' }),
|
||||
} as unknown as Response)
|
||||
|
||||
await expect(move(['a-1'], 'missing-parent')).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith('Error: Folder not found')
|
||||
})
|
||||
})
|
||||
|
||||
describe('deleteAsset', () => {
|
||||
it('exits with error when SHUMAI_ALLOW_DELETE is not set or not true', async () => {
|
||||
delete process.env.SHUMAI_ALLOW_DELETE
|
||||
await expect(deleteAsset(['a-1'])).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
'Error: Asset deletion is disabled in this environment.',
|
||||
)
|
||||
})
|
||||
|
||||
it('exits with error when assetIds is empty', async () => {
|
||||
process.env.SHUMAI_ALLOW_DELETE = 'true'
|
||||
await expect(deleteAsset([])).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith(expect.stringContaining('Asset ID is required'))
|
||||
})
|
||||
|
||||
it('exits with error when more than one asset ID is passed', async () => {
|
||||
process.env.SHUMAI_ALLOW_DELETE = 'true'
|
||||
await expect(deleteAsset(['a-1', 'a-2'])).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith('Error: Can only delete one asset at a time.')
|
||||
})
|
||||
|
||||
it('exits with error when asset is not found', async () => {
|
||||
process.env.SHUMAI_ALLOW_DELETE = 'true'
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: false,
|
||||
json: async () => ({ error: 'Asset not found' }),
|
||||
} as unknown as Response)
|
||||
|
||||
await expect(deleteAsset(['a-1'])).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith('Error: Asset not found')
|
||||
})
|
||||
|
||||
it('successfully deletes a file when SHUMAI_ALLOW_DELETE is true', async () => {
|
||||
process.env.SHUMAI_ALLOW_DELETE = 'true'
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'a-1', type: 'file' }),
|
||||
} as unknown as Response)
|
||||
mockClient.api.files.$delete.mockResolvedValue({
|
||||
ok: true,
|
||||
} as unknown as Response)
|
||||
|
||||
await deleteAsset(['a-1'])
|
||||
|
||||
expect(mockClient.api.files.$delete).toHaveBeenCalledWith({
|
||||
json: { ids: ['a-1'] },
|
||||
})
|
||||
expect(mockClient.api.folders.$delete).not.toHaveBeenCalled()
|
||||
expect(logSpy).toHaveBeenCalledWith('Deleted asset a-1')
|
||||
})
|
||||
|
||||
it('successfully deletes a folder when SHUMAI_ALLOW_DELETE is 1', async () => {
|
||||
process.env.SHUMAI_ALLOW_DELETE = '1'
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'folder-1', type: 'folder' }),
|
||||
} as unknown as Response)
|
||||
mockClient.api.folders.$delete.mockResolvedValue({
|
||||
ok: true,
|
||||
} as unknown as Response)
|
||||
|
||||
await deleteAsset(['folder-1'])
|
||||
|
||||
expect(mockClient.api.folders.$delete).toHaveBeenCalledWith({
|
||||
json: { ids: ['folder-1'] },
|
||||
})
|
||||
expect(logSpy).toHaveBeenCalledWith('Deleted asset folder-1')
|
||||
})
|
||||
|
||||
it('exits with error when delete API returns an error', async () => {
|
||||
process.env.SHUMAI_ALLOW_DELETE = 'true'
|
||||
mockClient.api.folders[':folderId'].$get.mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ id: 'a-1', type: 'file' }),
|
||||
} as unknown as Response)
|
||||
mockClient.api.files.$delete.mockResolvedValue({
|
||||
ok: false,
|
||||
json: async () => ({ error: 'Failed to delete' }),
|
||||
} as unknown as Response)
|
||||
|
||||
await expect(deleteAsset(['a-1'])).rejects.toThrow('process.exit(1)')
|
||||
expect(errorSpy).toHaveBeenCalledWith('Error: Failed to delete')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { getClient } from '../client'
|
||||
|
||||
export async function deleteAsset(assetIds: string[]) {
|
||||
const isAllowed =
|
||||
process.env.SHUMAI_ALLOW_DELETE === 'true' || process.env.SHUMAI_ALLOW_DELETE === '1'
|
||||
if (!isAllowed) {
|
||||
console.error('Error: Asset deletion is disabled in this environment.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (!assetIds || assetIds.length === 0) {
|
||||
console.error('Error: Asset ID is required. Usage: shumai-cli delete <assetId>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
if (assetIds.length > 1) {
|
||||
console.error('Error: Can only delete one asset at a time.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const assetId = assetIds[0]
|
||||
const client = getClient()
|
||||
|
||||
try {
|
||||
// Inspect asset to determine whether it is a folder or file
|
||||
const getRes = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: assetId },
|
||||
})
|
||||
|
||||
if (!getRes.ok) {
|
||||
const err = (await getRes.json().catch(() => ({ error: 'Asset not found' }))) as {
|
||||
error?: string
|
||||
}
|
||||
console.error(`Error: ${err.error || 'Asset not found'}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const asset = await getRes.json()
|
||||
const isFolder = asset.type === 'folder'
|
||||
|
||||
const res = isFolder
|
||||
? await client.api.folders.$delete({
|
||||
json: { ids: [assetId] },
|
||||
})
|
||||
: await client.api.files.$delete({
|
||||
json: { ids: [assetId] },
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const err = (await res.json().catch(() => ({ error: 'Failed to delete asset' }))) as {
|
||||
error?: string
|
||||
}
|
||||
console.error(`Error: ${err.error || 'Failed to delete asset'}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log(`Deleted asset ${assetId}`)
|
||||
} catch (err) {
|
||||
console.error('Error connecting to API server:', err instanceof Error ? err.message : err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import { getClient } from '../client'
|
||||
|
||||
export async function move(assetIds: string[], parentId: string) {
|
||||
if (!assetIds || assetIds.length === 0) {
|
||||
console.error(
|
||||
'Error: At least one asset ID is required. Usage: shumai-cli move <assetId...> -p <parentId>',
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
if (!parentId) {
|
||||
console.error('Error: Option -p/--parent <parentId> is required.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const client = getClient()
|
||||
|
||||
try {
|
||||
// Fetch destination folder to get its projectId
|
||||
const parentRes = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: parentId },
|
||||
})
|
||||
|
||||
if (!parentRes.ok) {
|
||||
const err = (await parentRes.json().catch(() => ({ error: 'Parent folder not found' }))) as {
|
||||
error?: string
|
||||
}
|
||||
console.error(`Error: ${err.error || 'Parent folder not found'}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const parentInfo = await parentRes.json()
|
||||
const projectId = parentInfo.projectId
|
||||
if (!projectId) {
|
||||
console.error('Error: Destination parent folder is not associated with a project.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const res = await client.api.projects[':projectId'].reparent.$post({
|
||||
param: { projectId },
|
||||
json: {
|
||||
assetIds,
|
||||
newParentId: parentId,
|
||||
},
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const err = (await res.json().catch(() => ({ error: 'Failed to move assets' }))) as {
|
||||
error?: string
|
||||
}
|
||||
console.error(`Error: ${err.error || 'Failed to move assets'}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log(`Moved ${assetIds.length} asset(s) to parent ${parentId}`)
|
||||
} catch (err) {
|
||||
console.error('Error connecting to API server:', err instanceof Error ? err.message : err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { getClient } from '../client'
|
||||
|
||||
export async function rename(assetId: string, newName: string) {
|
||||
if (!assetId) {
|
||||
console.error('Error: Asset ID is required. Usage: shumai-cli rename <assetId> <newName>')
|
||||
process.exit(1)
|
||||
}
|
||||
if (!newName) {
|
||||
console.error('Error: New name is required. Usage: shumai-cli rename <assetId> <newName>')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const client = getClient()
|
||||
|
||||
try {
|
||||
// Determine whether asset is a folder or a file
|
||||
const getRes = await client.api.folders[':folderId'].$get({
|
||||
param: { folderId: assetId },
|
||||
})
|
||||
|
||||
if (!getRes.ok) {
|
||||
const err = (await getRes.json().catch(() => ({ error: 'Asset not found' }))) as {
|
||||
error?: string
|
||||
}
|
||||
console.error(`Error: ${err.error || 'Asset not found'}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const asset = await getRes.json()
|
||||
const isFolder = asset.type === 'folder'
|
||||
|
||||
const updateRes = isFolder
|
||||
? await client.api.folders[':folderId'].$put({
|
||||
param: { folderId: assetId },
|
||||
json: { name: newName },
|
||||
})
|
||||
: await client.api.files[':fileId'].$put({
|
||||
param: { fileId: assetId },
|
||||
json: { name: newName },
|
||||
})
|
||||
|
||||
if (!updateRes.ok) {
|
||||
const err = (await updateRes.json().catch(() => ({ error: 'Failed to rename asset' }))) as {
|
||||
error?: string
|
||||
}
|
||||
console.error(`Error: ${err.error || 'Failed to rename asset'}`)
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
console.log(`Renamed asset ${assetId} to "${newName}"`)
|
||||
} catch (err) {
|
||||
console.error('Error connecting to API server:', err instanceof Error ? err.message : err)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
+37
-1
@@ -3,6 +3,9 @@ import { ls } from './commands/ls'
|
||||
import { mkdir } from './commands/mkdir'
|
||||
import { upload } from './commands/upload'
|
||||
import { createVersion } from './commands/create-version'
|
||||
import { rename } from './commands/rename'
|
||||
import { move } from './commands/move'
|
||||
import { deleteAsset } from './commands/delete'
|
||||
|
||||
function printHelp() {
|
||||
console.log(`
|
||||
@@ -14,9 +17,12 @@ Commands:
|
||||
mkdir <name> -p <parentId> Create a new folder in a parent folder
|
||||
upload <path> -p <parentId> Upload a local file or folder to a parent folder
|
||||
create-version <path> -p <id> Create a new version of an existing file or version stack
|
||||
rename <assetId> <newName> Rename an existing file or folder
|
||||
move <assetIds...> -p <target> Move one or more assets to a destination parent folder (alias: mv)
|
||||
delete <assetId> Delete a single file or folder (alias: rm)
|
||||
|
||||
Options:
|
||||
-p, --parent <id> The parent folder/asset ID (required for ls, mkdir, upload, create-version)
|
||||
-p, --parent <id> The parent folder/asset ID (required for ls, mkdir, upload, create-version, move)
|
||||
-h, --help Show help details
|
||||
`)
|
||||
}
|
||||
@@ -92,6 +98,36 @@ async function main() {
|
||||
process.exit(1)
|
||||
}
|
||||
await createVersion(localPath, parentId)
|
||||
} else if (cmd === 'rename') {
|
||||
const assetId = cleanArgs[1]
|
||||
const newName = cleanArgs[2]
|
||||
if (!assetId || !newName) {
|
||||
console.error(
|
||||
'Error: Asset ID and new name are required. Usage: shumai-cli rename <assetId> <newName>',
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
await rename(assetId, newName)
|
||||
} else if (cmd === 'move' || cmd === 'mv') {
|
||||
const assetIds = cleanArgs.slice(1)
|
||||
if (assetIds.length === 0) {
|
||||
console.error(
|
||||
'Error: At least one asset ID is required. Usage: shumai-cli move <assetId...> -p <parentId>',
|
||||
)
|
||||
process.exit(1)
|
||||
}
|
||||
if (!parentId) {
|
||||
console.error('Error: Option -p/--parent <parentId> is required.')
|
||||
process.exit(1)
|
||||
}
|
||||
await move(assetIds, parentId)
|
||||
} else if (cmd === 'delete' || cmd === 'rm') {
|
||||
const assetIds = cleanArgs.slice(1)
|
||||
if (assetIds.length === 0) {
|
||||
console.error('Error: Asset ID is required. Usage: shumai-cli delete <assetId>')
|
||||
process.exit(1)
|
||||
}
|
||||
await deleteAsset(assetIds)
|
||||
} else {
|
||||
console.error(`Error: Unknown command "${cmd}". Run "shumai-cli --help" for usage.`)
|
||||
process.exit(1)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# Premiere UXP Plugin Guidelines
|
||||
|
||||
## Component Library (Spectrum Web Components / SWC)
|
||||
|
||||
- **Always prefer SWC components if possible**: Use Spectrum Web Component React wrappers (`@swc-react/*`) and `@swc-uxp-wrappers/*` for UI elements (Button, ActionButton, Textfield, Card, Divider, ProgressCircle, StatusLight, Badge, Search, FieldLabel, HelpText, IllustratedMessage, ActionGroup, etc.) rather than hand-crafting custom HTML/CSS elements.
|
||||
- **SWC Support**: `public/manifest.json` has `"featureFlags": { "enableSWCSupport": true }`.
|
||||
- **Package Versions**: Keep SWC packages aligned at version `0.37.0` (matching Adobe UXP compatibility).
|
||||
- **Bundler Aliases**: `build.ts` uses `swcAliasPlugin` with `aliases` from `@swc-uxp-wrappers/utils` to resolve internal SWC imports for Bun.
|
||||
|
||||
## Icons
|
||||
|
||||
- **Always use Spectrum Workflow Icons (`@spectrum-web-components/icons-workflow`)**: Never use external icon libraries like `lucide-react`.
|
||||
- **Registration**: All workflow icons used must be imported and registered in `src/index.tsx` (e.g. `import '@spectrum-web-components/icons-workflow/icons/sp-icon-movie-camera.js'`). Note: Ensure the icon exists in `@spectrum-web-components/icons-workflow/icons/` (Spectrum 1 compatible) rather than only `icons-s2/` (which falls back to an empty circular DefaultIcon under Spectrum 1).
|
||||
- **Typing**: Add custom element declarations to `src/declarations.d.ts` under both `declare namespace React.JSX` and `declare global.JSX.IntrinsicElements` with `SpIconCustomElementProps`.
|
||||
|
||||
## Adobe UXP Layout Engine Rules (Critical CSS Gotchas)
|
||||
|
||||
Adobe UXP's layout engine (Yoga-based) does **not** support several standard modern CSS features:
|
||||
|
||||
1. **No CSS Grid**:
|
||||
- `display: grid` and `grid-template-columns` are **unsupported / invalid**.
|
||||
- Always use Flexbox (`display: flex; flex-direction: row | column;`).
|
||||
2. **No `aspect-ratio`**:
|
||||
- `aspect-ratio` is invalid in UXP and collapses containers to `0px` height.
|
||||
- Always specify explicit `width` and `height` on preview / thumbnail containers.
|
||||
3. **No `box-sizing: border-box`**:
|
||||
- `box-sizing` is not supported (UXP elements are natively border-box). Specifying it logs invalid property warnings.
|
||||
4. **No `gap` in Flexbox**:
|
||||
- `gap` is invalid in Premiere UXP flexbox. Items will render with 0px spacing.
|
||||
- Use `margin-bottom` or `margin-right` on child items for spacing.
|
||||
5. **Always Set `flex-shrink: 0` on List Items**:
|
||||
- Flex children default to `flex-shrink: 1`. When rendering lists with many items (>10 items), flexbox squishes the items down to slivers instead of scrolling.
|
||||
- Always add `flex-shrink: 0` and an explicit `min-height` to list row cards (`.project-row-card`, `.file-row-card`, `.item-row`, etc.).
|
||||
6. **Scroll Containers**:
|
||||
- Scrollable flex children (like `.view-content`) must have `min-height: 0` and `overflow-y: auto` to allow children to overflow and scroll vertically.
|
||||
|
||||
## Build and Packaging Commands
|
||||
|
||||
- **Build**: `bun run --filter @shumai/premiere-uxp build`
|
||||
- **Watch mode**: `bun run --filter @shumai/premiere-uxp dev`
|
||||
- **Package CCX**: `bun run --filter @shumai/premiere-uxp package` (outputs `apps/premiere-uxp/shumai-premiere.ccx`)
|
||||
@@ -0,0 +1,109 @@
|
||||
#!/usr/bin/env bun
|
||||
import { cp, rm, mkdir } from 'node:fs/promises'
|
||||
import { existsSync, watch } from 'node:fs'
|
||||
import { $ } from 'bun'
|
||||
import { aliases } from '@swc-uxp-wrappers/utils'
|
||||
import type { BunPlugin } from 'bun'
|
||||
|
||||
const swcAliasPlugin: BunPlugin = {
|
||||
name: 'swc-uxp-aliases',
|
||||
setup(build) {
|
||||
for (const [key, target] of Object.entries(aliases)) {
|
||||
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
const filter = new RegExp(`^${escaped}(/.*)?$`)
|
||||
build.onResolve({ filter }, (args) => {
|
||||
const subpath = args.path.slice(key.length)
|
||||
const targetPath = target + subpath
|
||||
try {
|
||||
return { path: import.meta.resolveSync(targetPath) }
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
const isWatch = process.argv.includes('--watch')
|
||||
const isPackage = process.argv.includes('--package')
|
||||
|
||||
async function build(): Promise<boolean> {
|
||||
const start = performance.now()
|
||||
try {
|
||||
if (!existsSync('dist')) {
|
||||
await mkdir('dist', { recursive: true })
|
||||
}
|
||||
|
||||
// 1. Copy public assets (manifest, index.html, styles, icons)
|
||||
await cp('public', 'dist', { recursive: true })
|
||||
|
||||
// 2. Bundle with Bun.build
|
||||
const result = await Bun.build({
|
||||
entrypoints: ['./src/index.tsx'],
|
||||
outdir: './dist',
|
||||
naming: 'index.js',
|
||||
target: 'browser',
|
||||
format: 'cjs',
|
||||
sourcemap: 'external',
|
||||
minify: false,
|
||||
plugins: [swcAliasPlugin],
|
||||
external: ['os', 'premierepro', 'uxp'],
|
||||
define: {
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
},
|
||||
})
|
||||
|
||||
if (!result.success) {
|
||||
console.error('❌ Build failed:')
|
||||
for (const log of result.logs) {
|
||||
console.error(log)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const elapsed = (performance.now() - start).toFixed(1)
|
||||
console.log(`✅ Build completed in ${elapsed}ms`)
|
||||
|
||||
// 3. Package .ccx if requested
|
||||
if (isPackage) {
|
||||
console.log('📦 Packaging shumai-premiere.ccx...')
|
||||
if (existsSync('shumai-premiere.ccx')) {
|
||||
await rm('shumai-premiere.ccx')
|
||||
}
|
||||
await $`cd dist && zip -r ../shumai-premiere.ccx . -x '*.map' -x '.DS_Store' -x '__MACOSX*'`
|
||||
console.log('✅ Package created.')
|
||||
}
|
||||
|
||||
return true
|
||||
} catch (err) {
|
||||
console.error('❌ Build error:', err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Clean and run initial build
|
||||
if (existsSync('dist')) {
|
||||
await rm('dist', { recursive: true, force: true })
|
||||
}
|
||||
const success = await build()
|
||||
if (!success && !isWatch) {
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
// Watch mode
|
||||
if (isWatch) {
|
||||
console.log('👀 Watching src/ and public/ for changes...')
|
||||
let building = false
|
||||
const triggerRebuild = async (dir: string) => {
|
||||
if (building) return
|
||||
building = true
|
||||
setTimeout(async () => {
|
||||
console.log(`\n🔄 Change detected in ${dir}, rebuilding...`)
|
||||
await build()
|
||||
building = false
|
||||
}, 50)
|
||||
}
|
||||
|
||||
watch('./src', { recursive: true }, () => triggerRebuild('src'))
|
||||
watch('./public', { recursive: true }, () => triggerRebuild('public'))
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
{
|
||||
"name": "@shumai/premiere-uxp",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "commonjs",
|
||||
"scripts": {
|
||||
"build": "bun run ./build.ts",
|
||||
"dev": "bun run ./build.ts --watch",
|
||||
"package": "bun run ./build.ts --package",
|
||||
"clean": "rm -rf dist"
|
||||
},
|
||||
"dependencies": {
|
||||
"@shumai/api": "workspace:*",
|
||||
"@shumai/dtos": "workspace:*",
|
||||
"@spectrum-web-components/action-menu": "0.37.0",
|
||||
"@spectrum-web-components/badge": "0.37.0",
|
||||
"@spectrum-web-components/icon": "1.12.2",
|
||||
"@spectrum-web-components/icons-workflow": "1.12.2",
|
||||
"@spectrum-web-components/menu": "0.37.0",
|
||||
"@spectrum-web-components/progress-circle": "0.37.0",
|
||||
"@spectrum-web-components/status-light": "0.37.0",
|
||||
"@spectrum-web-components/theme": "0.37.0",
|
||||
"@swc-react/action-button": "0.37.0",
|
||||
"@swc-react/action-group": "0.37.0",
|
||||
"@swc-react/action-menu": "0.37.0",
|
||||
"@swc-react/badge": "0.37.0",
|
||||
"@swc-react/button": "0.37.0",
|
||||
"@swc-react/card": "0.37.0",
|
||||
"@swc-react/divider": "0.37.0",
|
||||
"@swc-react/field-label": "0.37.0",
|
||||
"@swc-react/help-text": "0.37.0",
|
||||
"@swc-react/illustrated-message": "0.37.0",
|
||||
"@swc-react/menu": "0.37.0",
|
||||
"@swc-react/progress-circle": "0.37.0",
|
||||
"@swc-react/search": "0.37.0",
|
||||
"@swc-react/status-light": "0.37.0",
|
||||
"@swc-react/textfield": "0.37.0",
|
||||
"@swc-react/theme": "0.37.0",
|
||||
"@swc-uxp-wrappers/action-button": "2.0.0",
|
||||
"@swc-uxp-wrappers/action-group": "2.0.0",
|
||||
"@swc-uxp-wrappers/button": "2.0.0",
|
||||
"@swc-uxp-wrappers/card": "2.0.0",
|
||||
"@swc-uxp-wrappers/divider": "2.0.0",
|
||||
"@swc-uxp-wrappers/field-label": "2.0.0",
|
||||
"@swc-uxp-wrappers/help-text": "2.0.0",
|
||||
"@swc-uxp-wrappers/illustrated-message": "2.0.0",
|
||||
"@swc-uxp-wrappers/menu": "2.0.0",
|
||||
"@swc-uxp-wrappers/overlay": "2.0.0",
|
||||
"@swc-uxp-wrappers/popover": "2.0.0",
|
||||
"@swc-uxp-wrappers/search": "2.0.0",
|
||||
"@swc-uxp-wrappers/textfield": "2.0.0",
|
||||
"@swc-uxp-wrappers/utils": "2.0.1",
|
||||
"hono": "4.13.5",
|
||||
"react": "19.2.8",
|
||||
"react-dom": "19.2.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@adobe/premierepro": "26.3.0",
|
||||
"@types/react": "19.2.18",
|
||||
"@types/react-dom": "19.2.7"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.1 KiB |
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Shumai</title>
|
||||
<link rel="stylesheet" href="./styles.css" />
|
||||
<script defer src="./index.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"id": "com.shumai.premiere",
|
||||
"name": "Shumai",
|
||||
"shortname": "shumai",
|
||||
"version": "0.1.0",
|
||||
"main": "index.html",
|
||||
"host": {
|
||||
"app": "premierepro",
|
||||
"minVersion": "25.1.0"
|
||||
},
|
||||
"manifestVersion": 5,
|
||||
"featureFlags": {
|
||||
"enableSWCSupport": true
|
||||
},
|
||||
"requiredPermissions": {
|
||||
"network": {
|
||||
"domains": "all"
|
||||
},
|
||||
"localFileSystem": "request",
|
||||
"clipboard": "readAndWrite"
|
||||
},
|
||||
"entrypoints": [
|
||||
{
|
||||
"id": "shumaiPanel",
|
||||
"type": "panel",
|
||||
"minimumSize": {
|
||||
"width": 320,
|
||||
"height": 480
|
||||
},
|
||||
"maximumSize": {
|
||||
"width": 2000,
|
||||
"height": 2000
|
||||
},
|
||||
"preferredDockedSize": {
|
||||
"width": 400,
|
||||
"height": 720
|
||||
},
|
||||
"preferredFloatingSize": {
|
||||
"width": 460,
|
||||
"height": 780
|
||||
},
|
||||
"label": {
|
||||
"default": "Shumai"
|
||||
},
|
||||
"icons": [
|
||||
{
|
||||
"width": 114,
|
||||
"height": 114,
|
||||
"path": "icons/icon.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"icons": [
|
||||
{
|
||||
"width": 114,
|
||||
"height": 114,
|
||||
"path": "icons/icon.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,123 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Header } from './components/Header'
|
||||
import { NavigationTabs, type MainTab } from './components/NavigationTabs'
|
||||
import { AuthView } from './views/AuthView'
|
||||
import { ProjectsView, ProjectSummary } from './views/ProjectsView'
|
||||
import { FileListView } from './views/FileListView'
|
||||
import { SequencesView } from './views/SequencesView'
|
||||
import { getStoredCredentials, clearStoredCredentials } from './services/storage'
|
||||
import { getAllSequenceLinksFromCache } from './services/linkStorage'
|
||||
import { resetClient } from './api/client'
|
||||
import { autoSyncService } from './services/autoSyncService'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
|
||||
type AppView = 'auth' | 'projects' | 'files'
|
||||
|
||||
export const App: React.FC = () => {
|
||||
const [view, setView] = useState<AppView>('auth')
|
||||
const [mainTab, setMainTab] = useState<MainTab>('browse')
|
||||
const [linkedCount, setLinkedCount] = useState<number>(0)
|
||||
const [endpoint, setEndpoint] = useState<string>('')
|
||||
const [apiKey, setApiKey] = useState<string>('')
|
||||
const [selectedProject, setSelectedProject] = useState<ProjectSummary | null>(null)
|
||||
const [initialLoading, setInitialLoading] = useState(true)
|
||||
|
||||
useEffect(() => {
|
||||
const creds = getStoredCredentials()
|
||||
if (creds && creds.endpoint && creds.apiKey) {
|
||||
setEndpoint(creds.endpoint)
|
||||
setApiKey(creds.apiKey)
|
||||
setView('projects')
|
||||
autoSyncService.start(creds.endpoint, creds.apiKey)
|
||||
const cached = getAllSequenceLinksFromCache()
|
||||
setLinkedCount(cached.length)
|
||||
} else {
|
||||
setView('auth')
|
||||
}
|
||||
setInitialLoading(false)
|
||||
|
||||
return () => {
|
||||
autoSyncService.stop()
|
||||
}
|
||||
}, [])
|
||||
|
||||
const handleConnectSuccess = (newEndpoint: string, newApiKey: string) => {
|
||||
setEndpoint(newEndpoint)
|
||||
setApiKey(newApiKey)
|
||||
setView('projects')
|
||||
autoSyncService.start(newEndpoint, newApiKey)
|
||||
}
|
||||
|
||||
const handleDisconnect = () => {
|
||||
autoSyncService.stop()
|
||||
clearStoredCredentials()
|
||||
resetClient()
|
||||
setEndpoint('')
|
||||
setApiKey('')
|
||||
setSelectedProject(null)
|
||||
setView('auth')
|
||||
setMainTab('browse')
|
||||
}
|
||||
|
||||
const handleSelectProject = (project: ProjectSummary) => {
|
||||
setSelectedProject(project)
|
||||
setView('files')
|
||||
setMainTab('browse')
|
||||
}
|
||||
|
||||
const handleBackToProjects = () => {
|
||||
setSelectedProject(null)
|
||||
setView('projects')
|
||||
setMainTab('browse')
|
||||
}
|
||||
|
||||
if (initialLoading) {
|
||||
return (
|
||||
<div className="app-container">
|
||||
<Header />
|
||||
<div className="view-content" style={{ justifyContent: 'center', alignItems: 'center' }}>
|
||||
<ProgressCircle indeterminate size="l" label="Loading Shumai..." />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="app-container">
|
||||
<Header
|
||||
endpoint={view !== 'auth' ? endpoint : undefined}
|
||||
onDisconnect={view !== 'auth' ? handleDisconnect : undefined}
|
||||
/>
|
||||
|
||||
{view !== 'auth' && (
|
||||
<NavigationTabs activeTab={mainTab} onTabChange={setMainTab} linkedCount={linkedCount} />
|
||||
)}
|
||||
|
||||
{view === 'auth' && (
|
||||
<AuthView
|
||||
initialEndpoint={endpoint || 'http://localhost:3000'}
|
||||
initialApiKey={apiKey}
|
||||
onConnectSuccess={handleConnectSuccess}
|
||||
/>
|
||||
)}
|
||||
|
||||
{view !== 'auth' && mainTab === 'sequences' && (
|
||||
<SequencesView endpoint={endpoint} apiKey={apiKey} onLinkCountChange={setLinkedCount} />
|
||||
)}
|
||||
|
||||
{view !== 'auth' && mainTab === 'browse' && view === 'projects' && (
|
||||
<ProjectsView endpoint={endpoint} apiKey={apiKey} onSelectProject={handleSelectProject} />
|
||||
)}
|
||||
|
||||
{view !== 'auth' && mainTab === 'browse' && view === 'files' && selectedProject && (
|
||||
<FileListView
|
||||
endpoint={endpoint}
|
||||
apiKey={apiKey}
|
||||
project={selectedProject}
|
||||
onBackToProjects={handleBackToProjects}
|
||||
onLinkCountChange={setLinkedCount}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { hc } from 'hono/client'
|
||||
import type { AppType } from '@shumai/api'
|
||||
|
||||
export type ShumaiClient = ReturnType<typeof hc<AppType>>
|
||||
|
||||
let currentClient: ShumaiClient | null = null
|
||||
let currentKey = ''
|
||||
|
||||
export function getShumaiClient(endpoint: string, apiKey: string): ShumaiClient {
|
||||
const normalizedEndpoint = endpoint.trim().replace(/\/+$/, '')
|
||||
const cacheKey = `${normalizedEndpoint}::${apiKey}`
|
||||
|
||||
if (currentClient && currentKey === cacheKey) {
|
||||
return currentClient
|
||||
}
|
||||
|
||||
currentClient = hc<AppType>(normalizedEndpoint, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
'x-api-key': apiKey,
|
||||
},
|
||||
})
|
||||
currentKey = cacheKey
|
||||
|
||||
return currentClient
|
||||
}
|
||||
|
||||
export function resetClient(): void {
|
||||
currentClient = null
|
||||
currentKey = ''
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import React from 'react'
|
||||
import { Divider } from '@swc-react/divider'
|
||||
|
||||
export interface BreadcrumbCrumb {
|
||||
id: string
|
||||
name: string
|
||||
}
|
||||
|
||||
interface BreadcrumbProps {
|
||||
projectName?: string
|
||||
crumbs: BreadcrumbCrumb[]
|
||||
onNavigateToProjects: () => void
|
||||
onNavigateToCrumb: (index: number) => void
|
||||
}
|
||||
|
||||
export const Breadcrumb: React.FC<BreadcrumbProps> = ({
|
||||
projectName,
|
||||
crumbs,
|
||||
onNavigateToProjects,
|
||||
onNavigateToCrumb,
|
||||
}) => {
|
||||
return (
|
||||
<>
|
||||
<nav className="breadcrumb-bar" aria-label="Folder Path">
|
||||
<span className="breadcrumb-item" onClick={onNavigateToProjects} title="Back to Projects">
|
||||
Projects
|
||||
</span>
|
||||
|
||||
{projectName && (
|
||||
<>
|
||||
<span className="breadcrumb-separator">/</span>
|
||||
<span
|
||||
className={`breadcrumb-item ${crumbs.length === 0 ? 'active' : ''}`}
|
||||
onClick={() => onNavigateToCrumb(-1)}
|
||||
title={projectName}
|
||||
>
|
||||
{projectName}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
|
||||
{crumbs.map((crumb, idx) => {
|
||||
const isLast = idx === crumbs.length - 1
|
||||
return (
|
||||
<React.Fragment key={crumb.id}>
|
||||
<span className="breadcrumb-separator">/</span>
|
||||
<span
|
||||
className={`breadcrumb-item ${isLast ? 'active' : ''}`}
|
||||
onClick={() => (!isLast ? onNavigateToCrumb(idx) : undefined)}
|
||||
title={crumb.name}
|
||||
>
|
||||
{crumb.name}
|
||||
</span>
|
||||
</React.Fragment>
|
||||
)
|
||||
})}
|
||||
</nav>
|
||||
<Divider size="s" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,409 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React from 'react'
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||
import { render, screen, fireEvent, cleanup } from '@testing-library/react'
|
||||
import {
|
||||
getFileTypeCategory,
|
||||
getAssetVersionLabel,
|
||||
FileItem,
|
||||
FileCardItem,
|
||||
type AssetSummary,
|
||||
} from './FileItem'
|
||||
|
||||
// Configure React 19 act environment for happy-dom
|
||||
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
describe('getFileTypeCategory', () => {
|
||||
it('identifies folder type', () => {
|
||||
const asset: AssetSummary = {
|
||||
id: 'f1',
|
||||
name: 'My Folder',
|
||||
type: 'folder',
|
||||
}
|
||||
expect(getFileTypeCategory(asset)).toBe('folder')
|
||||
})
|
||||
|
||||
it('identifies video by mimeType', () => {
|
||||
const asset: AssetSummary = {
|
||||
id: 'v1',
|
||||
name: 'clip.dat',
|
||||
type: 'file',
|
||||
mimeType: 'video/mp4',
|
||||
}
|
||||
expect(getFileTypeCategory(asset)).toBe('video')
|
||||
})
|
||||
|
||||
it('identifies video by extension', () => {
|
||||
const extensions = ['mp4', 'mov', 'avi', 'mkv', 'm4v', 'webm']
|
||||
for (const ext of extensions) {
|
||||
const asset: AssetSummary = {
|
||||
id: `v-${ext}`,
|
||||
name: `sample.${ext}`,
|
||||
type: 'file',
|
||||
}
|
||||
expect(getFileTypeCategory(asset)).toBe('video')
|
||||
}
|
||||
})
|
||||
|
||||
it('identifies audio by mimeType or extension', () => {
|
||||
const asset1: AssetSummary = {
|
||||
id: 'a1',
|
||||
name: 'audio.raw',
|
||||
type: 'file',
|
||||
mimeType: 'audio/wav',
|
||||
}
|
||||
const asset2: AssetSummary = {
|
||||
id: 'a2',
|
||||
name: 'track.mp3',
|
||||
type: 'file',
|
||||
}
|
||||
expect(getFileTypeCategory(asset1)).toBe('audio')
|
||||
expect(getFileTypeCategory(asset2)).toBe('audio')
|
||||
})
|
||||
|
||||
it('identifies image by mimeType or extension', () => {
|
||||
const asset1: AssetSummary = {
|
||||
id: 'i1',
|
||||
name: 'photo.bin',
|
||||
type: 'file',
|
||||
mimeType: 'image/png',
|
||||
}
|
||||
const asset2: AssetSummary = {
|
||||
id: 'i2',
|
||||
name: 'art.jpg',
|
||||
type: 'file',
|
||||
}
|
||||
expect(getFileTypeCategory(asset1)).toBe('image')
|
||||
expect(getFileTypeCategory(asset2)).toBe('image')
|
||||
})
|
||||
|
||||
it('falls back to generic file', () => {
|
||||
const asset: AssetSummary = {
|
||||
id: 'doc1',
|
||||
name: 'notes.pdf',
|
||||
type: 'file',
|
||||
mimeType: 'application/pdf',
|
||||
}
|
||||
expect(getFileTypeCategory(asset)).toBe('file')
|
||||
})
|
||||
})
|
||||
|
||||
describe('FileItem and FileCardItem UI Components', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
const mockOnClick = vi.fn()
|
||||
const mockOnImportRaw = vi.fn()
|
||||
const mockOnSelectVideoForImport = vi.fn()
|
||||
|
||||
const folderAsset: AssetSummary = {
|
||||
id: 'folder-1',
|
||||
name: 'Raw Footage',
|
||||
type: 'folder',
|
||||
fileCount: 5,
|
||||
}
|
||||
|
||||
const imageAsset: AssetSummary = {
|
||||
id: 'img-1',
|
||||
name: 'logo.png',
|
||||
type: 'file',
|
||||
mimeType: 'image/png',
|
||||
sizeByte: 2048,
|
||||
}
|
||||
|
||||
const videoAsset: AssetSummary = {
|
||||
id: 'vid-1',
|
||||
name: 'interview.mp4',
|
||||
type: 'file',
|
||||
mimeType: 'video/mp4',
|
||||
sizeByte: 50 * 1024 * 1024,
|
||||
}
|
||||
|
||||
it('FileItem navigates into folder on click without download button', () => {
|
||||
render(
|
||||
<FileItem
|
||||
asset={folderAsset}
|
||||
onClick={mockOnClick}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onSelectVideoForImport={mockOnSelectVideoForImport}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByText('Raw Footage')).toBeTruthy()
|
||||
expect(screen.queryByTitle('Import into Premiere Pro')).toBeNull()
|
||||
|
||||
fireEvent.click(screen.getByText('Raw Footage'))
|
||||
expect(mockOnClick).toHaveBeenCalled()
|
||||
expect(mockOnImportRaw).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FileCardItem calls onImportRaw when download button is clicked for non-video, but clicking card does not', () => {
|
||||
render(
|
||||
<FileCardItem
|
||||
asset={imageAsset}
|
||||
onClick={mockOnClick}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onSelectVideoForImport={mockOnSelectVideoForImport}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByText('logo.png')).toBeTruthy()
|
||||
// Clicking the file title / card text should NOT trigger import
|
||||
fireEvent.click(screen.getByText('logo.png'))
|
||||
expect(mockOnImportRaw).not.toHaveBeenCalled()
|
||||
|
||||
const downloadBtn = screen.getByTitle('Import into Premiere Pro')
|
||||
expect(downloadBtn).toBeTruthy()
|
||||
|
||||
fireEvent.click(downloadBtn)
|
||||
expect(mockOnImportRaw).toHaveBeenCalledWith(imageAsset)
|
||||
})
|
||||
|
||||
it('FileCardItem calls onSelectVideoForImport when download button is clicked for video', () => {
|
||||
render(
|
||||
<FileCardItem
|
||||
asset={videoAsset}
|
||||
onClick={mockOnClick}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onSelectVideoForImport={mockOnSelectVideoForImport}
|
||||
/>,
|
||||
)
|
||||
|
||||
expect(screen.getByText('interview.mp4')).toBeTruthy()
|
||||
const downloadBtn = screen.getByTitle('Import into Premiere Pro')
|
||||
fireEvent.click(downloadBtn)
|
||||
|
||||
expect(mockOnSelectVideoForImport).toHaveBeenCalledWith(videoAsset)
|
||||
expect(mockOnImportRaw).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FileCardItem renders sp-icon-link when isLinked is false, and triggers onLinkSequence on click', () => {
|
||||
const mockOnLinkSequence = vi.fn()
|
||||
const { container } = render(
|
||||
<FileCardItem
|
||||
asset={videoAsset}
|
||||
onClick={mockOnClick}
|
||||
onLinkSequence={mockOnLinkSequence}
|
||||
isLinked={false}
|
||||
/>,
|
||||
)
|
||||
|
||||
const linkIcon = container.querySelector('sp-icon-link')
|
||||
const unlinkIcon = container.querySelector('sp-icon-unlink')
|
||||
expect(linkIcon).toBeTruthy()
|
||||
expect(unlinkIcon).toBeNull()
|
||||
|
||||
const linkBtn = screen.getByTitle('Link to Sequence')
|
||||
expect(linkBtn).toBeTruthy()
|
||||
fireEvent.click(linkBtn)
|
||||
expect(mockOnLinkSequence).toHaveBeenCalledWith(videoAsset)
|
||||
})
|
||||
|
||||
it('FileCardItem renders sp-icon-unlink when isLinked is true, and triggers onUnlinkSequence on click', () => {
|
||||
const mockOnLinkSequence = vi.fn()
|
||||
const mockOnUnlinkSequence = vi.fn()
|
||||
const { container } = render(
|
||||
<FileCardItem
|
||||
asset={videoAsset}
|
||||
onClick={mockOnClick}
|
||||
onLinkSequence={mockOnLinkSequence}
|
||||
onUnlinkSequence={mockOnUnlinkSequence}
|
||||
isLinked={true}
|
||||
linkedSequenceName="Cut_v1"
|
||||
/>,
|
||||
)
|
||||
|
||||
const linkIcon = container.querySelector('sp-icon-link')
|
||||
const unlinkIcon = container.querySelector('sp-icon-unlink')
|
||||
expect(linkIcon).toBeNull()
|
||||
expect(unlinkIcon).toBeTruthy()
|
||||
|
||||
const unlinkBtn = screen.getByTitle('Unlink from Cut_v1')
|
||||
expect(unlinkBtn).toBeTruthy()
|
||||
fireEvent.click(unlinkBtn)
|
||||
expect(mockOnUnlinkSequence).toHaveBeenCalledWith(videoAsset)
|
||||
expect(mockOnLinkSequence).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('FileItem renders sp-icon-unlink when isLinked is true', () => {
|
||||
const mockOnLinkSequence = vi.fn()
|
||||
const mockOnUnlinkSequence = vi.fn()
|
||||
const { container } = render(
|
||||
<FileItem
|
||||
asset={videoAsset}
|
||||
onClick={mockOnClick}
|
||||
onLinkSequence={mockOnLinkSequence}
|
||||
onUnlinkSequence={mockOnUnlinkSequence}
|
||||
isLinked={true}
|
||||
linkedSequenceName="Cut_v1"
|
||||
/>,
|
||||
)
|
||||
|
||||
const linkIcon = container.querySelector('sp-icon-link')
|
||||
const unlinkIcon = container.querySelector('sp-icon-unlink')
|
||||
expect(linkIcon).toBeNull()
|
||||
expect(unlinkIcon).toBeTruthy()
|
||||
|
||||
const unlinkBtn = screen.getByTitle('Unlink from Cut_v1')
|
||||
expect(unlinkBtn).toBeTruthy()
|
||||
fireEvent.click(unlinkBtn)
|
||||
expect(mockOnUnlinkSequence).toHaveBeenCalledWith(videoAsset)
|
||||
})
|
||||
|
||||
it('FileCardItem renders version in details when asset has versionStack', () => {
|
||||
const versionedAsset: AssetSummary = {
|
||||
id: 'vid-v2',
|
||||
name: 'interview_cut.mp4',
|
||||
type: 'file',
|
||||
mimeType: 'video/mp4',
|
||||
sizeByte: 20 * 1024 * 1024,
|
||||
versionStack: {
|
||||
id: 'stack-1',
|
||||
versions: [
|
||||
{ version: 2, current: true, id: 'vid-v2', name: 'interview_cut.mp4' },
|
||||
{ version: 1, current: false, id: 'vid-v1', name: 'interview_cut_v1.mp4' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
render(<FileCardItem asset={versionedAsset} onClick={mockOnClick} />)
|
||||
|
||||
expect(screen.getByText('v2')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('FileCardItem does not render version when asset has no versionStack', () => {
|
||||
render(<FileCardItem asset={videoAsset} onClick={mockOnClick} />)
|
||||
|
||||
expect(screen.queryByText(/^v\d+$/)).toBeNull()
|
||||
})
|
||||
|
||||
it('FileItem renders version in subtext when asset has versionStack', () => {
|
||||
const versionedAsset: AssetSummary = {
|
||||
id: 'vid-v2',
|
||||
name: 'interview_cut.mp4',
|
||||
type: 'file',
|
||||
mimeType: 'video/mp4',
|
||||
sizeByte: 20 * 1024 * 1024,
|
||||
versionStack: {
|
||||
id: 'stack-1',
|
||||
versions: [
|
||||
{ version: 2, current: true, id: 'vid-v2', name: 'interview_cut.mp4' },
|
||||
{ version: 1, current: false, id: 'vid-v1', name: 'interview_cut_v1.mp4' },
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
render(<FileItem asset={versionedAsset} onClick={mockOnClick} />)
|
||||
|
||||
expect(screen.getByText(/v2 •/)).toBeTruthy()
|
||||
})
|
||||
|
||||
it('FileCardItem renders createdAt time when provided', () => {
|
||||
const assetWithDates: AssetSummary = {
|
||||
id: 'date-1',
|
||||
name: 'render.mp4',
|
||||
type: 'file',
|
||||
createdAt: new Date(Date.now() - 3600 * 1000).toISOString(),
|
||||
updatedAt: new Date(Date.now() - 60 * 1000).toISOString(),
|
||||
}
|
||||
|
||||
render(<FileCardItem asset={assetWithDates} onClick={mockOnClick} />)
|
||||
expect(screen.getByText('1h ago')).toBeTruthy()
|
||||
expect(screen.queryByText('1m ago')).toBeNull()
|
||||
})
|
||||
|
||||
it('FileCardItem falls back to updatedAt if createdAt is absent', () => {
|
||||
const assetWithUpdatedOnly: AssetSummary = {
|
||||
id: 'date-2',
|
||||
name: 'render2.mp4',
|
||||
type: 'file',
|
||||
updatedAt: new Date(Date.now() - 60 * 1000).toISOString(),
|
||||
}
|
||||
|
||||
render(<FileCardItem asset={assetWithUpdatedOnly} onClick={mockOnClick} />)
|
||||
expect(screen.getByText('1m ago')).toBeTruthy()
|
||||
})
|
||||
|
||||
it('FileItem renders createdAt time in subtext when provided', () => {
|
||||
const assetWithDates: AssetSummary = {
|
||||
id: 'date-3',
|
||||
name: 'render3.mp4',
|
||||
type: 'file',
|
||||
createdAt: new Date(Date.now() - 3600 * 1000).toISOString(),
|
||||
updatedAt: new Date(Date.now() - 60 * 1000).toISOString(),
|
||||
}
|
||||
|
||||
render(<FileItem asset={assetWithDates} onClick={mockOnClick} />)
|
||||
expect(screen.getByText(/1h ago/)).toBeTruthy()
|
||||
expect(screen.queryByText(/1m ago/)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAssetVersionLabel', () => {
|
||||
it('returns null for folder asset', () => {
|
||||
const folder: AssetSummary = {
|
||||
id: 'f1',
|
||||
name: 'Footage',
|
||||
type: 'folder',
|
||||
}
|
||||
expect(getAssetVersionLabel(folder)).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null for standalone file without versionStack', () => {
|
||||
const file: AssetSummary = {
|
||||
id: 'file1',
|
||||
name: 'clip.mp4',
|
||||
type: 'file',
|
||||
}
|
||||
expect(getAssetVersionLabel(file)).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null when versionStack has empty versions array', () => {
|
||||
const file: AssetSummary = {
|
||||
id: 'file1',
|
||||
name: 'clip.mp4',
|
||||
type: 'file',
|
||||
versionStack: {
|
||||
id: 'stack-1',
|
||||
versions: [],
|
||||
},
|
||||
}
|
||||
expect(getAssetVersionLabel(file)).toBeNull()
|
||||
})
|
||||
|
||||
it('returns formatted version matching asset id', () => {
|
||||
const file: AssetSummary = {
|
||||
id: 'ver-1',
|
||||
name: 'cut.mov',
|
||||
type: 'file',
|
||||
versionStack: {
|
||||
id: 'stack-1',
|
||||
versions: [
|
||||
{ version: 3, current: false, id: 'ver-3' },
|
||||
{ version: 2, current: false, id: 'ver-2' },
|
||||
{ version: 1, current: false, id: 'ver-1' },
|
||||
],
|
||||
},
|
||||
}
|
||||
expect(getAssetVersionLabel(file)).toBe('v1')
|
||||
})
|
||||
|
||||
it('returns current version when asset id is stack id or does not match', () => {
|
||||
const file: AssetSummary = {
|
||||
id: 'stack-1',
|
||||
name: 'cut.mov',
|
||||
type: 'version_stack',
|
||||
versionStack: {
|
||||
id: 'stack-1',
|
||||
versions: [
|
||||
{ version: 3, current: true, id: 'ver-3' },
|
||||
{ version: 2, current: false, id: 'ver-2' },
|
||||
{ version: 1, current: false, id: 'ver-1' },
|
||||
],
|
||||
},
|
||||
}
|
||||
expect(getAssetVersionLabel(file)).toBe('v3')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,503 @@
|
||||
import React, { useState } from 'react'
|
||||
import { formatDateAgo } from '../utils/date'
|
||||
import { formatBytes, formatDuration } from '../utils/format'
|
||||
import { resolveAssetUrl } from '../utils/url'
|
||||
|
||||
export { formatBytes, formatDuration }
|
||||
|
||||
export interface AssetSummary {
|
||||
id: string
|
||||
name: string
|
||||
type: string
|
||||
size?: number | null
|
||||
sizeByte?: number | null
|
||||
mimeType?: string | null
|
||||
updatedAt?: string | Date
|
||||
createdAt?: string | Date
|
||||
commentsCount?: number
|
||||
fileCount?: number
|
||||
creator?: {
|
||||
id: string
|
||||
name: string
|
||||
image?: string | null
|
||||
} | null
|
||||
agent?: {
|
||||
id: string
|
||||
name: string
|
||||
} | null
|
||||
preview?: {
|
||||
thumbnailUrl?: string
|
||||
duration?: number
|
||||
pageCount?: number
|
||||
proxyType?: string | null
|
||||
} | null
|
||||
media?: {
|
||||
original?: {
|
||||
key?: string
|
||||
filesizeInBytes?: number
|
||||
codec?: string
|
||||
} | null
|
||||
metadata?: {
|
||||
duration?: number
|
||||
}
|
||||
videoTranscodes?: Array<{
|
||||
id: string
|
||||
url: string
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
size: number
|
||||
}>
|
||||
} | null
|
||||
versionStack?: {
|
||||
id: string
|
||||
versions: Array<{
|
||||
version: number
|
||||
current: boolean
|
||||
id: string
|
||||
name?: string | null
|
||||
createdAt?: string | null
|
||||
previewUrl?: string | null
|
||||
}>
|
||||
} | null
|
||||
}
|
||||
|
||||
export interface FileItemProps {
|
||||
asset: AssetSummary
|
||||
endpoint?: string
|
||||
apiKey?: string
|
||||
onClick: (e: React.MouseEvent) => void
|
||||
onImportRaw?: (asset: AssetSummary) => void
|
||||
onSelectVideoForImport?: (asset: AssetSummary) => void
|
||||
onLinkSequence?: (asset: AssetSummary) => void
|
||||
onUnlinkSequence?: (asset: AssetSummary) => void
|
||||
isLinked?: boolean
|
||||
linkedSequenceName?: string
|
||||
}
|
||||
|
||||
export function getFileTypeCategory(
|
||||
asset: AssetSummary,
|
||||
): 'folder' | 'video' | 'audio' | 'image' | 'file' {
|
||||
if (asset.type === 'folder') return 'folder'
|
||||
const name = asset.name.toLowerCase()
|
||||
const mime = asset.mimeType?.toLowerCase() || ''
|
||||
|
||||
if (mime.startsWith('video/') || /\.(mp4|mov|avi|mkv|m4v|webm)$/.test(name)) {
|
||||
return 'video'
|
||||
}
|
||||
if (mime.startsWith('audio/') || /\.(mp3|wav|aac|flac|m4a|ogg)$/.test(name)) {
|
||||
return 'audio'
|
||||
}
|
||||
if (mime.startsWith('image/') || /\.(png|jpg|jpeg|gif|webp|svg|bmp)$/.test(name)) {
|
||||
return 'image'
|
||||
}
|
||||
return 'file'
|
||||
}
|
||||
|
||||
export function getAssetVersionLabel(asset: AssetSummary): string | null {
|
||||
if (asset.versionStack?.versions && asset.versionStack.versions.length > 0) {
|
||||
const matched = asset.versionStack.versions.find((v) => v.id === asset.id)
|
||||
if (matched?.version != null) {
|
||||
return `v${matched.version}`
|
||||
}
|
||||
const current = asset.versionStack.versions.find((v) => v.current)
|
||||
if (current?.version != null) {
|
||||
return `v${current.version}`
|
||||
}
|
||||
const first = asset.versionStack.versions[0]
|
||||
if (first?.version != null) {
|
||||
return `v${first.version}`
|
||||
}
|
||||
return `v${asset.versionStack.versions.length}`
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/** List View Row Item */
|
||||
export const FileItem: React.FC<FileItemProps> = ({
|
||||
asset,
|
||||
endpoint = '',
|
||||
onClick,
|
||||
onImportRaw,
|
||||
onSelectVideoForImport,
|
||||
onLinkSequence,
|
||||
onUnlinkSequence,
|
||||
isLinked = false,
|
||||
linkedSequenceName,
|
||||
}) => {
|
||||
const [imgError, setImgError] = useState(false)
|
||||
const category = getFileTypeCategory(asset)
|
||||
const isFolder = category === 'folder'
|
||||
const versionLabel = getAssetVersionLabel(asset)
|
||||
const effectiveSize = asset.sizeByte ?? asset.size
|
||||
const timeText = formatDateAgo(asset.createdAt || asset.updatedAt)
|
||||
const thumbUrl = resolveAssetUrl(asset.preview?.thumbnailUrl, endpoint)
|
||||
|
||||
const iconFallback = (
|
||||
<div className={`item-icon ${category}`}>
|
||||
{category === 'folder' && (
|
||||
<sp-icon-folder size="s" style={{ color: '#fbbf24' }}></sp-icon-folder>
|
||||
)}
|
||||
{category === 'video' && (
|
||||
<sp-icon-filmstrip size="s" style={{ color: '#60a5fa' }}></sp-icon-filmstrip>
|
||||
)}
|
||||
{category === 'audio' && (
|
||||
<sp-icon-audio size="s" style={{ color: '#a78bfa' }}></sp-icon-audio>
|
||||
)}
|
||||
{category === 'image' && (
|
||||
<sp-icon-image size="s" style={{ color: '#f472b6' }}></sp-icon-image>
|
||||
)}
|
||||
{category === 'file' && (
|
||||
<sp-icon-document size="s" style={{ color: '#999999' }}></sp-icon-document>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
const handleImportAction = () => {
|
||||
if (isFolder) return
|
||||
if (category === 'video' && onSelectVideoForImport) {
|
||||
onSelectVideoForImport(asset)
|
||||
} else if (onImportRaw) {
|
||||
onImportRaw(asset)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRowClick = (e: React.MouseEvent) => {
|
||||
if (isFolder) {
|
||||
onClick(e)
|
||||
} else {
|
||||
e.stopPropagation()
|
||||
handleImportAction()
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="item-row"
|
||||
onClick={handleRowClick}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
handleRowClick(e as unknown as React.MouseEvent)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="item-left">
|
||||
{thumbUrl && !isFolder && !imgError ? (
|
||||
<div className="item-thumb-wrapper">
|
||||
<img
|
||||
src={thumbUrl}
|
||||
alt={asset.name}
|
||||
className="item-thumb-img"
|
||||
onLoad={() => console.log('[UXP Image OK]', thumbUrl)}
|
||||
onError={() => {
|
||||
console.error('[UXP Image Failed]', thumbUrl)
|
||||
setImgError(true)
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
iconFallback
|
||||
)}
|
||||
|
||||
<div className="item-meta">
|
||||
<span className="item-name" title={asset.name}>
|
||||
{asset.name}
|
||||
</span>
|
||||
<span className="item-subtext">
|
||||
{versionLabel ? `${versionLabel} • ` : ''}
|
||||
{isFolder ? 'Folder' : formatBytes(effectiveSize)}
|
||||
{timeText ? ` • ${timeText}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="item-right">
|
||||
{asset.commentsCount != null && asset.commentsCount > 0 && (
|
||||
<span className="item-comments-count" title={`${asset.commentsCount} comments`}>
|
||||
{asset.commentsCount} {asset.commentsCount === 1 ? 'comment' : 'comments'}
|
||||
</span>
|
||||
)}
|
||||
{isFolder ? (
|
||||
<sp-icon-chevron-right size="xs"></sp-icon-chevron-right>
|
||||
) : (
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
{(onLinkSequence || onUnlinkSequence) &&
|
||||
(category === 'video' || category === 'audio') && (
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
icon-only
|
||||
label={
|
||||
isLinked
|
||||
? onUnlinkSequence
|
||||
? `Unlink from ${linkedSequenceName || 'Sequence'}`
|
||||
: `Linked to ${linkedSequenceName || 'Sequence'}`
|
||||
: 'Link to Sequence'
|
||||
}
|
||||
title={
|
||||
isLinked
|
||||
? onUnlinkSequence
|
||||
? `Unlink from ${linkedSequenceName || 'Sequence'}`
|
||||
: `Linked to ${linkedSequenceName || 'Sequence'}`
|
||||
: 'Link to Sequence'
|
||||
}
|
||||
className="item-row-link-btn"
|
||||
style={{ marginRight: 4 }}
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (isLinked && onUnlinkSequence) {
|
||||
onUnlinkSequence(asset)
|
||||
} else if (onLinkSequence) {
|
||||
onLinkSequence(asset)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{isLinked ? (
|
||||
<sp-icon-unlink
|
||||
size="s"
|
||||
slot="icon"
|
||||
style={{ color: '#f87171' }}
|
||||
></sp-icon-unlink>
|
||||
) : (
|
||||
<sp-icon-link size="s" slot="icon"></sp-icon-link>
|
||||
)}
|
||||
</sp-action-button>
|
||||
)}
|
||||
{(onImportRaw || onSelectVideoForImport) && (
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
icon-only
|
||||
label="Import into Premiere Pro"
|
||||
title="Import into Premiere Pro"
|
||||
className="item-row-import-btn"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
handleImportAction()
|
||||
}}
|
||||
>
|
||||
<sp-icon-download size="s" slot="icon"></sp-icon-download>
|
||||
</sp-action-button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** Card View Row Item (2 Columns: Left Preview, Right Info as Raw Text) */
|
||||
export const FileCardItem: React.FC<FileItemProps> = ({
|
||||
asset,
|
||||
endpoint = '',
|
||||
onClick,
|
||||
onImportRaw,
|
||||
onSelectVideoForImport,
|
||||
onLinkSequence,
|
||||
onUnlinkSequence,
|
||||
isLinked = false,
|
||||
linkedSequenceName,
|
||||
}) => {
|
||||
const [imgError, setImgError] = useState(false)
|
||||
const category = getFileTypeCategory(asset)
|
||||
const isFolder = category === 'folder'
|
||||
const effectiveSize = asset.sizeByte ?? asset.size
|
||||
const timeText = formatDateAgo(asset.createdAt || asset.updatedAt)
|
||||
const thumbUrl = resolveAssetUrl(asset.preview?.thumbnailUrl, endpoint)
|
||||
const duration = asset.preview?.duration ?? asset.media?.metadata?.duration
|
||||
const durationText = formatDuration(duration)
|
||||
const creatorName = asset.creator?.name || asset.agent?.name
|
||||
|
||||
const cardFallback = (
|
||||
<div className={`file-row-placeholder ${category}`}>
|
||||
{category === 'folder' && (
|
||||
<sp-icon-folder size="l" style={{ color: '#fbbf24' }}></sp-icon-folder>
|
||||
)}
|
||||
{category === 'video' && (
|
||||
<sp-icon-filmstrip size="l" style={{ color: '#60a5fa' }}></sp-icon-filmstrip>
|
||||
)}
|
||||
{category === 'audio' && (
|
||||
<sp-icon-audio size="l" style={{ color: '#a78bfa' }}></sp-icon-audio>
|
||||
)}
|
||||
{category === 'image' && (
|
||||
<sp-icon-image size="l" style={{ color: '#f472b6' }}></sp-icon-image>
|
||||
)}
|
||||
{category === 'file' && (
|
||||
<sp-icon-document size="l" style={{ color: '#999999' }}></sp-icon-document>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
|
||||
const handleImportAction = () => {
|
||||
if (isFolder) return
|
||||
if (category === 'video' && onSelectVideoForImport) {
|
||||
onSelectVideoForImport(asset)
|
||||
} else if (onImportRaw) {
|
||||
onImportRaw(asset)
|
||||
}
|
||||
}
|
||||
|
||||
const handleCardClick = (e: React.MouseEvent) => {
|
||||
if (isFolder) {
|
||||
onClick(e)
|
||||
}
|
||||
}
|
||||
|
||||
// Assemble raw text details for Line 3 (Version • Duration • Size/Type • Comments)
|
||||
const details: string[] = []
|
||||
const versionLabel = getAssetVersionLabel(asset)
|
||||
if (versionLabel) {
|
||||
details.push(versionLabel)
|
||||
}
|
||||
if (durationText) {
|
||||
details.push(durationText)
|
||||
}
|
||||
if (isFolder) {
|
||||
details.push(asset.fileCount != null ? `${asset.fileCount} items` : 'Folder')
|
||||
} else if (effectiveSize != null) {
|
||||
details.push(formatBytes(effectiveSize))
|
||||
}
|
||||
if (asset.commentsCount != null && asset.commentsCount > 0) {
|
||||
details.push(`${asset.commentsCount} ${asset.commentsCount === 1 ? 'comment' : 'comments'}`)
|
||||
}
|
||||
if (isLinked) {
|
||||
details.push(`Linked: ${linkedSequenceName || 'Sequence'}`)
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className={`file-row-card ${isFolder ? 'is-folder' : 'is-file'}`}
|
||||
onClick={isFolder ? handleCardClick : undefined}
|
||||
role={isFolder ? 'button' : undefined}
|
||||
tabIndex={isFolder ? 0 : undefined}
|
||||
title={isFolder ? asset.name : undefined}
|
||||
onKeyDown={
|
||||
isFolder
|
||||
? (e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
handleCardClick(e as unknown as React.MouseEvent)
|
||||
}
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
{/* Left Column: Preview Only (NO LABELS, NO BADGES) */}
|
||||
<div className="file-row-preview">
|
||||
{thumbUrl && !isFolder && !imgError ? (
|
||||
<img
|
||||
src={thumbUrl}
|
||||
alt={asset.name}
|
||||
className="file-row-img"
|
||||
onError={() => setImgError(true)}
|
||||
/>
|
||||
) : (
|
||||
cardFallback
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Right Column: Title, Creator & Date, Duration / Size / Comments as Raw Text */}
|
||||
<div className="file-row-content">
|
||||
<div className="file-row-header">
|
||||
<span className="file-row-title" title={isFolder ? asset.name : undefined}>
|
||||
{asset.name}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{(creatorName || timeText) && (
|
||||
<div className="file-row-meta">
|
||||
{creatorName && <span className="file-row-creator">{creatorName}</span>}
|
||||
{creatorName && timeText && <span className="file-row-meta-dot">•</span>}
|
||||
{timeText && <span className="file-row-time">{timeText}</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{details.length > 0 && (
|
||||
<div className="file-row-subtext file-row-details">
|
||||
{details.map((item, idx) => (
|
||||
<React.Fragment key={idx}>
|
||||
{idx > 0 && <span className="file-row-meta-dot">•</span>}
|
||||
<span
|
||||
className={`file-row-detail-item${item === versionLabel ? ' file-row-version' : ''}`}
|
||||
>
|
||||
{item}
|
||||
</span>
|
||||
</React.Fragment>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Far Right Action Column (Centered Vertically across the card) */}
|
||||
<div className="file-row-actions" style={{ display: 'flex', alignItems: 'center' }}>
|
||||
{isFolder ? (
|
||||
<sp-icon-chevron-right size="xs" className="file-row-chevron"></sp-icon-chevron-right>
|
||||
) : (
|
||||
<>
|
||||
{(onLinkSequence || onUnlinkSequence) &&
|
||||
(category === 'video' || category === 'audio') && (
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
icon-only
|
||||
label={
|
||||
isLinked
|
||||
? onUnlinkSequence
|
||||
? `Unlink from ${linkedSequenceName || 'Sequence'}`
|
||||
: `Linked to ${linkedSequenceName || 'Sequence'}`
|
||||
: 'Link to Sequence'
|
||||
}
|
||||
title={
|
||||
isLinked
|
||||
? onUnlinkSequence
|
||||
? `Unlink from ${linkedSequenceName || 'Sequence'}`
|
||||
: `Linked to ${linkedSequenceName || 'Sequence'}`
|
||||
: 'Link to Sequence'
|
||||
}
|
||||
className="file-row-link-btn"
|
||||
style={{ marginRight: 4 }}
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
if (isLinked && onUnlinkSequence) {
|
||||
onUnlinkSequence(asset)
|
||||
} else if (onLinkSequence) {
|
||||
onLinkSequence(asset)
|
||||
}
|
||||
}}
|
||||
>
|
||||
{isLinked ? (
|
||||
<sp-icon-unlink
|
||||
size="s"
|
||||
slot="icon"
|
||||
style={{ color: '#f87171' }}
|
||||
></sp-icon-unlink>
|
||||
) : (
|
||||
<sp-icon-link size="s" slot="icon"></sp-icon-link>
|
||||
)}
|
||||
</sp-action-button>
|
||||
)}
|
||||
{(onImportRaw || onSelectVideoForImport) && (
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
icon-only
|
||||
label="Import into Premiere Pro"
|
||||
title="Import into Premiere Pro"
|
||||
className="file-row-import-btn"
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
handleImportAction()
|
||||
}}
|
||||
>
|
||||
<sp-icon-download size="s" slot="icon"></sp-icon-download>
|
||||
</sp-action-button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import React from 'react'
|
||||
import { Divider } from '@swc-react/divider'
|
||||
import { ShumaiLogo } from './icons'
|
||||
|
||||
interface HeaderProps {
|
||||
endpoint?: string
|
||||
onDisconnect?: () => void
|
||||
}
|
||||
|
||||
export const Header: React.FC<HeaderProps> = ({ endpoint, onDisconnect }) => {
|
||||
let displayHost = ''
|
||||
if (endpoint) {
|
||||
try {
|
||||
const url = new URL(endpoint)
|
||||
displayHost = url.host
|
||||
} catch {
|
||||
displayHost = endpoint
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="app-header">
|
||||
<div className="logo-group">
|
||||
<div className="logo-icon">
|
||||
<ShumaiLogo width={18} height={18} />
|
||||
</div>
|
||||
<span className="app-title">Shumai</span>
|
||||
</div>
|
||||
|
||||
{endpoint && onDisconnect && (
|
||||
<div className="actions-group">
|
||||
<div
|
||||
className="header-status"
|
||||
title={`Connected to ${endpoint}`}
|
||||
role="status"
|
||||
aria-label={`Connected to ${displayHost}`}
|
||||
>
|
||||
<span className="status-dot positive" />
|
||||
<span className="status-text">{displayHost}</span>
|
||||
</div>
|
||||
<sp-button
|
||||
quiet
|
||||
variant="secondary"
|
||||
size="s"
|
||||
label="Disconnect / Change Server"
|
||||
icon-only
|
||||
onClick={onDisconnect}
|
||||
title="Disconnect / Change Server"
|
||||
>
|
||||
<sp-icon-log-out slot="icon" size="s"></sp-icon-log-out>
|
||||
</sp-button>
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
<Divider size="s" />
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React, { act } from 'react'
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||
import { render, screen, fireEvent, cleanup } from '@testing-library/react'
|
||||
import { ImportVideoDialog } from './ImportVideoDialog'
|
||||
import type { AssetSummary } from './FileItem'
|
||||
import * as importService from '../services/import'
|
||||
|
||||
// Configure React 19 act environment for happy-dom
|
||||
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
describe('ImportVideoDialog Component', () => {
|
||||
const mockOnClose = vi.fn()
|
||||
const mockOnImportRaw = vi.fn()
|
||||
const mockOnImportProxy = vi.fn()
|
||||
|
||||
const videoAsset: AssetSummary = {
|
||||
id: 'asset-vid-1',
|
||||
name: 'interview_clip.mp4',
|
||||
type: 'file',
|
||||
mimeType: 'video/mp4',
|
||||
sizeByte: 1024 * 1024 * 45,
|
||||
preview: {
|
||||
duration: 154,
|
||||
},
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('renders nothing when closed or asset is null', () => {
|
||||
const { container } = render(
|
||||
<ImportVideoDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={false}
|
||||
onClose={mockOnClose}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onImportProxy={mockOnImportProxy}
|
||||
/>,
|
||||
)
|
||||
expect(container.firstChild).toBeNull()
|
||||
|
||||
const { container: containerNull } = render(
|
||||
<ImportVideoDialog
|
||||
asset={null}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onImportProxy={mockOnImportProxy}
|
||||
/>,
|
||||
)
|
||||
expect(containerNull.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('renders video info and selects original file by default', async () => {
|
||||
vi.spyOn(importService, 'fetchVideoProxies').mockResolvedValue([])
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<ImportVideoDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onImportProxy={mockOnImportProxy}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
expect(screen.getByText('Import Video')).toBeTruthy()
|
||||
expect(screen.getByText('interview_clip.mp4')).toBeTruthy()
|
||||
expect(screen.getByText('Original File')).toBeTruthy()
|
||||
expect(screen.getByText('No proxy transcodes available for this video.')).toBeTruthy()
|
||||
|
||||
// Click Import button
|
||||
const importBtn = screen.getByText('Import')
|
||||
fireEvent.click(importBtn)
|
||||
|
||||
expect(mockOnImportRaw).toHaveBeenCalledWith(videoAsset)
|
||||
expect(mockOnClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fetches and allows selecting a proxy transcode', async () => {
|
||||
vi.spyOn(importService, 'fetchVideoProxies').mockResolvedValue([
|
||||
{
|
||||
id: 'proxy-1',
|
||||
label: '1080p (MP4)',
|
||||
resolution: '1080p',
|
||||
url: 'https://cdn.shumai.test/1080p.mp4',
|
||||
key: 'proxies/1080p.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
size: 1024 * 1024 * 12,
|
||||
},
|
||||
])
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<ImportVideoDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onImportProxy={mockOnImportProxy}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
expect(screen.getByText('1080p (MP4)')).toBeTruthy()
|
||||
|
||||
// Select the proxy card
|
||||
const proxyCard = screen.getByText('1080p (MP4)')
|
||||
fireEvent.click(proxyCard)
|
||||
|
||||
// Click Import button
|
||||
const importBtn = screen.getByText('Import')
|
||||
fireEvent.click(importBtn)
|
||||
|
||||
expect(mockOnImportProxy).toHaveBeenCalledWith(
|
||||
videoAsset,
|
||||
expect.objectContaining({ id: 'proxy-1', label: '1080p (MP4)' }),
|
||||
)
|
||||
expect(mockOnClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('closes on Escape key or cancel button', async () => {
|
||||
vi.spyOn(importService, 'fetchVideoProxies').mockResolvedValue([])
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<ImportVideoDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onImportRaw={mockOnImportRaw}
|
||||
onImportProxy={mockOnImportProxy}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
const cancelBtn = screen.getByText('Cancel')
|
||||
fireEvent.click(cancelBtn)
|
||||
expect(mockOnClose).toHaveBeenCalledTimes(1)
|
||||
|
||||
act(() => {
|
||||
fireEvent.keyDown(document, { key: 'Escape' })
|
||||
})
|
||||
expect(mockOnClose).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,245 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react'
|
||||
import type { AssetSummary } from './FileItem'
|
||||
import { fetchVideoProxies, type ProxyOption } from '../services/import'
|
||||
import { formatBytes, formatDuration } from '../utils/format'
|
||||
import { resolveAssetUrl } from '../utils/url'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
|
||||
export interface ImportVideoDialogProps {
|
||||
asset: AssetSummary | null
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onImportRaw: (asset: AssetSummary) => void
|
||||
onImportProxy: (asset: AssetSummary, proxy: ProxyOption) => void
|
||||
}
|
||||
|
||||
export const ImportVideoDialog: React.FC<ImportVideoDialogProps> = ({
|
||||
asset,
|
||||
endpoint,
|
||||
apiKey,
|
||||
isOpen,
|
||||
onClose,
|
||||
onImportRaw,
|
||||
onImportProxy,
|
||||
}) => {
|
||||
const [selectedVersion, setSelectedVersion] = useState<'raw' | string>('raw')
|
||||
const [proxies, setProxies] = useState<ProxyOption[]>([])
|
||||
const [loadingProxies, setLoadingProxies] = useState(false)
|
||||
const [thumbError, setThumbError] = useState(false)
|
||||
|
||||
// Reset and fetch proxies when a new video asset is opened
|
||||
useEffect(() => {
|
||||
if (!isOpen || !asset) {
|
||||
setProxies([])
|
||||
setSelectedVersion('raw')
|
||||
setLoadingProxies(false)
|
||||
setThumbError(false)
|
||||
return
|
||||
}
|
||||
|
||||
let isMounted = true
|
||||
setLoadingProxies(true)
|
||||
setSelectedVersion('raw')
|
||||
|
||||
void fetchVideoProxies(endpoint, apiKey, asset.id)
|
||||
.then((items) => {
|
||||
if (isMounted) {
|
||||
setProxies(items)
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
console.warn('Failed to load video proxies:', err)
|
||||
})
|
||||
.finally(() => {
|
||||
if (isMounted) {
|
||||
setLoadingProxies(false)
|
||||
}
|
||||
})
|
||||
|
||||
return () => {
|
||||
isMounted = false
|
||||
}
|
||||
}, [isOpen, asset, endpoint, apiKey])
|
||||
|
||||
// Handle Escape key to close dialog
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape') {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('keydown', handleKeyDown)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyDown)
|
||||
}
|
||||
}, [isOpen, onClose])
|
||||
|
||||
const handleConfirm = useCallback(() => {
|
||||
if (!asset) return
|
||||
|
||||
if (selectedVersion === 'raw') {
|
||||
onClose()
|
||||
onImportRaw(asset)
|
||||
} else if (selectedVersion.startsWith('proxy:')) {
|
||||
const proxyId = selectedVersion.slice('proxy:'.length)
|
||||
const targetProxy = proxies.find((p) => p.id === proxyId)
|
||||
if (targetProxy) {
|
||||
onClose()
|
||||
onImportProxy(asset, targetProxy)
|
||||
}
|
||||
}
|
||||
}, [asset, selectedVersion, proxies, onClose, onImportRaw, onImportProxy])
|
||||
|
||||
if (!isOpen || !asset) return null
|
||||
|
||||
const effectiveSize = asset.sizeByte ?? asset.size
|
||||
const thumbUrl = resolveAssetUrl(asset.preview?.thumbnailUrl, endpoint)
|
||||
const duration = asset.preview?.duration ?? asset.media?.metadata?.duration
|
||||
const durationText = formatDuration(duration)
|
||||
|
||||
return (
|
||||
<div
|
||||
className="shumai-dialog-backdrop"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget) {
|
||||
onClose()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="shumai-dialog" role="dialog" aria-modal="true" aria-labelledby="dialog-title">
|
||||
{/* Dialog Header */}
|
||||
<div className="shumai-dialog-header">
|
||||
<span id="dialog-title" className="shumai-dialog-title">
|
||||
Import Video
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
className="shumai-dialog-close"
|
||||
onClick={onClose}
|
||||
title="Close dialog"
|
||||
aria-label="Close dialog"
|
||||
>
|
||||
<sp-icon-close size="s"></sp-icon-close>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Video Asset Preview Info */}
|
||||
<div className="shumai-dialog-asset-info">
|
||||
<div className="shumai-dialog-thumb">
|
||||
{thumbUrl && !thumbError ? (
|
||||
<img src={thumbUrl} alt={asset.name} onError={() => setThumbError(true)} />
|
||||
) : (
|
||||
<sp-icon-filmstrip size="xxl" style={{ color: '#60a5fa' }}></sp-icon-filmstrip>
|
||||
)}
|
||||
</div>
|
||||
<div className="shumai-dialog-asset-meta">
|
||||
<span className="shumai-dialog-asset-name" title={asset.name}>
|
||||
{asset.name}
|
||||
</span>
|
||||
<span className="shumai-dialog-asset-details">
|
||||
{durationText ? `${durationText} • ` : ''}
|
||||
{effectiveSize ? formatBytes(effectiveSize) : 'Video'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Options Selection Body */}
|
||||
<div className="shumai-dialog-body">
|
||||
<div className="shumai-dialog-section-label">Choose Version to Import</div>
|
||||
|
||||
{/* Original Version Card */}
|
||||
<div
|
||||
className={`shumai-option-card ${selectedVersion === 'raw' ? 'selected' : ''}`}
|
||||
onClick={() => setSelectedVersion('raw')}
|
||||
role="radio"
|
||||
aria-checked={selectedVersion === 'raw'}
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
setSelectedVersion('raw')
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="shumai-option-left">
|
||||
<div className="shumai-option-texts">
|
||||
<span className="shumai-option-title">Original File</span>
|
||||
<span className="shumai-option-meta">
|
||||
Full resolution • {effectiveSize ? formatBytes(effectiveSize) : 'Raw file'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="shumai-option-radio">
|
||||
{selectedVersion === 'raw' && <div className="shumai-option-radio-dot" />}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="shumai-dialog-divider" />
|
||||
|
||||
{/* Proxies Section */}
|
||||
<div className="shumai-dialog-section-label">Transcode Proxies</div>
|
||||
|
||||
{loadingProxies ? (
|
||||
<div className="shumai-dialog-loading">
|
||||
<ProgressCircle indeterminate size="s" label="Checking available proxies..." />
|
||||
<span>Checking available proxies...</span>
|
||||
</div>
|
||||
) : proxies.length > 0 ? (
|
||||
proxies.map((proxy) => {
|
||||
const isSelected = selectedVersion === `proxy:${proxy.id}`
|
||||
return (
|
||||
<div
|
||||
key={proxy.id}
|
||||
className={`shumai-option-card ${isSelected ? 'selected' : ''}`}
|
||||
onClick={() => setSelectedVersion(`proxy:${proxy.id}`)}
|
||||
role="radio"
|
||||
aria-checked={isSelected}
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
setSelectedVersion(`proxy:${proxy.id}`)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="shumai-option-left">
|
||||
<div className="shumai-option-texts">
|
||||
<span className="shumai-option-title">{proxy.label}</span>
|
||||
<span className="shumai-option-meta">
|
||||
{proxy.width && proxy.height ? `${proxy.width}x${proxy.height} • ` : ''}
|
||||
{proxy.size ? `${formatBytes(proxy.size)} • ` : ''}
|
||||
Fast editing proxy
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="shumai-option-radio">
|
||||
{isSelected && <div className="shumai-option-radio-dot" />}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<div className="shumai-dialog-empty-proxies">
|
||||
<span>No proxy transcodes available for this video.</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Dialog Footer Actions */}
|
||||
<div className="shumai-dialog-footer">
|
||||
<sp-button quiet variant="secondary" size="s" onClick={onClose}>
|
||||
Cancel
|
||||
</sp-button>
|
||||
<sp-button variant="accent" size="s" onClick={handleConfirm}>
|
||||
Import
|
||||
</sp-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React, { act } from 'react'
|
||||
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent, cleanup } from '@testing-library/react'
|
||||
import { LinkSequenceDialog } from './LinkSequenceDialog'
|
||||
import type { AssetSummary } from './FileItem'
|
||||
import * as premiereService from '../services/premiere'
|
||||
import * as linkStorage from '../services/linkStorage'
|
||||
import * as markersService from '../services/markers'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
|
||||
// Configure React 19 act environment for happy-dom
|
||||
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
describe('LinkSequenceDialog Component', () => {
|
||||
const mockOnClose = vi.fn()
|
||||
const mockOnLinkSuccess = vi.fn()
|
||||
|
||||
const videoAsset: AssetSummary = {
|
||||
id: 'asset-vid-1',
|
||||
name: 'interview_clip.mp4',
|
||||
type: 'file',
|
||||
mimeType: 'video/mp4',
|
||||
sizeByte: 1024 * 1024 * 45,
|
||||
preview: {
|
||||
duration: 154,
|
||||
},
|
||||
commentsCount: 3,
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
it('renders nothing when closed or asset is null', () => {
|
||||
const { container } = render(
|
||||
<LinkSequenceDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={false}
|
||||
onClose={mockOnClose}
|
||||
onLinkSuccess={mockOnLinkSuccess}
|
||||
/>,
|
||||
)
|
||||
expect(container.firstChild).toBeNull()
|
||||
|
||||
const { container: containerNull } = render(
|
||||
<LinkSequenceDialog
|
||||
asset={null}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onLinkSuccess={mockOnLinkSuccess}
|
||||
/>,
|
||||
)
|
||||
expect(containerNull.firstChild).toBeNull()
|
||||
})
|
||||
|
||||
it('displays error message when no active project is open', async () => {
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(null)
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<LinkSequenceDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onLinkSuccess={mockOnLinkSuccess}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
expect(screen.getByText(/no active premiere pro project found/i)).toBeDefined()
|
||||
})
|
||||
|
||||
it('lists project sequences and highlights active sequence without sequence icon', async () => {
|
||||
const mockSeq1 = { guid: 'seq-1', name: 'Rough Cut' }
|
||||
const mockSeq2 = { guid: 'seq-2', name: 'Fine Cut' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([
|
||||
mockSeq1,
|
||||
mockSeq2,
|
||||
] as unknown as Sequence[])
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(
|
||||
mockSeq2 as unknown as Sequence,
|
||||
)
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([])
|
||||
|
||||
let renderedContainer: HTMLElement = null!
|
||||
await act(async () => {
|
||||
const { container } = render(
|
||||
<LinkSequenceDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onLinkSuccess={mockOnLinkSuccess}
|
||||
/>,
|
||||
)
|
||||
renderedContainer = container
|
||||
})
|
||||
|
||||
expect(screen.getByText('Rough Cut')).toBeDefined()
|
||||
expect(screen.getByText('Fine Cut')).toBeDefined()
|
||||
expect(screen.getByText('Active')).toBeDefined()
|
||||
expect(renderedContainer.querySelectorAll('.shumai-option-card sp-icon-filmstrip').length).toBe(
|
||||
0,
|
||||
)
|
||||
})
|
||||
|
||||
it('executes sync and invokes onLinkSuccess on confirmation', async () => {
|
||||
const mockSeq1 = { guid: 'seq-1', name: 'Rough Cut' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([
|
||||
mockSeq1,
|
||||
] as unknown as Sequence[])
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(
|
||||
mockSeq1 as unknown as Sequence,
|
||||
)
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([])
|
||||
vi.spyOn(markersService, 'fetchAssetComments').mockResolvedValue([
|
||||
{ id: 'comm-1', second: 10, message: 'Test marker' } as unknown as CommentInfo,
|
||||
])
|
||||
|
||||
const mockUpdatedLink = {
|
||||
sequenceGuid: 'seq-1',
|
||||
sequenceName: 'Rough Cut',
|
||||
assetId: 'asset-vid-1',
|
||||
assetName: 'interview_clip.mp4',
|
||||
syncedCommentIds: ['comm-1'],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced: 1,
|
||||
}
|
||||
|
||||
vi.spyOn(markersService, 'syncCommentsToSequence').mockResolvedValue({
|
||||
updatedLink: mockUpdatedLink,
|
||||
addedCount: 1,
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<LinkSequenceDialog
|
||||
asset={videoAsset}
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
isOpen={true}
|
||||
onClose={mockOnClose}
|
||||
onLinkSuccess={mockOnLinkSuccess}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
const linkBtn = screen.getByText('Link Sequence')
|
||||
await act(async () => {
|
||||
fireEvent.click(linkBtn)
|
||||
})
|
||||
|
||||
expect(markersService.fetchAssetComments).toHaveBeenCalledWith(
|
||||
'https://api.shumai.test',
|
||||
'test-key',
|
||||
'asset-vid-1',
|
||||
)
|
||||
expect(markersService.syncCommentsToSequence).toHaveBeenCalledWith(
|
||||
mockProject,
|
||||
mockSeq1,
|
||||
expect.any(Array),
|
||||
expect.objectContaining({
|
||||
endpoint: 'https://api.shumai.test',
|
||||
sequenceGuid: 'seq-1',
|
||||
assetId: 'asset-vid-1',
|
||||
}),
|
||||
)
|
||||
expect(mockOnLinkSuccess).toHaveBeenCalledWith(mockUpdatedLink, 1)
|
||||
expect(mockOnClose).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,420 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react'
|
||||
import type { Sequence, Project } from '@adobe/premierepro'
|
||||
import type { AssetSummary } from './FileItem'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
import { getActiveProject, getAllSequences, getActiveSequence } from '../services/premiere'
|
||||
import { getAllLinkedSequences, normalizeGuid, removeSequenceLink } from '../services/linkStorage'
|
||||
import { fetchAssetComments, syncCommentsToSequence } from '../services/markers'
|
||||
import { resolveAssetUrl, isSameEndpoint } from '../utils/url'
|
||||
import { formatBytes, formatDuration } from '../utils/format'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
|
||||
export interface LinkSequenceDialogProps {
|
||||
asset: AssetSummary | null
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
isOpen: boolean
|
||||
onClose: () => void
|
||||
onLinkSuccess: (link: LinkedSequenceAsset, addedMarkersCount: number) => void
|
||||
}
|
||||
|
||||
interface SequenceOption {
|
||||
sequence: Sequence
|
||||
guid: string
|
||||
name: string
|
||||
isActive: boolean
|
||||
currentLink: LinkedSequenceAsset | null
|
||||
}
|
||||
|
||||
export const LinkSequenceDialog: React.FC<LinkSequenceDialogProps> = ({
|
||||
asset,
|
||||
endpoint,
|
||||
apiKey,
|
||||
isOpen,
|
||||
onClose,
|
||||
onLinkSuccess,
|
||||
}) => {
|
||||
const [project, setProject] = useState<Project | null>(null)
|
||||
const [sequences, setSequences] = useState<SequenceOption[]>([])
|
||||
const [selectedGuid, setSelectedGuid] = useState<string>('')
|
||||
const [loadingSequences, setLoadingSequences] = useState(true)
|
||||
const [linking, setLinking] = useState(false)
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null)
|
||||
const [thumbError, setThumbError] = useState(false)
|
||||
|
||||
// Load project sequences and link states when opened
|
||||
useEffect(() => {
|
||||
if (!isOpen || !asset) {
|
||||
setProject(null)
|
||||
setSequences([])
|
||||
setSelectedGuid('')
|
||||
setErrorMessage(null)
|
||||
setLinking(false)
|
||||
setThumbError(false)
|
||||
return
|
||||
}
|
||||
|
||||
let isMounted = true
|
||||
setLoadingSequences(true)
|
||||
setErrorMessage(null)
|
||||
|
||||
async function loadProjectData() {
|
||||
try {
|
||||
const pr = await getActiveProject()
|
||||
if (!isMounted) return
|
||||
|
||||
if (!pr) {
|
||||
setProject(null)
|
||||
setLoadingSequences(false)
|
||||
setErrorMessage('No active Premiere Pro project found. Please open a project first.')
|
||||
return
|
||||
}
|
||||
|
||||
setProject(pr)
|
||||
|
||||
const [allSeqs, activeSeq, existingLinks] = await Promise.all([
|
||||
getAllSequences(pr),
|
||||
getActiveSequence(pr),
|
||||
getAllLinkedSequences(pr),
|
||||
])
|
||||
|
||||
if (!isMounted) return
|
||||
|
||||
if (!allSeqs || allSeqs.length === 0) {
|
||||
setLoadingSequences(false)
|
||||
setErrorMessage(
|
||||
'No sequences found in the current project. Please create a sequence first.',
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const activeGuid = normalizeGuid(activeSeq?.guid)
|
||||
const linksMap = new Map<string, LinkedSequenceAsset>()
|
||||
for (const link of existingLinks) {
|
||||
if (!link.endpoint || isSameEndpoint(link.endpoint, endpoint)) {
|
||||
linksMap.set(normalizeGuid(link.sequenceGuid), link)
|
||||
}
|
||||
}
|
||||
|
||||
const options: SequenceOption[] = allSeqs.map((seq) => {
|
||||
const guidStr = normalizeGuid(seq.guid)
|
||||
return {
|
||||
sequence: seq,
|
||||
guid: guidStr,
|
||||
name: seq.name || 'Untitled Sequence',
|
||||
isActive: Boolean(activeGuid && guidStr === activeGuid),
|
||||
currentLink: linksMap.get(guidStr) || null,
|
||||
}
|
||||
})
|
||||
|
||||
setSequences(options)
|
||||
|
||||
// Pre-select active sequence if found, else first sequence
|
||||
if (activeGuid && options.some((opt) => opt.guid === activeGuid)) {
|
||||
setSelectedGuid(activeGuid)
|
||||
} else if (options.length > 0) {
|
||||
setSelectedGuid(options[0].guid)
|
||||
}
|
||||
} catch (err) {
|
||||
if (!isMounted) return
|
||||
console.error('[LinkSequenceDialog] Error loading project data:', err)
|
||||
setErrorMessage('Failed to load project sequences from Premiere Pro.')
|
||||
} finally {
|
||||
if (isMounted) {
|
||||
setLoadingSequences(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadProjectData()
|
||||
|
||||
return () => {
|
||||
isMounted = false
|
||||
}
|
||||
}, [isOpen, asset, endpoint])
|
||||
|
||||
// Escape key handler
|
||||
useEffect(() => {
|
||||
if (!isOpen) return
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && !linking) {
|
||||
onClose()
|
||||
}
|
||||
}
|
||||
document.addEventListener('keydown', handleKeyDown)
|
||||
return () => {
|
||||
document.removeEventListener('keydown', handleKeyDown)
|
||||
}
|
||||
}, [isOpen, linking, onClose])
|
||||
|
||||
const handleConfirm = useCallback(async () => {
|
||||
if (!asset || !project || !selectedGuid || linking) return
|
||||
const targetOption = sequences.find(
|
||||
(opt) => normalizeGuid(opt.guid) === normalizeGuid(selectedGuid),
|
||||
)
|
||||
if (!targetOption) return
|
||||
|
||||
setLinking(true)
|
||||
try {
|
||||
// If sequence was linked to another asset, remove its previous link and markers first
|
||||
if (targetOption.currentLink && targetOption.currentLink.assetId !== asset.id) {
|
||||
await removeSequenceLink(project, targetOption.sequence)
|
||||
}
|
||||
|
||||
// 1. Fetch timecoded comments for this asset
|
||||
const comments = await fetchAssetComments(endpoint, apiKey, asset.id)
|
||||
|
||||
// 2. Prepare initial link metadata
|
||||
const prGuidStr = project.guid ? normalizeGuid(project.guid) : undefined
|
||||
const initialLink: LinkedSequenceAsset = {
|
||||
sequenceGuid: normalizeGuid(targetOption.guid),
|
||||
sequenceName: targetOption.name,
|
||||
assetId: asset.id,
|
||||
assetName: asset.name,
|
||||
assetThumbnailUrl: asset.preview?.thumbnailUrl,
|
||||
endpoint: endpoint.trim().replace(/\/+$/, ''),
|
||||
projectId: prGuidStr,
|
||||
syncedCommentIds:
|
||||
targetOption.currentLink?.assetId === asset.id
|
||||
? targetOption.currentLink.syncedCommentIds
|
||||
: [],
|
||||
syncedMarkerGuids:
|
||||
targetOption.currentLink?.assetId === asset.id
|
||||
? (targetOption.currentLink.syncedMarkerGuids || []).map(normalizeGuid)
|
||||
: [],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced:
|
||||
targetOption.currentLink?.assetId === asset.id
|
||||
? targetOption.currentLink.totalCommentsSynced
|
||||
: 0,
|
||||
}
|
||||
|
||||
// 3. Translate comments to markers on the sequence
|
||||
const { updatedLink, addedCount } = await syncCommentsToSequence(
|
||||
project,
|
||||
targetOption.sequence,
|
||||
comments,
|
||||
initialLink,
|
||||
)
|
||||
|
||||
onLinkSuccess(updatedLink, addedCount)
|
||||
onClose()
|
||||
} catch (err) {
|
||||
console.error('[LinkSequenceDialog] Failed to link sequence:', err)
|
||||
setErrorMessage('Failed to link sequence and sync markers. Please try again.')
|
||||
} finally {
|
||||
setLinking(false)
|
||||
}
|
||||
}, [asset, project, selectedGuid, linking, sequences, endpoint, apiKey, onLinkSuccess, onClose])
|
||||
|
||||
if (!isOpen || !asset) return null
|
||||
|
||||
const selectedOption = sequences.find((opt) => opt.guid === selectedGuid)
|
||||
const isReplacingOtherAsset =
|
||||
selectedOption?.currentLink && selectedOption.currentLink.assetId !== asset.id
|
||||
|
||||
const effectiveSize = asset.sizeByte ?? asset.size
|
||||
const thumbUrl = resolveAssetUrl(asset.preview?.thumbnailUrl, endpoint)
|
||||
const duration = asset.preview?.duration ?? asset.media?.metadata?.duration
|
||||
const durationText = formatDuration(duration)
|
||||
|
||||
return (
|
||||
<div
|
||||
className="shumai-dialog-backdrop"
|
||||
onClick={(e) => {
|
||||
if (e.target === e.currentTarget && !linking) {
|
||||
onClose()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="shumai-dialog"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-labelledby="link-dialog-title"
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="shumai-dialog-header">
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<sp-icon-link size="s" style={{ marginRight: 6, color: '#3b82f6' }}></sp-icon-link>
|
||||
<span id="link-dialog-title" className="shumai-dialog-title">
|
||||
Link to Sequence
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="shumai-dialog-close"
|
||||
onClick={onClose}
|
||||
disabled={linking}
|
||||
title="Close dialog"
|
||||
aria-label="Close dialog"
|
||||
>
|
||||
<sp-icon-close size="s"></sp-icon-close>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Asset Info Card */}
|
||||
<div className="shumai-dialog-asset-info">
|
||||
<div className="shumai-dialog-thumb">
|
||||
{thumbUrl && !thumbError ? (
|
||||
<img src={thumbUrl} alt={asset.name} onError={() => setThumbError(true)} />
|
||||
) : asset.type === 'video' ? (
|
||||
<sp-icon-filmstrip size="xxl" style={{ color: '#60a5fa' }}></sp-icon-filmstrip>
|
||||
) : asset.type === 'audio' ? (
|
||||
<sp-icon-audio size="xxl" style={{ color: '#a78bfa' }}></sp-icon-audio>
|
||||
) : (
|
||||
<sp-icon-document size="xxl" style={{ color: '#999999' }}></sp-icon-document>
|
||||
)}
|
||||
</div>
|
||||
<div className="shumai-dialog-asset-meta">
|
||||
<span className="shumai-dialog-asset-name" title={asset.name}>
|
||||
{asset.name}
|
||||
</span>
|
||||
<span className="shumai-dialog-asset-details">
|
||||
{durationText ? `${durationText} • ` : ''}
|
||||
{effectiveSize ? `${formatBytes(effectiveSize)} • ` : ''}
|
||||
{asset.commentsCount != null && asset.commentsCount > 0
|
||||
? `${asset.commentsCount} comments`
|
||||
: 'No comments'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Dialog Body */}
|
||||
<div className="shumai-dialog-body">
|
||||
<div className="shumai-dialog-section-label">Select Sequence in Project</div>
|
||||
|
||||
{loadingSequences ? (
|
||||
<div className="shumai-dialog-loading">
|
||||
<ProgressCircle indeterminate size="s" label="Checking project sequences..." />
|
||||
<span>Checking project sequences...</span>
|
||||
</div>
|
||||
) : errorMessage ? (
|
||||
<div className="shumai-dialog-empty-proxies" style={{ color: '#f87171' }}>
|
||||
<span>{errorMessage}</span>
|
||||
</div>
|
||||
) : sequences.length > 0 ? (
|
||||
sequences.map((opt) => {
|
||||
const isSelected = selectedGuid === opt.guid
|
||||
const isLinkedToAnother = opt.currentLink && opt.currentLink.assetId !== asset.id
|
||||
const isLinkedToThis = opt.currentLink && opt.currentLink.assetId === asset.id
|
||||
|
||||
return (
|
||||
<div
|
||||
key={opt.guid}
|
||||
className={`shumai-option-card ${isSelected ? 'selected' : ''}`}
|
||||
onClick={() => !linking && setSelectedGuid(opt.guid)}
|
||||
role="radio"
|
||||
aria-checked={isSelected}
|
||||
tabIndex={0}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
if (!linking) setSelectedGuid(opt.guid)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="shumai-option-left">
|
||||
<div className="shumai-option-texts">
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="shumai-option-title">{opt.name}</span>
|
||||
{opt.isActive && (
|
||||
<span
|
||||
style={{
|
||||
fontSize: '10px',
|
||||
marginLeft: 6,
|
||||
padding: '1px 5px',
|
||||
borderRadius: '3px',
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.2)',
|
||||
color: '#60a5fa',
|
||||
fontWeight: 500,
|
||||
}}
|
||||
>
|
||||
Active
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="shumai-option-meta">
|
||||
{isLinkedToThis ? (
|
||||
<span style={{ color: '#34d399' }}>Already linked to this asset</span>
|
||||
) : isLinkedToAnother ? (
|
||||
<span style={{ color: '#fbbf24' }}>
|
||||
Linked to "{opt.currentLink?.assetName}" (will replace)
|
||||
</span>
|
||||
) : (
|
||||
'Ready to link'
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="shumai-option-radio">
|
||||
{isSelected && <div className="shumai-option-radio-dot" />}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})
|
||||
) : (
|
||||
<div className="shumai-dialog-empty-proxies">
|
||||
<span>No sequences available in current project.</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{isReplacingOtherAsset && (
|
||||
<div
|
||||
style={{
|
||||
marginTop: 10,
|
||||
padding: '8px 10px',
|
||||
borderRadius: 4,
|
||||
backgroundColor: 'rgba(245, 158, 11, 0.12)',
|
||||
border: '1px solid rgba(245, 158, 11, 0.3)',
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
fontSize: 11,
|
||||
color: '#fbbf24',
|
||||
}}
|
||||
>
|
||||
<sp-icon-alert-triangle
|
||||
size="s"
|
||||
style={{ marginRight: 6, flexShrink: 0 }}
|
||||
></sp-icon-alert-triangle>
|
||||
<span>
|
||||
This sequence is already linked to another asset. Proceeding will replace the link
|
||||
and sync markers for this asset.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{ marginTop: 12, fontSize: 11, color: 'var(--text-secondary)' }}>
|
||||
Comments with timestamps will be placed on the sequence timeline as markers. Markers
|
||||
deleted in Premiere Pro will not be re-synced.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Footer */}
|
||||
<div className="shumai-dialog-footer">
|
||||
<sp-button quiet variant="secondary" size="s" onClick={onClose} disabled={linking}>
|
||||
Cancel
|
||||
</sp-button>
|
||||
<sp-button
|
||||
variant="accent"
|
||||
size="s"
|
||||
onClick={handleConfirm}
|
||||
disabled={!selectedGuid || loadingSequences || Boolean(errorMessage) || linking}
|
||||
>
|
||||
{linking ? (
|
||||
<>
|
||||
<ProgressCircle indeterminate size="s" slot="icon" label="Linking..." />
|
||||
Linking...
|
||||
</>
|
||||
) : isReplacingOtherAsset ? (
|
||||
'Replace & Link'
|
||||
) : (
|
||||
'Link Sequence'
|
||||
)}
|
||||
</sp-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React from 'react'
|
||||
import { describe, it, expect, vi, afterEach } from 'vitest'
|
||||
import { render, screen, fireEvent, cleanup } from '@testing-library/react'
|
||||
import { NavigationTabs } from './NavigationTabs'
|
||||
|
||||
describe('NavigationTabs Component', () => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
it('renders Sequences and Browse tabs with badge', () => {
|
||||
const handleTabChange = vi.fn()
|
||||
render(<NavigationTabs activeTab="sequences" onTabChange={handleTabChange} linkedCount={3} />)
|
||||
|
||||
expect(screen.getByText('Sequences')).toBeDefined()
|
||||
expect(screen.getByText('Browse')).toBeDefined()
|
||||
expect(screen.getByText('3')).toBeDefined()
|
||||
})
|
||||
|
||||
it('handles tab click events', () => {
|
||||
const handleTabChange = vi.fn()
|
||||
render(<NavigationTabs activeTab="sequences" onTabChange={handleTabChange} linkedCount={0} />)
|
||||
|
||||
const browseTab = screen.getByText('Browse')
|
||||
fireEvent.click(browseTab)
|
||||
expect(handleTabChange).toHaveBeenCalledWith('browse')
|
||||
|
||||
const sequencesTab = screen.getByText('Sequences')
|
||||
fireEvent.click(sequencesTab)
|
||||
expect(handleTabChange).toHaveBeenCalledWith('sequences')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,44 @@
|
||||
import React from 'react'
|
||||
|
||||
export type MainTab = 'sequences' | 'browse'
|
||||
|
||||
export interface NavigationTabsProps {
|
||||
activeTab: MainTab
|
||||
onTabChange: (tab: MainTab) => void
|
||||
linkedCount?: number
|
||||
}
|
||||
|
||||
export const NavigationTabs: React.FC<NavigationTabsProps> = ({
|
||||
activeTab,
|
||||
onTabChange,
|
||||
linkedCount = 0,
|
||||
}) => {
|
||||
return (
|
||||
<div className="shumai-nav-tabs-bar" role="tablist">
|
||||
<sp-button
|
||||
size="s"
|
||||
variant={activeTab === 'sequences' ? 'accent' : 'secondary'}
|
||||
treatment="fill"
|
||||
onClick={() => onTabChange('sequences')}
|
||||
className={`shumai-tab-sp-btn ${activeTab === 'sequences' ? 'active' : ''}`}
|
||||
>
|
||||
<span className="shumai-tab-label">Sequences</span>
|
||||
{linkedCount > 0 && (
|
||||
<span className="shumai-tab-badge" title={`${linkedCount} linked sequence assets`}>
|
||||
{linkedCount}
|
||||
</span>
|
||||
)}
|
||||
</sp-button>
|
||||
|
||||
<sp-button
|
||||
size="s"
|
||||
variant={activeTab === 'browse' ? 'accent' : 'secondary'}
|
||||
treatment="fill"
|
||||
onClick={() => onTabChange('browse')}
|
||||
className={`shumai-tab-sp-btn ${activeTab === 'browse' ? 'active' : ''}`}
|
||||
>
|
||||
<span className="shumai-tab-label">Browse</span>
|
||||
</sp-button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import React, { useState } from 'react'
|
||||
import { formatDateAgo } from '../utils/date'
|
||||
import { resolveAssetUrl } from '../utils/url'
|
||||
import type { ProjectSummary } from '../views/ProjectsView'
|
||||
|
||||
interface ProjectCardProps {
|
||||
project: ProjectSummary
|
||||
endpoint?: string
|
||||
onClick: () => void
|
||||
}
|
||||
|
||||
export const ShumaiPolygonCover: React.FC = () => (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 180.95 164.7"
|
||||
preserveAspectRatio="xMidYMid slice"
|
||||
style={{ width: '100%', height: '100%', display: 'block' }}
|
||||
>
|
||||
<polygon fill="#FC9F8E" points="0 18.5 0 76.0 151.69 164.7 180.95 164.7 180.95 113.6" />
|
||||
<polygon fill="#FEBAB8" points="0 0 74.58 61.5 90.53 51.6 110.33 63.9 180.95 18.9 180.95 0" />
|
||||
<polyline
|
||||
fill="#FAA5A5"
|
||||
points="0 18.5 74.58 61.5 90.53 51.6 110.33 63.9 180.95 18.9 180.95 0 0 0"
|
||||
/>
|
||||
<polygon fill="#EC5B6C" points="0 76.0 0 164.7 151.69 164.7" />
|
||||
<polygon fill="#E85C71" points="180.95 18.9 110.33 63.9 117.37 68.0 117.26 73.4 180.95 113.6" />
|
||||
<polygon
|
||||
fill="#C8405B"
|
||||
points="117.26 73.4 117.37 99.0 90.53 114.9 174.35 164.7 180.95 164.7 180.95 113.6"
|
||||
/>
|
||||
<polygon fill="#FFCCBE" points="90.53 51.6 63.69 68.1 90.53 83.4" />
|
||||
<path
|
||||
fill="#FB9991"
|
||||
d="M 90.53 51.6 L 90.53 61.3 L 100.87 67.4 L 90.53 73.5 L 90.53 83.4 L 117.37 68.0 C 117.15 67.6 90.53 51.6 90.53 51.6 Z"
|
||||
/>
|
||||
<path
|
||||
fill="#FFEACD"
|
||||
d="M 63.69 68.1 C 63.47 68.5 64.02 99.3 64.02 99.3 C 64.02 99.3 64.46 99.6 64.9 99.9 L 90.53 83.4 L 63.69 68.1 Z"
|
||||
/>
|
||||
<polygon fill="#FFCFB5" points="64.02 99.3 90.53 114.9 90.53 83.4" />
|
||||
<path fill="#F67D73" d="M 90.53 83.4 L 90.53 114.9 L 117.37 99.0 Z" />
|
||||
<path fill="#F26560" d="M 90.53 83.4 L 117.37 99.0 L 117.37 68.0 Z" />
|
||||
<polygon fill="#EB5F5B" points="80.08 67.5 90.53 73.5 90.53 61.3" />
|
||||
<polygon fill="#DB4D50" points="90.53 61.3 90.53 73.5 100.87 67.4" />
|
||||
</svg>
|
||||
)
|
||||
|
||||
export const ProjectCard: React.FC<ProjectCardProps> = ({ project, endpoint, onClick }) => {
|
||||
const [imgError, setImgError] = useState(false)
|
||||
const updatedText = formatDateAgo(project.updatedAt)
|
||||
const coverUrl = resolveAssetUrl(project.coverImage, endpoint)
|
||||
|
||||
return (
|
||||
<div
|
||||
className="project-row-card"
|
||||
onClick={onClick}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
title={project.name}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
onClick()
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="project-row-preview">
|
||||
{coverUrl && !imgError ? (
|
||||
<img
|
||||
src={coverUrl}
|
||||
alt={project.name}
|
||||
className="project-row-img"
|
||||
onError={() => setImgError(true)}
|
||||
/>
|
||||
) : (
|
||||
<ShumaiPolygonCover />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="project-row-content">
|
||||
<span className="project-row-title">{project.name}</span>
|
||||
<span className="project-row-subtext">
|
||||
{updatedText ? `Updated ${updatedText}` : 'Project'}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import React from 'react'
|
||||
|
||||
export const ShumaiLogo: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {
|
||||
return (
|
||||
<svg viewBox="0 0 100 100" fill="none" xmlns="http://www.w3.org/2000/svg" {...props}>
|
||||
<defs>
|
||||
<clipPath id="bg-clip">
|
||||
<rect x="5" y="5" width="90" height="90" rx="22" />
|
||||
</clipPath>
|
||||
</defs>
|
||||
|
||||
{/* Background */}
|
||||
<rect x="5" y="5" width="90" height="90" rx="22" fill="#D95A66" />
|
||||
|
||||
{/* Long Shadow */}
|
||||
<path
|
||||
d="M 35 75 L 65 75 L 80 60 L 75 30 L 175 130 L 135 175 Z"
|
||||
fill="#A8384D"
|
||||
clipPath="url(#bg-clip)"
|
||||
/>
|
||||
|
||||
{/* Left Cream */}
|
||||
<path d="M 25 30 Q 38 36 50 42 L 35 55 L 35 75 L 20 60 Z" fill="#FDF0D5" />
|
||||
|
||||
{/* Right Orange */}
|
||||
<path d="M 50 42 Q 62 36 75 30 L 80 60 L 65 75 L 65 55 Z" fill="#E77A65" />
|
||||
|
||||
{/* Front Peach */}
|
||||
<path d="M 35 75 L 65 75 L 65 55 L 50 42 L 35 55 Z" fill="#F5B895" />
|
||||
|
||||
{/* Top Pink */}
|
||||
<path d="M 50 42 Q 38 36 25 30 Q 38 26 50 20 Q 62 26 75 30 Q 62 36 50 42 Z" fill="#F4B8B8" />
|
||||
|
||||
{/* Hole Left */}
|
||||
<path d="M 50 25 L 42 30 L 50 35 Z" fill="#E57A5F" />
|
||||
|
||||
{/* Hole Right */}
|
||||
<path d="M 50 25 L 58 30 L 50 35 Z" fill="#C2523C" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
+299
@@ -0,0 +1,299 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention -- Custom element tag names in IntrinsicElements require hyphens */
|
||||
declare module '@swc-uxp-wrappers/utils' {
|
||||
export const aliases: Record<string, string>
|
||||
}
|
||||
|
||||
type SpIconCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
size?: 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'
|
||||
slot?: string
|
||||
name?: string
|
||||
label?: string
|
||||
}
|
||||
|
||||
type SpButtonCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
HTMLButtonElement
|
||||
> & {
|
||||
variant?: 'accent' | 'primary' | 'secondary' | 'negative' | 'white' | 'black' | string
|
||||
treatment?: 'fill' | 'outline' | string
|
||||
quiet?: boolean
|
||||
size?: 'xs' | 's' | 'm' | 'l' | 'xl'
|
||||
label?: string
|
||||
'icon-only'?: boolean
|
||||
disabled?: boolean
|
||||
slot?: string
|
||||
}
|
||||
|
||||
type SpButtonGroupCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
vertical?: boolean
|
||||
size?: 'xs' | 's' | 'm' | 'l' | 'xl'
|
||||
}
|
||||
|
||||
type SpActionButtonCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
HTMLButtonElement
|
||||
> & {
|
||||
quiet?: boolean
|
||||
size?: 'xs' | 's' | 'm' | 'l' | 'xl'
|
||||
label?: string
|
||||
disabled?: boolean
|
||||
selected?: boolean
|
||||
toggles?: boolean
|
||||
emphasized?: boolean
|
||||
slot?: string
|
||||
}
|
||||
|
||||
type SpActionMenuCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
quiet?: boolean
|
||||
size?: 'xs' | 's' | 'm' | 'l' | 'xl'
|
||||
label?: string
|
||||
disabled?: boolean
|
||||
open?: boolean
|
||||
placement?:
|
||||
| 'top'
|
||||
| 'top-start'
|
||||
| 'top-end'
|
||||
| 'right'
|
||||
| 'right-start'
|
||||
| 'right-end'
|
||||
| 'bottom'
|
||||
| 'bottom-start'
|
||||
| 'bottom-end'
|
||||
| 'left'
|
||||
| 'left-start'
|
||||
| 'left-end'
|
||||
'force-popover'?: boolean
|
||||
selects?: 'single'
|
||||
value?: string
|
||||
slot?: string
|
||||
}
|
||||
|
||||
type SpMenuCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
slot?: string
|
||||
selects?: 'single' | 'multiple' | 'inherit'
|
||||
label?: string
|
||||
}
|
||||
|
||||
type SpMenuItemCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
disabled?: boolean
|
||||
selected?: boolean
|
||||
value?: string
|
||||
slot?: string
|
||||
}
|
||||
|
||||
type SpMenuDividerCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
size?: 's' | 'm' | 'l'
|
||||
}
|
||||
|
||||
type SpMenuGroupCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
slot?: string
|
||||
}
|
||||
|
||||
type SpStatusLightCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
variant?:
|
||||
| 'negative'
|
||||
| 'notice'
|
||||
| 'positive'
|
||||
| 'info'
|
||||
| 'neutral'
|
||||
| 'yellow'
|
||||
| 'fuchsia'
|
||||
| 'indigo'
|
||||
| 'seafoam'
|
||||
| 'chartreuse'
|
||||
| 'magenta'
|
||||
| 'celery'
|
||||
| 'purple'
|
||||
| string
|
||||
disabled?: boolean
|
||||
slot?: string
|
||||
}
|
||||
|
||||
type SpProgressCircleCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
size?: 's' | 'm' | 'l'
|
||||
indeterminate?: boolean
|
||||
label?: string
|
||||
slot?: string
|
||||
'static-color'?: 'white' | string
|
||||
}
|
||||
|
||||
type SpTopNavCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
selected?: string
|
||||
quiet?: boolean
|
||||
compact?: boolean
|
||||
label?: string
|
||||
}
|
||||
|
||||
type SpTopNavItemCustomElementProps = import('react').DetailedHTMLProps<
|
||||
import('react').HTMLAttributes<HTMLElement>,
|
||||
HTMLElement
|
||||
> & {
|
||||
value?: string
|
||||
selected?: boolean
|
||||
href?: string
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
declare namespace React {
|
||||
namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
'sp-icon': SpIconCustomElementProps
|
||||
'sp-icon-refresh': SpIconCustomElementProps
|
||||
'sp-icon-chevron-down': SpIconCustomElementProps
|
||||
'sp-icon-chevron-right': SpIconCustomElementProps
|
||||
'sp-icon-log-out': SpIconCustomElementProps
|
||||
'sp-icon-arrow-right': SpIconCustomElementProps
|
||||
'sp-icon-filmstrip': SpIconCustomElementProps
|
||||
'sp-icon-folder': SpIconCustomElementProps
|
||||
'sp-icon-folder-open': SpIconCustomElementProps
|
||||
'sp-icon-audio': SpIconCustomElementProps
|
||||
'sp-icon-image': SpIconCustomElementProps
|
||||
'sp-icon-document': SpIconCustomElementProps
|
||||
'sp-icon-link': SpIconCustomElementProps
|
||||
'sp-icon-unlink': SpIconCustomElementProps
|
||||
'sp-icon-link-out': SpIconCustomElementProps
|
||||
'sp-icon-download': SpIconCustomElementProps
|
||||
'sp-icon-briefcase': SpIconCustomElementProps
|
||||
'sp-icon-alert-circle': SpIconCustomElementProps
|
||||
'sp-icon-alert-triangle': SpIconCustomElementProps
|
||||
'sp-icon-checkmark-circle': SpIconCustomElementProps
|
||||
'sp-icon-close': SpIconCustomElementProps
|
||||
'sp-icon-movie-camera': SpIconCustomElementProps
|
||||
'sp-icon-video-filled': SpIconCustomElementProps
|
||||
'sp-button': SpButtonCustomElementProps
|
||||
'sp-button-group': SpButtonGroupCustomElementProps
|
||||
'sp-action-button': SpActionButtonCustomElementProps
|
||||
'sp-action-menu': SpActionMenuCustomElementProps
|
||||
'sp-menu': SpMenuCustomElementProps
|
||||
'sp-menu-item': SpMenuItemCustomElementProps
|
||||
'sp-menu-divider': SpMenuDividerCustomElementProps
|
||||
'sp-menu-group': SpMenuGroupCustomElementProps
|
||||
'sp-status-light': SpStatusLightCustomElementProps
|
||||
'sp-progress-circle': SpProgressCircleCustomElementProps
|
||||
'sp-top-nav': SpTopNavCustomElementProps
|
||||
'sp-top-nav-item': SpTopNavItemCustomElementProps
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
declare namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
'sp-icon': SpIconCustomElementProps
|
||||
'sp-icon-refresh': SpIconCustomElementProps
|
||||
'sp-icon-chevron-down': SpIconCustomElementProps
|
||||
'sp-icon-chevron-right': SpIconCustomElementProps
|
||||
'sp-icon-log-out': SpIconCustomElementProps
|
||||
'sp-icon-arrow-right': SpIconCustomElementProps
|
||||
'sp-icon-filmstrip': SpIconCustomElementProps
|
||||
'sp-icon-folder': SpIconCustomElementProps
|
||||
'sp-icon-folder-open': SpIconCustomElementProps
|
||||
'sp-icon-audio': SpIconCustomElementProps
|
||||
'sp-icon-image': SpIconCustomElementProps
|
||||
'sp-icon-document': SpIconCustomElementProps
|
||||
'sp-icon-link': SpIconCustomElementProps
|
||||
'sp-icon-unlink': SpIconCustomElementProps
|
||||
'sp-icon-link-out': SpIconCustomElementProps
|
||||
'sp-icon-download': SpIconCustomElementProps
|
||||
'sp-icon-briefcase': SpIconCustomElementProps
|
||||
'sp-icon-alert-circle': SpIconCustomElementProps
|
||||
'sp-icon-alert-triangle': SpIconCustomElementProps
|
||||
'sp-icon-checkmark-circle': SpIconCustomElementProps
|
||||
'sp-icon-close': SpIconCustomElementProps
|
||||
'sp-icon-movie-camera': SpIconCustomElementProps
|
||||
'sp-icon-video-filled': SpIconCustomElementProps
|
||||
'sp-button': SpButtonCustomElementProps
|
||||
'sp-button-group': SpButtonGroupCustomElementProps
|
||||
'sp-action-button': SpActionButtonCustomElementProps
|
||||
'sp-action-menu': SpActionMenuCustomElementProps
|
||||
'sp-menu': SpMenuCustomElementProps
|
||||
'sp-menu-item': SpMenuItemCustomElementProps
|
||||
'sp-menu-divider': SpMenuDividerCustomElementProps
|
||||
'sp-menu-group': SpMenuGroupCustomElementProps
|
||||
'sp-status-light': SpStatusLightCustomElementProps
|
||||
'sp-progress-circle': SpProgressCircleCustomElementProps
|
||||
'sp-top-nav': SpTopNavCustomElementProps
|
||||
'sp-top-nav-item': SpTopNavItemCustomElementProps
|
||||
}
|
||||
}
|
||||
|
||||
type UxpEntry = UxpFileEntry | UxpFolderEntry
|
||||
|
||||
interface UxpFileEntry {
|
||||
readonly isFile: true
|
||||
readonly isFolder: false
|
||||
readonly name: string
|
||||
readonly nativePath: string
|
||||
write(data: ArrayBuffer | string, options?: { format?: unknown; append?: boolean }): Promise<void>
|
||||
}
|
||||
|
||||
interface UxpFolderEntry {
|
||||
readonly isFile: false
|
||||
readonly isFolder: true
|
||||
readonly name: string
|
||||
readonly nativePath: string
|
||||
createFile(name: string, options?: { overwrite?: boolean }): Promise<UxpFileEntry>
|
||||
getEntries(): Promise<UxpEntry[]>
|
||||
getFiles?(): Promise<UxpFileEntry[]>
|
||||
}
|
||||
|
||||
interface UxpLocalFileSystem {
|
||||
getFileForSaving(
|
||||
defaultName?: string,
|
||||
options?: { types?: string[] },
|
||||
): Promise<UxpFileEntry | null>
|
||||
getFileForOpening(options?: {
|
||||
allowMultiple?: boolean
|
||||
types?: string[]
|
||||
}): Promise<UxpFileEntry | UxpFileEntry[] | null>
|
||||
getFolder(): Promise<UxpFolderEntry | null>
|
||||
getTemporaryFolder(): Promise<UxpFolderEntry>
|
||||
getDataFolder(): Promise<UxpFolderEntry>
|
||||
getPluginFolder(): Promise<UxpFolderEntry>
|
||||
}
|
||||
|
||||
interface UxpStorageFormats {
|
||||
readonly binary: unknown
|
||||
readonly utf8: unknown
|
||||
}
|
||||
|
||||
interface UxpModule {
|
||||
storage: {
|
||||
localFileSystem: UxpLocalFileSystem
|
||||
formats: UxpStorageFormats
|
||||
}
|
||||
}
|
||||
|
||||
declare module 'uxp' {
|
||||
const uxp: UxpModule
|
||||
export = uxp
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import './polyfills'
|
||||
import React from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { Theme } from '@swc-react/theme'
|
||||
import '@spectrum-web-components/theme/theme-dark.js'
|
||||
import '@spectrum-web-components/theme/theme-darkest.js'
|
||||
import '@spectrum-web-components/theme/theme-light.js'
|
||||
import '@spectrum-web-components/theme/scale-medium.js'
|
||||
import '@swc-uxp-wrappers/button/sp-button.js'
|
||||
import '@swc-uxp-wrappers/action-button/sp-action-button.js'
|
||||
import '@swc-uxp-wrappers/menu/sp-menu.js'
|
||||
import '@swc-uxp-wrappers/menu/sp-menu-item.js'
|
||||
import '@swc-uxp-wrappers/menu/sp-menu-divider.js'
|
||||
import '@swc-uxp-wrappers/menu/sp-menu-group.js'
|
||||
import '@swc-uxp-wrappers/popover/sp-popover.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-refresh.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-chevron-down.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-chevron-right.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-log-out.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-arrow-right.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-filmstrip.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-folder.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-folder-open.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-audio.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-image.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-document.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-link.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-unlink.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-link-out.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-download.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-briefcase.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert-circle.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-alert-triangle.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-checkmark-circle.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-close.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-movie-camera.js'
|
||||
import '@spectrum-web-components/icons-workflow/icons/sp-icon-video-filled.js'
|
||||
import { App } from './App'
|
||||
|
||||
const container = document.getElementById('root')
|
||||
if (container) {
|
||||
const root = createRoot(container)
|
||||
root.render(
|
||||
<React.StrictMode>
|
||||
<Theme theme="spectrum" scale="medium" color="dark">
|
||||
<App />
|
||||
</Theme>
|
||||
</React.StrictMode>,
|
||||
)
|
||||
} else {
|
||||
console.error('Failed to find root container element')
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import './polyfills'
|
||||
|
||||
describe('polyfills', () => {
|
||||
it('defines window.matchMedia polyfill when missing', () => {
|
||||
expect(typeof window.matchMedia).toBe('function')
|
||||
const mql = window.matchMedia('(prefers-color-scheme: dark)')
|
||||
expect(mql).toBeDefined()
|
||||
expect(mql.matches).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
// Guard against duplicate custom element registrations during UXP development and plugin reload
|
||||
if (typeof window !== 'undefined' && window.customElements) {
|
||||
const origDefine = window.customElements.define.bind(window.customElements)
|
||||
window.customElements.define = (
|
||||
name: string,
|
||||
constructor: CustomElementConstructor,
|
||||
options?: ElementDefinitionOptions,
|
||||
) => {
|
||||
if (window.customElements.get(name)) {
|
||||
return
|
||||
}
|
||||
origDefine(name, constructor, options)
|
||||
}
|
||||
}
|
||||
|
||||
// Polyfill window.matchMedia for Adobe UXP environment
|
||||
if (typeof window !== 'undefined' && typeof window.matchMedia !== 'function') {
|
||||
window.matchMedia = (query: string): MediaQueryList => {
|
||||
const mql: MediaQueryList = {
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
addListener: () => {},
|
||||
removeListener: () => {},
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
dispatchEvent: () => false,
|
||||
}
|
||||
return mql
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
|
||||
import { autoSyncService } from './autoSyncService'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
import * as premiereService from './premiere'
|
||||
import * as linkStorage from './linkStorage'
|
||||
import * as markersService from './markers'
|
||||
|
||||
describe('autoSyncService', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
vi.restoreAllMocks()
|
||||
autoSyncService.stop()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
autoSyncService.stop()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('starts and stops background interval without throwing', () => {
|
||||
autoSyncService.start('https://api.shumai.test', 'test-key')
|
||||
expect(autoSyncService['timer']).not.toBeNull()
|
||||
|
||||
autoSyncService.stop()
|
||||
expect(autoSyncService['timer']).toBeNull()
|
||||
})
|
||||
|
||||
it('syncs all linked sequences on triggerImmediateSync', async () => {
|
||||
const mockSeq = { guid: 'seq-1', name: 'Seq 1' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
const mockLink = {
|
||||
sequenceGuid: 'seq-1',
|
||||
sequenceName: 'Seq 1',
|
||||
assetId: 'asset-1',
|
||||
assetName: 'video.mp4',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: 0,
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([mockSeq as unknown as Sequence])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([mockLink])
|
||||
vi.spyOn(markersService, 'fetchAssetComments').mockResolvedValue([
|
||||
{ id: 'comm-1', second: 5, message: 'hello' } as unknown as CommentInfo,
|
||||
])
|
||||
vi.spyOn(markersService, 'syncCommentsToSequence').mockResolvedValue({
|
||||
updatedLink: { ...mockLink, syncedCommentIds: ['comm-1'] },
|
||||
addedCount: 1,
|
||||
})
|
||||
|
||||
autoSyncService.start('https://api.shumai.test', 'test-key')
|
||||
await autoSyncService.triggerImmediateSync()
|
||||
|
||||
expect(markersService.fetchAssetComments).toHaveBeenCalledWith(
|
||||
'https://api.shumai.test',
|
||||
'test-key',
|
||||
'asset-1',
|
||||
)
|
||||
expect(markersService.syncCommentsToSequence).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('normalizes sequence GUIDs with braces and uppercase when matching against linked sequences', async () => {
|
||||
const mockSeq = { guid: '{B991F605-7BD7-4028-B05F-0BC36B66CD0A}', name: 'Seq Braced' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
const mockLink = {
|
||||
sequenceGuid: 'b991f605-7bd7-4028-b05f-0bc36b66cd0a',
|
||||
sequenceName: 'Seq Braced',
|
||||
assetId: 'asset-99',
|
||||
assetName: 'video.mp4',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: 0,
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([mockSeq as unknown as Sequence])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([mockLink])
|
||||
vi.spyOn(markersService, 'fetchAssetComments').mockResolvedValue([
|
||||
{ id: 'comm-1', second: 1, message: 'braced guid comment' } as unknown as CommentInfo,
|
||||
])
|
||||
vi.spyOn(markersService, 'syncCommentsToSequence').mockResolvedValue({
|
||||
updatedLink: { ...mockLink, syncedCommentIds: ['comm-1'] },
|
||||
addedCount: 1,
|
||||
})
|
||||
|
||||
autoSyncService.start('https://api.shumai.test', 'test-key')
|
||||
await autoSyncService.triggerImmediateSync()
|
||||
|
||||
expect(markersService.fetchAssetComments).toHaveBeenCalledWith(
|
||||
'https://api.shumai.test',
|
||||
'test-key',
|
||||
'asset-99',
|
||||
)
|
||||
expect(markersService.syncCommentsToSequence).toHaveBeenCalledWith(
|
||||
mockProject,
|
||||
mockSeq,
|
||||
expect.any(Array),
|
||||
mockLink,
|
||||
)
|
||||
})
|
||||
|
||||
it('skips linked sequences configured for a different server endpoint', async () => {
|
||||
const mockSeq1 = { guid: 'seq-foreign', name: 'Seq Foreign' }
|
||||
const mockSeq2 = { guid: 'seq-local', name: 'Seq Local' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
|
||||
const foreignLink = {
|
||||
sequenceGuid: 'seq-foreign',
|
||||
sequenceName: 'Seq Foreign',
|
||||
assetId: 'asset-foreign',
|
||||
assetName: 'foreign.mp4',
|
||||
endpoint: 'http://localhost:3000',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: 0,
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
const sameLink = {
|
||||
sequenceGuid: 'seq-local',
|
||||
sequenceName: 'Seq Local',
|
||||
assetId: 'asset-local',
|
||||
assetName: 'local.mp4',
|
||||
endpoint: 'https://staging.shumai.one/', // trailing slash variation
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: 0,
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([
|
||||
mockSeq1 as unknown as Sequence,
|
||||
mockSeq2 as unknown as Sequence,
|
||||
])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([foreignLink, sameLink])
|
||||
vi.spyOn(markersService, 'fetchAssetComments').mockResolvedValue([
|
||||
{ id: 'comm-1', second: 2, message: 'comment' } as unknown as CommentInfo,
|
||||
])
|
||||
vi.spyOn(markersService, 'syncCommentsToSequence').mockResolvedValue({
|
||||
updatedLink: { ...sameLink, syncedCommentIds: ['comm-1'] },
|
||||
addedCount: 1,
|
||||
})
|
||||
|
||||
autoSyncService.start('https://staging.shumai.one', 'test-key')
|
||||
await autoSyncService.triggerImmediateSync()
|
||||
|
||||
// Foreign link should be skipped
|
||||
expect(markersService.fetchAssetComments).not.toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
'asset-foreign',
|
||||
)
|
||||
|
||||
// Matching link should be synced
|
||||
expect(markersService.fetchAssetComments).toHaveBeenCalledWith(
|
||||
'https://staging.shumai.one',
|
||||
'test-key',
|
||||
'asset-local',
|
||||
)
|
||||
expect(markersService.syncCommentsToSequence).toHaveBeenCalledWith(
|
||||
mockProject,
|
||||
mockSeq2,
|
||||
expect.any(Array),
|
||||
sameLink,
|
||||
)
|
||||
})
|
||||
|
||||
it('aborts syncing when stop() is called and credentials are reset', async () => {
|
||||
const fetchSpy = vi.spyOn(markersService, 'fetchAssetComments')
|
||||
autoSyncService.start('https://api.shumai.test', 'test-key')
|
||||
autoSyncService.stop()
|
||||
await autoSyncService.triggerImmediateSync()
|
||||
expect(fetchSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,175 @@
|
||||
import type { Sequence } from '@adobe/premierepro'
|
||||
import { getActiveProject, getAllSequences, getPremiereModule } from './premiere'
|
||||
import { getAllLinkedSequences, normalizeGuid } from './linkStorage'
|
||||
import { fetchAssetComments, syncCommentsToSequence } from './markers'
|
||||
import { isSameEndpoint } from '../utils/url'
|
||||
|
||||
const SYNC_INTERVAL_MS = 12000 // 12 seconds
|
||||
|
||||
class AutoSyncService {
|
||||
private timer: ReturnType<typeof setInterval> | null = null
|
||||
private endpoint = ''
|
||||
private apiKey = ''
|
||||
private cleanupListeners: (() => void) | null = null
|
||||
private syncPromise: Promise<void> | null = null
|
||||
|
||||
/**
|
||||
* Starts the background auto-sync loop.
|
||||
*/
|
||||
start(endpoint: string, apiKey: string): void {
|
||||
this.stop()
|
||||
this.endpoint = endpoint
|
||||
this.apiKey = apiKey
|
||||
|
||||
if (!endpoint || !apiKey) return
|
||||
|
||||
// Setup background interval
|
||||
this.timer = setInterval(() => {
|
||||
void this.syncAllLinkedSequences()
|
||||
}, SYNC_INTERVAL_MS)
|
||||
|
||||
// Setup host and window event listeners
|
||||
this.setupListeners()
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the background auto-sync loop and tears down listeners.
|
||||
*/
|
||||
stop(): void {
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer)
|
||||
this.timer = null
|
||||
}
|
||||
if (this.cleanupListeners) {
|
||||
this.cleanupListeners()
|
||||
this.cleanupListeners = null
|
||||
}
|
||||
this.endpoint = ''
|
||||
this.apiKey = ''
|
||||
this.syncPromise = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Forces an immediate synchronization cycle.
|
||||
*/
|
||||
async triggerImmediateSync(): Promise<void> {
|
||||
if (this.syncPromise) {
|
||||
await this.syncPromise
|
||||
}
|
||||
await this.syncAllLinkedSequences()
|
||||
}
|
||||
|
||||
private setupListeners(): void {
|
||||
const onFocus = () => {
|
||||
void this.triggerImmediateSync()
|
||||
}
|
||||
const onVisibilityChange = () => {
|
||||
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
|
||||
void this.triggerImmediateSync()
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.addEventListener('focus', onFocus)
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
document.addEventListener('visibilitychange', onVisibilityChange)
|
||||
}
|
||||
|
||||
// Premiere Pro Sequence Activated listener
|
||||
const ppro = getPremiereModule()
|
||||
let hasSeqListener = false
|
||||
const onSequenceActivated = () => {
|
||||
void this.triggerImmediateSync()
|
||||
}
|
||||
|
||||
if (ppro?.EventManager && ppro.Constants?.SequenceEvent?.ACTIVATED) {
|
||||
try {
|
||||
ppro.EventManager.addGlobalEventListener(
|
||||
ppro.Constants.SequenceEvent.ACTIVATED,
|
||||
onSequenceActivated,
|
||||
)
|
||||
hasSeqListener = true
|
||||
} catch (err) {
|
||||
console.warn('[autoSyncService] Could not register SequenceEvent listener:', err)
|
||||
}
|
||||
}
|
||||
|
||||
this.cleanupListeners = () => {
|
||||
if (typeof window !== 'undefined') {
|
||||
window.removeEventListener('focus', onFocus)
|
||||
}
|
||||
if (typeof document !== 'undefined') {
|
||||
document.removeEventListener('visibilitychange', onVisibilityChange)
|
||||
}
|
||||
if (hasSeqListener && ppro?.EventManager && ppro.Constants?.SequenceEvent?.ACTIVATED) {
|
||||
try {
|
||||
ppro.EventManager.removeGlobalEventListener(
|
||||
ppro.Constants.SequenceEvent.ACTIVATED,
|
||||
onSequenceActivated,
|
||||
)
|
||||
} catch {
|
||||
// Ignore error during cleanup
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async syncAllLinkedSequences(): Promise<void> {
|
||||
if (this.syncPromise) {
|
||||
return this.syncPromise
|
||||
}
|
||||
const currentEndpoint = this.endpoint
|
||||
const currentApiKey = this.apiKey
|
||||
if (!currentEndpoint || !currentApiKey) return
|
||||
|
||||
this.syncPromise = (async () => {
|
||||
try {
|
||||
const project = await getActiveProject()
|
||||
if (!project || this.endpoint !== currentEndpoint || this.apiKey !== currentApiKey) return
|
||||
|
||||
const allSeqs = await getAllSequences(project)
|
||||
if (!allSeqs || allSeqs.length === 0 || this.endpoint !== currentEndpoint) return
|
||||
|
||||
const linkedItems = await getAllLinkedSequences(project, allSeqs)
|
||||
if (!linkedItems || linkedItems.length === 0 || this.endpoint !== currentEndpoint) return
|
||||
|
||||
const seqsMap = new Map<string, Sequence>()
|
||||
for (const s of allSeqs) {
|
||||
const normGuid = normalizeGuid(s.guid)
|
||||
if (normGuid) {
|
||||
seqsMap.set(normGuid, s)
|
||||
}
|
||||
}
|
||||
|
||||
for (const link of linkedItems) {
|
||||
if (this.endpoint !== currentEndpoint || this.apiKey !== currentApiKey) break
|
||||
|
||||
// Skip links created against a different server endpoint
|
||||
if (link.endpoint && !isSameEndpoint(link.endpoint, currentEndpoint)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const targetSeq = seqsMap.get(normalizeGuid(link.sequenceGuid))
|
||||
if (!targetSeq) continue
|
||||
|
||||
try {
|
||||
const comments = await fetchAssetComments(currentEndpoint, currentApiKey, link.assetId)
|
||||
if (this.endpoint !== currentEndpoint) break
|
||||
await syncCommentsToSequence(project, targetSeq, comments, link)
|
||||
} catch (itemErr) {
|
||||
console.error(`[autoSyncService] Error syncing sequence ${link.sequenceName}:`, itemErr)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[autoSyncService] Sync cycle failed:', err)
|
||||
} finally {
|
||||
this.syncPromise = null
|
||||
}
|
||||
})()
|
||||
|
||||
return this.syncPromise
|
||||
}
|
||||
}
|
||||
|
||||
export const autoSyncService = new AutoSyncService()
|
||||
@@ -0,0 +1,124 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { fetchAssetComments, formatCommentBody } from './commentUtils'
|
||||
import * as clientModule from '../api/client'
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
|
||||
describe('commentUtils', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('fetchAssetComments', () => {
|
||||
it('returns comments array when response is ok', async () => {
|
||||
const mockComments: Partial<CommentInfo>[] = [
|
||||
{ id: 'c1', message: 'First comment', second: 12 },
|
||||
{ id: 'c2', message: 'Second comment', second: 45 },
|
||||
]
|
||||
|
||||
const mockGet = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ data: mockComments }),
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
':fileId': {
|
||||
comments: {
|
||||
$get: mockGet,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const result = await fetchAssetComments('https://api.shumai.test', 'test-key', 'asset-1')
|
||||
|
||||
expect(mockGet).toHaveBeenCalledWith({
|
||||
param: { fileId: 'asset-1' },
|
||||
query: { first: '100' },
|
||||
})
|
||||
expect(result).toEqual(mockComments)
|
||||
})
|
||||
|
||||
it('throws error with message from server response when res.ok is false', async () => {
|
||||
const mockGet = vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 404,
|
||||
json: async () => ({ error: 'Asset not found on this server' }),
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
':fileId': {
|
||||
comments: {
|
||||
$get: mockGet,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
await expect(
|
||||
fetchAssetComments('https://api.shumai.test', 'test-key', 'asset-missing'),
|
||||
).rejects.toThrow('Asset not found on this server')
|
||||
})
|
||||
|
||||
it('throws fallback HTTP status error when res.ok is false and response has no error field', async () => {
|
||||
const mockGet = vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 500,
|
||||
json: async () => {
|
||||
throw new Error('Invalid JSON')
|
||||
},
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
':fileId': {
|
||||
comments: {
|
||||
$get: mockGet,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
await expect(
|
||||
fetchAssetComments('https://api.shumai.test', 'test-key', 'asset-crash'),
|
||||
).rejects.toThrow('Failed to fetch comments (HTTP 500)')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatCommentBody', () => {
|
||||
it('formats single comment without replies', () => {
|
||||
const comment = {
|
||||
message: 'Review cut at 01:23',
|
||||
replies: [],
|
||||
} as unknown as CommentInfo
|
||||
|
||||
expect(formatCommentBody(comment)).toBe('Review cut at 01:23')
|
||||
})
|
||||
|
||||
it('formats comment with nested replies and authors', () => {
|
||||
const comment = {
|
||||
message: 'Needs color correction',
|
||||
replies: [
|
||||
{ creator: { name: 'Alice' }, message: 'Applied LUT' },
|
||||
{ creator: { name: 'Bob' }, message: 'Looks better' },
|
||||
],
|
||||
} as unknown as CommentInfo
|
||||
|
||||
const result = formatCommentBody(comment)
|
||||
expect(result).toContain('Needs color correction')
|
||||
expect(result).toContain('--- Replies ---')
|
||||
expect(result).toContain('Alice: Applied LUT')
|
||||
expect(result).toContain('Bob: Looks better')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
import { getShumaiClient } from '../api/client'
|
||||
|
||||
/**
|
||||
* Fetches timecoded comments for an asset from Shumai.
|
||||
*/
|
||||
export async function fetchAssetComments(
|
||||
endpoint: string,
|
||||
apiKey: string,
|
||||
assetId: string,
|
||||
): Promise<CommentInfo[]> {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
const res = await client.api.files[':fileId'].comments.$get({
|
||||
param: { fileId: assetId },
|
||||
query: { first: '100' },
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = (await res.json().catch(() => ({}))) as { error?: string }
|
||||
throw new Error(errData.error || `Failed to fetch comments (HTTP ${res.status})`)
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
return (data?.data as CommentInfo[]) || []
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a Shumai comment into marker text including any threaded replies.
|
||||
*/
|
||||
export function formatCommentBody(comment: CommentInfo): string {
|
||||
let body = comment.message || ''
|
||||
|
||||
if (comment.replies && comment.replies.length > 0) {
|
||||
body += '\n\n--- Replies ---'
|
||||
for (const reply of comment.replies) {
|
||||
const author = reply.creator?.name || 'User'
|
||||
const replyMsg = reply.message || ''
|
||||
body += `\n${author}: ${replyMsg}`
|
||||
}
|
||||
}
|
||||
|
||||
return body
|
||||
}
|
||||
@@ -0,0 +1,619 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import {
|
||||
formatResolutionLabel,
|
||||
getResolutionRank,
|
||||
resolveRawDownloadUrl,
|
||||
fetchVideoProxies,
|
||||
getUniqueFileName,
|
||||
getFolderEntryNames,
|
||||
createUniqueFileInFolder,
|
||||
importAssetIntoPremiere,
|
||||
} from './import'
|
||||
import * as premiereModule from './premiere'
|
||||
import * as clientModule from '../api/client'
|
||||
import type { AssetSummary } from '../components/FileItem'
|
||||
|
||||
describe('import service', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('formatResolutionLabel', () => {
|
||||
it('formats given resolution strings', () => {
|
||||
expect(formatResolutionLabel(undefined, undefined, '1080p')).toBe('1080p (MP4)')
|
||||
expect(formatResolutionLabel(undefined, undefined, '720')).toBe('720p (MP4)')
|
||||
})
|
||||
|
||||
it('formats given height numbers', () => {
|
||||
expect(formatResolutionLabel(1920, 1080)).toBe('1080p (MP4)')
|
||||
expect(formatResolutionLabel(1280, 720)).toBe('720p (MP4)')
|
||||
})
|
||||
|
||||
it('formats by width if height is missing', () => {
|
||||
expect(formatResolutionLabel(1920, undefined)).toBe('1080p (MP4)')
|
||||
expect(formatResolutionLabel(1280, undefined)).toBe('720p (MP4)')
|
||||
expect(formatResolutionLabel(3840, undefined)).toBe('2160p (MP4)')
|
||||
})
|
||||
|
||||
it('falls back to Proxy (MP4)', () => {
|
||||
expect(formatResolutionLabel(undefined, undefined)).toBe('Proxy (MP4)')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getResolutionRank', () => {
|
||||
it('extracts resolution numeric rank', () => {
|
||||
expect(getResolutionRank('1080p (MP4)')).toBe(1080)
|
||||
expect(getResolutionRank('720p (MP4)')).toBe(720)
|
||||
expect(getResolutionRank('Proxy (MP4)')).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveRawDownloadUrl', () => {
|
||||
it('resolves directly via download-url when original key is in knownAsset', async () => {
|
||||
const mockDownloadUrlPost = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ url: 'https://s3.example.com/direct-raw.mp4' }),
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-url': {
|
||||
$post: mockDownloadUrlPost,
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const knownAsset: AssetSummary = {
|
||||
id: 'file-1',
|
||||
name: 'direct-raw.mp4',
|
||||
type: 'file',
|
||||
media: {
|
||||
original: {
|
||||
key: 'files/test/direct-raw.mp4',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const result = await resolveRawDownloadUrl('http://test', 'key', 'file-1', knownAsset)
|
||||
expect(result.url).toBe('https://s3.example.com/direct-raw.mp4')
|
||||
expect(result.name).toBe('direct-raw.mp4')
|
||||
expect(mockDownloadUrlPost).toHaveBeenCalledWith({
|
||||
json: { key: 'files/test/direct-raw.mp4', assetId: 'file-1' },
|
||||
})
|
||||
})
|
||||
|
||||
it('resolves via GET :fileId and download-url when not in knownAsset', async () => {
|
||||
const mockGet = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
id: 'file-1',
|
||||
name: 'remote-video.mp4',
|
||||
media: {
|
||||
original: {
|
||||
key: 'files/remote/video.mp4',
|
||||
},
|
||||
},
|
||||
}),
|
||||
})
|
||||
const mockDownloadUrlPost = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({ url: 'https://s3.example.com/presigned-remote.mp4' }),
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
':fileId': {
|
||||
$get: mockGet,
|
||||
},
|
||||
'download-url': {
|
||||
$post: mockDownloadUrlPost,
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const result = await resolveRawDownloadUrl('http://test', 'key', 'file-1')
|
||||
expect(result.url).toBe('https://s3.example.com/presigned-remote.mp4')
|
||||
expect(result.name).toBe('remote-video.mp4')
|
||||
expect(mockGet).toHaveBeenCalledWith({ param: { fileId: 'file-1' } })
|
||||
expect(mockDownloadUrlPost).toHaveBeenCalledWith({
|
||||
json: { key: 'files/remote/video.mp4', assetId: 'file-1' },
|
||||
})
|
||||
})
|
||||
|
||||
it('falls back to download-links endpoint when download-url is unavailable', async () => {
|
||||
const mockPost = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
files: [{ id: 'file-1', name: 'video.mov', url: 'https://s3.example.com/video.mov' }],
|
||||
}),
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-links': {
|
||||
$post: mockPost,
|
||||
},
|
||||
},
|
||||
},
|
||||
// Partial mock of Hono client for unit test isolation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const result = await resolveRawDownloadUrl('http://test', 'key', 'file-1')
|
||||
expect(result.url).toBe('https://s3.example.com/video.mov')
|
||||
expect(result.name).toBe('video.mov')
|
||||
expect(mockPost).toHaveBeenCalledWith({ json: { ids: ['file-1'] } })
|
||||
})
|
||||
|
||||
it('throws error when all resolution methods fail', async () => {
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-links': {
|
||||
$post: vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 500,
|
||||
json: async () => ({ error: 'Server error' }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
// Partial mock of Hono client for unit test isolation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
await expect(resolveRawDownloadUrl('http://test', 'key', 'file-1')).rejects.toThrow(
|
||||
'Server error',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('fetchVideoProxies', () => {
|
||||
it('returns available proxies sorted descending', async () => {
|
||||
const mockGet = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
id: 'file-1',
|
||||
media: {
|
||||
videoTranscodes: [
|
||||
{
|
||||
id: 't-720',
|
||||
key: 'files/720.mp4',
|
||||
url: 'https://s3.example.com/720.mp4',
|
||||
width: 1280,
|
||||
height: 720,
|
||||
},
|
||||
{
|
||||
id: 't-1080',
|
||||
key: 'files/1080.mp4',
|
||||
url: 'https://s3.example.com/1080.mp4',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
':fileId': {
|
||||
$get: mockGet,
|
||||
},
|
||||
},
|
||||
},
|
||||
// Partial mock of Hono client for unit test isolation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const proxies = await fetchVideoProxies('http://test', 'key', 'file-1')
|
||||
expect(proxies).toHaveLength(2)
|
||||
// Highest resolution first
|
||||
expect(proxies[0].label).toBe('1080p (MP4)')
|
||||
expect(proxies[1].label).toBe('720p (MP4)')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getUniqueFileName', () => {
|
||||
it('returns exact name when no collision exists', () => {
|
||||
expect(getUniqueFileName([], 'image.png')).toBe('image.png')
|
||||
expect(getUniqueFileName(['other.png', 'test.mov'], 'image.png')).toBe('image.png')
|
||||
})
|
||||
|
||||
it('appends _1 on first collision', () => {
|
||||
expect(getUniqueFileName(['image.png'], 'image.png')).toBe('image_1.png')
|
||||
})
|
||||
|
||||
it('appends _2 when original and _1 both exist', () => {
|
||||
expect(getUniqueFileName(['image.png', 'image_1.png'], 'image.png')).toBe('image_2.png')
|
||||
})
|
||||
|
||||
it('handles case-insensitive collision checks', () => {
|
||||
expect(getUniqueFileName(['IMAGE.PNG'], 'image.png')).toBe('image_1.png')
|
||||
expect(getUniqueFileName(['image.png', 'IMAGE_1.PNG'], 'image.png')).toBe('image_2.png')
|
||||
})
|
||||
|
||||
it('handles files without extensions', () => {
|
||||
expect(getUniqueFileName(['README'], 'README')).toBe('README_1')
|
||||
expect(getUniqueFileName(['README', 'README_1'], 'README')).toBe('README_2')
|
||||
})
|
||||
|
||||
it('handles files with multiple dots', () => {
|
||||
expect(getUniqueFileName(['archive.tar.gz'], 'archive.tar.gz')).toBe('archive.tar_1.gz')
|
||||
expect(getUniqueFileName(['archive.tar.gz', 'archive.tar_1.gz'], 'archive.tar.gz')).toBe(
|
||||
'archive.tar_2.gz',
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getFolderEntryNames', () => {
|
||||
it('reads entry names from folder.getEntries', async () => {
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'dir',
|
||||
nativePath: '/path/dir',
|
||||
createFile: vi.fn(),
|
||||
getEntries: vi.fn().mockResolvedValue([
|
||||
{ name: 'file1.mp4', isFile: true, isFolder: false },
|
||||
{ name: 'subfolder', isFile: false, isFolder: true },
|
||||
]),
|
||||
}
|
||||
|
||||
const names = await getFolderEntryNames(mockFolder)
|
||||
expect(names).toEqual(['file1.mp4', 'subfolder'])
|
||||
})
|
||||
|
||||
it('handles folder.getEntries error gracefully', async () => {
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'dir',
|
||||
nativePath: '/path/dir',
|
||||
createFile: vi.fn(),
|
||||
getEntries: vi.fn().mockRejectedValue(new Error('Permission denied')),
|
||||
}
|
||||
|
||||
const names = await getFolderEntryNames(mockFolder)
|
||||
expect(names).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('createUniqueFileInFolder', () => {
|
||||
it('creates file with candidate name when no collision', async () => {
|
||||
const mockCreatedFile = {
|
||||
isFile: true as const,
|
||||
isFolder: false as const,
|
||||
name: 'test.mp4',
|
||||
nativePath: '/path/test.mp4',
|
||||
write: vi.fn(),
|
||||
}
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'dir',
|
||||
nativePath: '/path/dir',
|
||||
createFile: vi.fn().mockResolvedValue(mockCreatedFile),
|
||||
getEntries: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
|
||||
const res = await createUniqueFileInFolder(mockFolder, 'test.mp4')
|
||||
expect(res.name).toBe('test.mp4')
|
||||
expect(res.file).toBe(mockCreatedFile)
|
||||
expect(mockFolder.createFile).toHaveBeenCalledWith('test.mp4', { overwrite: false })
|
||||
})
|
||||
|
||||
it('auto-increments suffix when candidate creation fails due to collision', async () => {
|
||||
const mockCreatedFile = {
|
||||
isFile: true as const,
|
||||
isFolder: false as const,
|
||||
name: 'test_1.mp4',
|
||||
nativePath: '/path/test_1.mp4',
|
||||
write: vi.fn(),
|
||||
}
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'dir',
|
||||
nativePath: '/path/dir',
|
||||
createFile: vi
|
||||
.fn()
|
||||
.mockRejectedValueOnce(new Error('File exists'))
|
||||
.mockResolvedValueOnce(mockCreatedFile),
|
||||
getEntries: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
|
||||
const res = await createUniqueFileInFolder(mockFolder, 'test.mp4')
|
||||
expect(res.name).toBe('test_1.mp4')
|
||||
expect(res.file).toBe(mockCreatedFile)
|
||||
})
|
||||
})
|
||||
|
||||
describe('importAssetIntoPremiere', () => {
|
||||
const mockAsset: AssetSummary = {
|
||||
id: 'asset-1',
|
||||
name: 'Sample.mov',
|
||||
type: 'file',
|
||||
}
|
||||
|
||||
it('returns error when no active project in Premiere', async () => {
|
||||
vi.spyOn(premiereModule, 'getActiveProject').mockResolvedValue(null)
|
||||
|
||||
const result = await importAssetIntoPremiere({
|
||||
endpoint: 'http://test',
|
||||
apiKey: 'key',
|
||||
asset: mockAsset,
|
||||
type: 'raw',
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
expect(result.message).toContain('Please open or create a project')
|
||||
})
|
||||
|
||||
it('returns cancelled when user cancels folder picker', async () => {
|
||||
// Mocking incomplete Premiere Project object in unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.spyOn(premiereModule, 'getActiveProject').mockResolvedValue({} as any)
|
||||
vi.spyOn(premiereModule, 'promptSelectFolder').mockResolvedValue(null)
|
||||
|
||||
const result = await importAssetIntoPremiere({
|
||||
endpoint: 'http://test',
|
||||
apiKey: 'key',
|
||||
asset: mockAsset,
|
||||
type: 'raw',
|
||||
})
|
||||
|
||||
expect(result.success).toBe(false)
|
||||
expect(result.cancelled).toBe(true)
|
||||
expect(premiereModule.promptSelectFolder).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('fails after folder selection if download link resolution fails', async () => {
|
||||
// Mocking incomplete Premiere Project object in unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
vi.spyOn(premiereModule, 'getActiveProject').mockResolvedValue({} as any)
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'dir',
|
||||
nativePath: '/path/dir',
|
||||
createFile: vi.fn(),
|
||||
getEntries: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
vi.spyOn(premiereModule, 'promptSelectFolder').mockResolvedValue(mockFolder)
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-links': {
|
||||
$post: vi.fn().mockResolvedValue({
|
||||
ok: false,
|
||||
status: 401,
|
||||
json: async () => ({ error: 'Unauthorized: Invalid API Key' }),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
// Partial mock of Hono client for unit test isolation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
await expect(
|
||||
importAssetIntoPremiere({
|
||||
endpoint: 'http://test',
|
||||
apiKey: 'key',
|
||||
asset: mockAsset,
|
||||
type: 'raw',
|
||||
}),
|
||||
).rejects.toThrow('Unauthorized: Invalid API Key')
|
||||
})
|
||||
|
||||
it('downloads and imports file successfully with original name when no conflict', async () => {
|
||||
// Mocking incomplete Premiere Project object in unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mockProject = {} as any
|
||||
vi.spyOn(premiereModule, 'getActiveProject').mockResolvedValue(mockProject)
|
||||
|
||||
const mockSaveFile = {
|
||||
isFile: true as const,
|
||||
isFolder: false as const,
|
||||
name: 'Sample.mov',
|
||||
nativePath: '/Users/test/Downloads/Sample.mov',
|
||||
write: vi.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'Downloads',
|
||||
nativePath: '/Users/test/Downloads',
|
||||
createFile: vi.fn().mockResolvedValue(mockSaveFile),
|
||||
getEntries: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
vi.spyOn(premiereModule, 'promptSelectFolder').mockResolvedValue(mockFolder)
|
||||
vi.spyOn(premiereModule, 'writeBinaryFile').mockResolvedValue(undefined)
|
||||
vi.spyOn(premiereModule, 'importFilesIntoProject').mockResolvedValue(true)
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-links': {
|
||||
$post: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
files: [{ id: 'asset-1', name: 'Sample.mov', url: 'https://s3.example.com/raw' }],
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
// Partial mock of Hono client for unit test isolation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
// Mock global fetch
|
||||
const dummyBuffer = new ArrayBuffer(8)
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
ok: true,
|
||||
arrayBuffer: async () => dummyBuffer,
|
||||
// Mocking Response object for unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const onProgress = vi.fn()
|
||||
const result = await importAssetIntoPremiere({
|
||||
endpoint: 'http://test',
|
||||
apiKey: 'key',
|
||||
asset: mockAsset,
|
||||
type: 'raw',
|
||||
onProgress,
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.fileName).toBe('Sample.mov')
|
||||
expect(result.message).toContain('Successfully imported Sample.mov')
|
||||
expect(mockFolder.createFile).toHaveBeenCalledWith('Sample.mov', { overwrite: false })
|
||||
expect(premiereModule.importFilesIntoProject).toHaveBeenCalledWith(mockProject, [
|
||||
'/Users/test/Downloads/Sample.mov',
|
||||
])
|
||||
expect(onProgress).toHaveBeenCalled()
|
||||
fetchSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('automatically adds _1 suffix when name conflict exists in selected folder', async () => {
|
||||
// Mocking incomplete Premiere Project object in unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mockProject = {} as any
|
||||
vi.spyOn(premiereModule, 'getActiveProject').mockResolvedValue(mockProject)
|
||||
|
||||
const mockSaveFile = {
|
||||
isFile: true as const,
|
||||
isFolder: false as const,
|
||||
name: 'Sample_1.mov',
|
||||
nativePath: '/Users/test/Downloads/Sample_1.mov',
|
||||
write: vi.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'Downloads',
|
||||
nativePath: '/Users/test/Downloads',
|
||||
createFile: vi.fn().mockResolvedValue(mockSaveFile),
|
||||
getEntries: vi
|
||||
.fn()
|
||||
.mockResolvedValue([{ name: 'Sample.mov', isFile: true, isFolder: false }]),
|
||||
}
|
||||
vi.spyOn(premiereModule, 'promptSelectFolder').mockResolvedValue(mockFolder)
|
||||
vi.spyOn(premiereModule, 'writeBinaryFile').mockResolvedValue(undefined)
|
||||
vi.spyOn(premiereModule, 'importFilesIntoProject').mockResolvedValue(true)
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-links': {
|
||||
$post: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
files: [{ id: 'asset-1', name: 'Sample.mov', url: 'https://s3.example.com/raw' }],
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
// Partial mock of Hono client for unit test isolation
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const dummyBuffer = new ArrayBuffer(8)
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
ok: true,
|
||||
arrayBuffer: async () => dummyBuffer,
|
||||
// Mocking Response object for unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const result = await importAssetIntoPremiere({
|
||||
endpoint: 'http://test',
|
||||
apiKey: 'key',
|
||||
asset: mockAsset,
|
||||
type: 'raw',
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
expect(result.fileName).toBe('Sample_1.mov')
|
||||
expect(result.message).toContain('Successfully imported Sample_1.mov')
|
||||
expect(mockFolder.createFile).toHaveBeenCalledWith('Sample_1.mov', { overwrite: false })
|
||||
expect(premiereModule.importFilesIntoProject).toHaveBeenCalledWith(mockProject, [
|
||||
'/Users/test/Downloads/Sample_1.mov',
|
||||
])
|
||||
fetchSpy.mockRestore()
|
||||
})
|
||||
|
||||
it('resolves relative download URL with endpoint before fetching', async () => {
|
||||
// Mocking incomplete Premiere Project object in unit test
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mockProject = {} as any
|
||||
vi.spyOn(premiereModule, 'getActiveProject').mockResolvedValue(mockProject)
|
||||
|
||||
const mockSaveFile = {
|
||||
isFile: true as const,
|
||||
isFolder: false as const,
|
||||
name: 'Sample.mov',
|
||||
nativePath: '/Users/test/Downloads/Sample.mov',
|
||||
write: vi.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
const mockFolder = {
|
||||
isFile: false as const,
|
||||
isFolder: true as const,
|
||||
name: 'Downloads',
|
||||
nativePath: '/Users/test/Downloads',
|
||||
createFile: vi.fn().mockResolvedValue(mockSaveFile),
|
||||
getEntries: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
vi.spyOn(premiereModule, 'promptSelectFolder').mockResolvedValue(mockFolder)
|
||||
vi.spyOn(premiereModule, 'writeBinaryFile').mockResolvedValue(undefined)
|
||||
vi.spyOn(premiereModule, 'importFilesIntoProject').mockResolvedValue(true)
|
||||
|
||||
vi.spyOn(clientModule, 'getShumaiClient').mockReturnValue({
|
||||
api: {
|
||||
files: {
|
||||
'download-links': {
|
||||
$post: vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
files: [{ id: 'asset-1', name: 'Sample.mov', url: '/api/upload/local?key=test' }],
|
||||
}),
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const dummyBuffer = new ArrayBuffer(8)
|
||||
const fetchSpy = vi.spyOn(globalThis, 'fetch').mockResolvedValue({
|
||||
ok: true,
|
||||
arrayBuffer: async () => dummyBuffer,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any)
|
||||
|
||||
const result = await importAssetIntoPremiere({
|
||||
endpoint: 'http://test:3000',
|
||||
apiKey: 'key',
|
||||
asset: mockAsset,
|
||||
type: 'raw',
|
||||
})
|
||||
|
||||
expect(result.success).toBe(true)
|
||||
expect(fetchSpy).toHaveBeenCalledWith('http://test:3000/api/upload/local?key=test')
|
||||
fetchSpy.mockRestore()
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,357 @@
|
||||
import { getShumaiClient } from '../api/client'
|
||||
import type { AssetSummary } from '../components/FileItem'
|
||||
import {
|
||||
getActiveProject,
|
||||
importFilesIntoProject,
|
||||
promptSelectFolder,
|
||||
writeBinaryFile,
|
||||
} from './premiere'
|
||||
import { resolveAssetUrl } from '../utils/url'
|
||||
|
||||
export interface ProxyOption {
|
||||
id: string
|
||||
label: string
|
||||
resolution: string
|
||||
url: string
|
||||
key: string
|
||||
width?: number
|
||||
height?: number
|
||||
size?: number
|
||||
}
|
||||
|
||||
export function formatResolutionLabel(width?: number, height?: number, res?: string): string {
|
||||
if (res) {
|
||||
const cleanRes = res.endsWith('p') ? res : `${res}p`
|
||||
return `${cleanRes} (MP4)`
|
||||
}
|
||||
if (height) return `${height}p (MP4)`
|
||||
if (width) {
|
||||
if (width >= 3840) return '2160p (MP4)'
|
||||
if (width >= 1920) return '1080p (MP4)'
|
||||
if (width >= 1280) return '720p (MP4)'
|
||||
if (width >= 960) return '540p (MP4)'
|
||||
if (width >= 640) return '360p (MP4)'
|
||||
}
|
||||
return 'Proxy (MP4)'
|
||||
}
|
||||
|
||||
export function getResolutionRank(label: string): number {
|
||||
const match = label.match(/(\d+)p/) || label.match(/^(\d+)/)
|
||||
return match ? parseInt(match[1], 10) : 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the presigned download URL for the original / raw file.
|
||||
*/
|
||||
export async function resolveRawDownloadUrl(
|
||||
endpoint: string,
|
||||
apiKey: string,
|
||||
assetId: string,
|
||||
knownAsset?: AssetSummary,
|
||||
): Promise<{ url: string; name?: string }> {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
|
||||
// 1. If original key is known directly from asset summary, presign via download-url endpoint
|
||||
const directKey = knownAsset?.media?.original?.key
|
||||
if (directKey) {
|
||||
try {
|
||||
const res = await client.api.files['download-url']?.$post({
|
||||
json: { key: directKey, assetId },
|
||||
})
|
||||
if (res?.ok) {
|
||||
const data = await res.json()
|
||||
if (data.url) {
|
||||
return { url: data.url, name: knownAsset?.name }
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Failed to resolve download URL via known key:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fetch full asset details via GET /api/files/:fileId to get the original media key
|
||||
try {
|
||||
const detailRes = await client.api.files[':fileId']?.$get({
|
||||
param: { fileId: assetId },
|
||||
})
|
||||
if (detailRes?.ok) {
|
||||
const assetData = await detailRes.json()
|
||||
const originalKey = assetData.media?.original?.key
|
||||
if (originalKey) {
|
||||
const urlRes = await client.api.files['download-url']?.$post({
|
||||
json: { key: originalKey, assetId },
|
||||
})
|
||||
if (urlRes?.ok) {
|
||||
const urlData = await urlRes.json()
|
||||
if (urlData.url) {
|
||||
return { url: urlData.url, name: assetData.name || knownAsset?.name }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Failed to fetch asset details for download URL:', err)
|
||||
}
|
||||
|
||||
// 3. Fallback to POST /api/files/download-links batch resolution
|
||||
const res = await client.api.files['download-links']?.$post({
|
||||
json: { ids: [assetId] },
|
||||
})
|
||||
|
||||
if (res?.ok) {
|
||||
const data = await res.json()
|
||||
const file = data.files?.[0]
|
||||
if (file?.url) {
|
||||
return { url: file.url, name: file.name || knownAsset?.name }
|
||||
}
|
||||
} else if (res) {
|
||||
const errData = (await res.json().catch(() => ({}))) as { error?: string }
|
||||
throw new Error(errData.error || `Failed to get download link (${res.status})`)
|
||||
}
|
||||
|
||||
throw new Error('No download URL returned from server.')
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches available video proxy transcodes for an asset.
|
||||
*/
|
||||
export async function fetchVideoProxies(
|
||||
endpoint: string,
|
||||
apiKey: string,
|
||||
assetId: string,
|
||||
): Promise<ProxyOption[]> {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
const res = await client.api.files[':fileId'].$get({
|
||||
param: { fileId: assetId },
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = (await res.json().catch(() => ({}))) as { error?: string }
|
||||
throw new Error(errData.error || `Failed to get asset details (${res.status})`)
|
||||
}
|
||||
|
||||
const asset = await res.json()
|
||||
const transcodes = asset.media?.videoTranscodes || []
|
||||
if (!transcodes.length) return []
|
||||
|
||||
const proxies: ProxyOption[] = []
|
||||
for (const t of transcodes) {
|
||||
let url = t.url
|
||||
if (!url && t.key) {
|
||||
// If transcode url wasn't presigned yet, request via download-url endpoint
|
||||
try {
|
||||
const urlRes = await client.api.files['download-url'].$post({
|
||||
json: { key: t.key, assetId },
|
||||
})
|
||||
if (urlRes.ok) {
|
||||
const urlData = await urlRes.json()
|
||||
url = urlData.url
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(`Failed to presign transcode key ${t.key}:`, err)
|
||||
}
|
||||
}
|
||||
|
||||
if (url) {
|
||||
const label = formatResolutionLabel(t.width, t.height)
|
||||
proxies.push({
|
||||
id: t.id || t.key,
|
||||
label,
|
||||
resolution: `${t.height || 0}p`,
|
||||
url,
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
size: t.size,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Sort descending by resolution (1080p, 720p, 540p, 360p)
|
||||
proxies.sort((a, b) => getResolutionRank(b.label) - getResolutionRank(a.label))
|
||||
return proxies
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a unique filename within the specified existing file names in a folder.
|
||||
* If requestedName exists, it appends _1, _2, etc. before the file extension.
|
||||
* Comparison is case-insensitive to safely handle Windows and macOS filesystems.
|
||||
*/
|
||||
export function getUniqueFileName(existingNames: string[], requestedName: string): string {
|
||||
const existingSet = new Set(existingNames.map((n) => n.toLowerCase()))
|
||||
if (!existingSet.has(requestedName.toLowerCase())) {
|
||||
return requestedName
|
||||
}
|
||||
|
||||
const dotIndex = requestedName.lastIndexOf('.')
|
||||
const base = dotIndex > 0 ? requestedName.slice(0, dotIndex) : requestedName
|
||||
const ext = dotIndex > 0 ? requestedName.slice(dotIndex) : ''
|
||||
|
||||
let counter = 1
|
||||
while (true) {
|
||||
const candidate = `${base}_${counter}${ext}`
|
||||
if (!existingSet.has(candidate.toLowerCase())) {
|
||||
return candidate
|
||||
}
|
||||
counter++
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads existing file/folder names inside a UXP FolderEntry safely.
|
||||
*/
|
||||
export async function getFolderEntryNames(folder: UxpFolderEntry): Promise<string[]> {
|
||||
try {
|
||||
if (typeof folder.getEntries === 'function') {
|
||||
const entries = await folder.getEntries()
|
||||
return entries.map((e) => e.name)
|
||||
}
|
||||
const folderRecord = folder as unknown as Record<string, unknown>
|
||||
if (typeof folderRecord.getFiles === 'function') {
|
||||
const files = await (folderRecord.getFiles as () => Promise<Array<{ name: string }>>)()
|
||||
return files.map((f) => f.name)
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('Failed to read folder entries:', err)
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a unique file entry in the target folder, preventing overwrites by auto-incrementing suffixes (_1, _2).
|
||||
*/
|
||||
export async function createUniqueFileInFolder(
|
||||
folder: UxpFolderEntry,
|
||||
requestedName: string,
|
||||
): Promise<{ file: UxpFileEntry; name: string }> {
|
||||
const existingNames = await getFolderEntryNames(folder)
|
||||
const candidateName = getUniqueFileName(existingNames, requestedName)
|
||||
|
||||
try {
|
||||
const file = await folder.createFile(candidateName, { overwrite: false })
|
||||
return { file, name: candidateName }
|
||||
} catch (err) {
|
||||
console.warn(`Could not create file "${candidateName}" with overwrite: false, retrying...`, err)
|
||||
const dotIndex = requestedName.lastIndexOf('.')
|
||||
const base = dotIndex > 0 ? requestedName.slice(0, dotIndex) : requestedName
|
||||
const ext = dotIndex > 0 ? requestedName.slice(dotIndex) : ''
|
||||
|
||||
for (let counter = 1; counter <= 50; counter++) {
|
||||
const retryName = `${base}_${counter}${ext}`
|
||||
try {
|
||||
const file = await folder.createFile(retryName, { overwrite: false })
|
||||
return { file, name: retryName }
|
||||
} catch {
|
||||
continue
|
||||
}
|
||||
}
|
||||
const fallbackFile = await folder.createFile(candidateName, { overwrite: true })
|
||||
return { file: fallbackFile, name: candidateName }
|
||||
}
|
||||
}
|
||||
|
||||
export interface ImportAssetOptions {
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
asset: AssetSummary
|
||||
type: 'raw' | 'proxy'
|
||||
proxyItem?: ProxyOption
|
||||
onProgress?: (message: string) => void
|
||||
}
|
||||
|
||||
export interface ImportResult {
|
||||
success: boolean
|
||||
cancelled?: boolean
|
||||
message: string
|
||||
fileName?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Orchestrates the full import workflow:
|
||||
* 1. Checks active Premiere Pro project
|
||||
* 2. Prompts user with native folder picker (Frame.io pattern)
|
||||
* 3. Resolves download URL from Shumai S3 presigned URL
|
||||
* 4. Resolves unique filename in folder with auto-increment (_1, _2) on collision
|
||||
* 5. Downloads binary data and writes to disk
|
||||
* 6. Calls Premiere project.importFiles
|
||||
*/
|
||||
export async function importAssetIntoPremiere({
|
||||
endpoint,
|
||||
apiKey,
|
||||
asset,
|
||||
type,
|
||||
proxyItem,
|
||||
onProgress,
|
||||
}: ImportAssetOptions): Promise<ImportResult> {
|
||||
// 1. Verify active Premiere project
|
||||
const project = await getActiveProject()
|
||||
if (!project) {
|
||||
return {
|
||||
success: false,
|
||||
message: 'Please open or create a project in Premiere Pro first.',
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Open native folder picker (Frame.io pattern)
|
||||
const targetFolder = await promptSelectFolder()
|
||||
if (!targetFolder) {
|
||||
return {
|
||||
success: false,
|
||||
cancelled: true,
|
||||
message: 'Import cancelled by user.',
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Determine default filename & download URL
|
||||
onProgress?.('Preparing download link...')
|
||||
let downloadUrl: string
|
||||
let defaultFileName: string
|
||||
if (type === 'raw') {
|
||||
const rawInfo = await resolveRawDownloadUrl(endpoint, apiKey, asset.id, asset)
|
||||
downloadUrl = rawInfo.url
|
||||
defaultFileName = rawInfo.name || asset.name
|
||||
} else {
|
||||
if (!proxyItem?.url) {
|
||||
throw new Error('Proxy URL not available.')
|
||||
}
|
||||
downloadUrl = proxyItem.url
|
||||
const rawName = asset.name
|
||||
const dotIndex = rawName.lastIndexOf('.')
|
||||
const baseName = dotIndex !== -1 ? rawName.slice(0, dotIndex) : rawName
|
||||
const resTag = proxyItem ? proxyItem.label.split(' ')[0] : 'proxy'
|
||||
defaultFileName = `${baseName}_proxy_${resTag}.mp4`
|
||||
}
|
||||
|
||||
const resolvedDownloadUrl = resolveAssetUrl(downloadUrl, endpoint) || downloadUrl
|
||||
|
||||
// 4. Create unique file in destination folder with collision avoidance (_1, _2)
|
||||
const { file: saveFile, name: finalFileName } = await createUniqueFileInFolder(
|
||||
targetFolder,
|
||||
defaultFileName,
|
||||
)
|
||||
|
||||
// 5. Download binary data
|
||||
onProgress?.(`Downloading ${finalFileName}...`)
|
||||
const response = await fetch(resolvedDownloadUrl)
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to download file (HTTP ${response.status})`)
|
||||
}
|
||||
const arrayBuffer = await response.arrayBuffer()
|
||||
|
||||
// 6. Write file to disk
|
||||
onProgress?.(`Saving ${finalFileName} to disk...`)
|
||||
await writeBinaryFile(saveFile, arrayBuffer)
|
||||
|
||||
// 7. Import into Premiere Pro
|
||||
onProgress?.('Importing into Premiere Pro...')
|
||||
const imported = await importFilesIntoProject(project, [saveFile.nativePath])
|
||||
if (!imported) {
|
||||
throw new Error(`Premiere Pro could not import "${finalFileName}".`)
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
fileName: finalFileName,
|
||||
message: `Successfully imported ${finalFileName} into Premiere Pro.`,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,548 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import {
|
||||
saveSequenceLinkToCache,
|
||||
getSequenceLinkFromCache,
|
||||
removeSequenceLinkFromCache,
|
||||
getAllSequenceLinksFromCache,
|
||||
getAllLinkedSequences,
|
||||
getSequenceLink,
|
||||
saveSequenceLink,
|
||||
removeSequenceLink,
|
||||
normalizeGuid,
|
||||
LINK_STORAGE_PROP_KEY,
|
||||
} from './linkStorage'
|
||||
import * as commentUtils from './commentUtils'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
|
||||
const localStorageMock = (() => {
|
||||
let store: Record<string, string> = {}
|
||||
return {
|
||||
getItem: (key: string) => store[key] || null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store[key] = value.toString()
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
delete store[key]
|
||||
},
|
||||
clear: () => {
|
||||
store = {}
|
||||
},
|
||||
key: (index: number) => Object.keys(store)[index] || null,
|
||||
get length() {
|
||||
return Object.keys(store).length
|
||||
},
|
||||
}
|
||||
})()
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: localStorageMock,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
})
|
||||
|
||||
describe('linkStorage service', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
vi.restoreAllMocks()
|
||||
// Reset global require
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (globalThis as any).require
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (globalThis as any).window
|
||||
})
|
||||
|
||||
const sampleLink: LinkedSequenceAsset = {
|
||||
sequenceGuid: 'seq-guid-1',
|
||||
sequenceName: 'Sequence 01',
|
||||
assetId: 'asset-1',
|
||||
assetName: 'video.mp4',
|
||||
syncedCommentIds: ['comm-1', 'comm-2'],
|
||||
lastSyncAt: 1000,
|
||||
totalCommentsSynced: 2,
|
||||
}
|
||||
|
||||
describe('cache operations (localStorage)', () => {
|
||||
it('saves and retrieves link from cache', () => {
|
||||
saveSequenceLinkToCache(sampleLink, 'proj-1')
|
||||
const result = getSequenceLinkFromCache('seq-guid-1', 'proj-1')
|
||||
expect(result).toEqual(sampleLink)
|
||||
})
|
||||
|
||||
it('saves and retrieves link with endpoint from cache', () => {
|
||||
const linkWithEndpoint: LinkedSequenceAsset = {
|
||||
...sampleLink,
|
||||
endpoint: 'https://staging.shumai.one',
|
||||
}
|
||||
saveSequenceLinkToCache(linkWithEndpoint, 'proj-1')
|
||||
const result = getSequenceLinkFromCache('seq-guid-1', 'proj-1')
|
||||
expect(result?.endpoint).toBe('https://staging.shumai.one')
|
||||
})
|
||||
|
||||
it('returns null when link is not in cache', () => {
|
||||
expect(getSequenceLinkFromCache('unknown-seq', 'proj-1')).toBeNull()
|
||||
})
|
||||
|
||||
it('lists all links for a project', () => {
|
||||
saveSequenceLinkToCache(sampleLink, 'proj-1')
|
||||
const link2: LinkedSequenceAsset = {
|
||||
...sampleLink,
|
||||
sequenceGuid: 'seq-guid-2',
|
||||
sequenceName: 'Sequence 02',
|
||||
}
|
||||
saveSequenceLinkToCache(link2, 'proj-1')
|
||||
|
||||
const all = getAllSequenceLinksFromCache('proj-1')
|
||||
expect(all).toHaveLength(2)
|
||||
expect(all.map((l) => l.sequenceGuid)).toContain('seq-guid-1')
|
||||
expect(all.map((l) => l.sequenceGuid)).toContain('seq-guid-2')
|
||||
})
|
||||
|
||||
it('removes a link from cache', () => {
|
||||
saveSequenceLinkToCache(sampleLink, 'proj-1')
|
||||
expect(getSequenceLinkFromCache('seq-guid-1', 'proj-1')).not.toBeNull()
|
||||
|
||||
removeSequenceLinkFromCache('seq-guid-1', 'proj-1')
|
||||
expect(getSequenceLinkFromCache('seq-guid-1', 'proj-1')).toBeNull()
|
||||
})
|
||||
|
||||
it('returns all links across projects when projectGuid is omitted', () => {
|
||||
saveSequenceLinkToCache(sampleLink, 'proj-1')
|
||||
const link2: LinkedSequenceAsset = {
|
||||
...sampleLink,
|
||||
sequenceGuid: 'seq-guid-2',
|
||||
sequenceName: 'Sequence 02',
|
||||
assetId: 'asset-2',
|
||||
}
|
||||
saveSequenceLinkToCache(link2, 'proj-2')
|
||||
|
||||
const all = getAllSequenceLinksFromCache()
|
||||
expect(all).toHaveLength(2)
|
||||
expect(all.map((l) => l.sequenceGuid)).toContain('seq-guid-1')
|
||||
expect(all.map((l) => l.sequenceGuid)).toContain('seq-guid-2')
|
||||
})
|
||||
|
||||
it('does not return links from default cache when projectGuid is specified', () => {
|
||||
saveSequenceLinkToCache(sampleLink, null)
|
||||
const result = getAllSequenceLinksFromCache('proj-unknown')
|
||||
expect(result).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('host sequence properties integration', () => {
|
||||
it('retrieves persistent property from sequence when available', async () => {
|
||||
const mockProps = {
|
||||
getValue: vi.fn().mockReturnValue(JSON.stringify(sampleLink)),
|
||||
}
|
||||
const mockPpro = {
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue(mockProps),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
const mockProj = { guid: 'proj-1' }
|
||||
|
||||
const link = await getSequenceLink(
|
||||
mockSeq as unknown as Sequence,
|
||||
mockProj as unknown as Project,
|
||||
)
|
||||
expect(link).toEqual(sampleLink)
|
||||
expect(mockProps.getValue).toHaveBeenCalledWith(LINK_STORAGE_PROP_KEY)
|
||||
})
|
||||
|
||||
it('saves persistent property and executes transaction', async () => {
|
||||
const mockCompoundAction = { addAction: vi.fn() }
|
||||
const mockProps = {
|
||||
createSetValueAction: vi.fn().mockReturnValue({ id: 'action-set' }),
|
||||
}
|
||||
const mockPpro = {
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue(mockProps),
|
||||
PROPERTY_PERSISTENT: 1,
|
||||
},
|
||||
Constants: {
|
||||
PropertyType: { PERSISTENT: 1 },
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
const mockProj = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn((cb) => {
|
||||
cb(mockCompoundAction)
|
||||
return true
|
||||
}),
|
||||
}
|
||||
|
||||
const success = await saveSequenceLink(
|
||||
mockProj as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
sampleLink,
|
||||
)
|
||||
expect(success).toBe(true)
|
||||
expect(mockProps.createSetValueAction).toHaveBeenCalledWith(
|
||||
LINK_STORAGE_PROP_KEY,
|
||||
JSON.stringify(sampleLink),
|
||||
1,
|
||||
)
|
||||
expect(mockCompoundAction.addAction).toHaveBeenCalledWith({ id: 'action-set' })
|
||||
})
|
||||
|
||||
it('clears persistent property on removeSequenceLink', async () => {
|
||||
const mockCompoundAction = { addAction: vi.fn() }
|
||||
const mockProps = {
|
||||
createClearValueAction: vi.fn().mockReturnValue({ id: 'action-clear' }),
|
||||
}
|
||||
const mockPpro = {
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue(mockProps),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
const mockProj = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn((cb) => {
|
||||
cb(mockCompoundAction)
|
||||
return true
|
||||
}),
|
||||
}
|
||||
|
||||
const success = await removeSequenceLink(
|
||||
mockProj as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
)
|
||||
expect(success).toBe(true)
|
||||
expect(mockProps.createClearValueAction).toHaveBeenCalledWith(LINK_STORAGE_PROP_KEY)
|
||||
})
|
||||
|
||||
it('removes synced markers matching syncedMarkerGuids on removeSequenceLink, preserving manual markers', async () => {
|
||||
const mockCompoundAction = { addAction: vi.fn() }
|
||||
const mockProps = {
|
||||
getValue: vi.fn().mockReturnValue(
|
||||
JSON.stringify({
|
||||
...sampleLink,
|
||||
syncedMarkerGuids: ['synced-marker-1', 'synced-marker-2'],
|
||||
}),
|
||||
),
|
||||
createClearValueAction: vi.fn().mockReturnValue({ id: 'action-clear' }),
|
||||
}
|
||||
|
||||
const mockMarker1 = {
|
||||
guid: 'synced-marker-1',
|
||||
name: 'Director (edited)',
|
||||
comments: 'Edited comment',
|
||||
}
|
||||
const mockMarker2 = { guid: 'synced-marker-2', name: 'Producer', comments: 'Another comment' }
|
||||
const mockManualMarker = {
|
||||
guid: 'manual-user-marker',
|
||||
name: 'Editor Note',
|
||||
comments: 'Manual marker',
|
||||
}
|
||||
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockReturnValue([mockMarker1, mockManualMarker, mockMarker2]),
|
||||
createRemoveMarkerAction: vi.fn().mockImplementation((marker) => ({
|
||||
type: 'remove-marker',
|
||||
guid: marker.guid,
|
||||
})),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue(mockProps),
|
||||
},
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
const mockProj = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn((cb) => {
|
||||
cb(mockCompoundAction)
|
||||
return true
|
||||
}),
|
||||
}
|
||||
|
||||
const success = await removeSequenceLink(
|
||||
mockProj as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
)
|
||||
expect(success).toBe(true)
|
||||
|
||||
// Only synced-marker-1 and synced-marker-2 should be removed; manual-user-marker must NOT be removed
|
||||
expect(mockSeqMarkers.createRemoveMarkerAction).toHaveBeenCalledTimes(2)
|
||||
expect(mockSeqMarkers.createRemoveMarkerAction).toHaveBeenCalledWith(mockMarker1)
|
||||
expect(mockSeqMarkers.createRemoveMarkerAction).toHaveBeenCalledWith(mockMarker2)
|
||||
expect(mockSeqMarkers.createRemoveMarkerAction).not.toHaveBeenCalledWith(mockManualMarker)
|
||||
|
||||
expect(mockCompoundAction.addAction).toHaveBeenCalledWith({
|
||||
type: 'remove-marker',
|
||||
guid: 'synced-marker-1',
|
||||
})
|
||||
expect(mockCompoundAction.addAction).toHaveBeenCalledWith({
|
||||
type: 'remove-marker',
|
||||
guid: 'synced-marker-2',
|
||||
})
|
||||
expect(mockProps.createClearValueAction).toHaveBeenCalledWith(LINK_STORAGE_PROP_KEY)
|
||||
})
|
||||
|
||||
it('removes markers by comment matching fallback when syncedMarkerGuids is empty', async () => {
|
||||
localStorage.setItem('shumai_uxp_endpoint', 'https://shumai.example.com')
|
||||
localStorage.setItem('shumai_uxp_api_key', 'test-api-key')
|
||||
|
||||
vi.spyOn(commentUtils, 'fetchAssetComments').mockResolvedValue([
|
||||
{
|
||||
id: 'comm-1',
|
||||
creator: {
|
||||
id: 'u1',
|
||||
name: 'Director',
|
||||
} as unknown as import('@shumai/dtos').CommentInfo['creator'],
|
||||
message: 'Please trim this scene',
|
||||
} as unknown as import('@shumai/dtos').CommentInfo,
|
||||
])
|
||||
|
||||
const mockCompoundAction = { addAction: vi.fn() }
|
||||
const mockProps = {
|
||||
getValue: vi.fn().mockReturnValue(
|
||||
JSON.stringify({
|
||||
...sampleLink,
|
||||
syncedMarkerGuids: [],
|
||||
}),
|
||||
),
|
||||
createClearValueAction: vi.fn().mockReturnValue({ id: 'action-clear' }),
|
||||
}
|
||||
|
||||
const mockLegacyShumaiMarker = {
|
||||
guid: 'legacy-guid-1',
|
||||
getName: () => 'Director',
|
||||
getComments: () => 'Please trim this scene',
|
||||
}
|
||||
const mockManualMarker = {
|
||||
guid: 'manual-guid-2',
|
||||
getName: () => 'Editor',
|
||||
getComments: () => 'My own note',
|
||||
}
|
||||
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockReturnValue([mockLegacyShumaiMarker, mockManualMarker]),
|
||||
createRemoveMarkerAction: vi.fn().mockImplementation((marker) => ({
|
||||
type: 'remove-marker',
|
||||
guid: marker.guid,
|
||||
})),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue(mockProps),
|
||||
},
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
const mockProj = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn((cb) => {
|
||||
cb(mockCompoundAction)
|
||||
return true
|
||||
}),
|
||||
}
|
||||
|
||||
const success = await removeSequenceLink(
|
||||
mockProj as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
)
|
||||
expect(success).toBe(true)
|
||||
|
||||
expect(mockSeqMarkers.createRemoveMarkerAction).toHaveBeenCalledWith(mockLegacyShumaiMarker)
|
||||
expect(mockSeqMarkers.createRemoveMarkerAction).not.toHaveBeenCalledWith(mockManualMarker)
|
||||
})
|
||||
|
||||
it('attempts individual marker removals if compound batch remove returns false', async () => {
|
||||
const mockCompoundAction = { addAction: vi.fn() }
|
||||
const mockProps = {
|
||||
getValue: vi.fn().mockReturnValue(
|
||||
JSON.stringify({
|
||||
...sampleLink,
|
||||
syncedMarkerGuids: ['synced-1'],
|
||||
}),
|
||||
),
|
||||
createClearValueAction: vi.fn().mockReturnValue({ id: 'action-clear' }),
|
||||
}
|
||||
|
||||
const mockMarker = { guid: 'synced-1' }
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockReturnValue([mockMarker]),
|
||||
createRemoveMarkerAction: vi.fn().mockReturnValue({ type: 'remove-marker' }),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue(mockProps),
|
||||
},
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
let txCount = 0
|
||||
const mockProj = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn((cb) => {
|
||||
txCount++
|
||||
cb(mockCompoundAction)
|
||||
if (txCount === 1) return false // batch failed
|
||||
return true // individual succeeded
|
||||
}),
|
||||
}
|
||||
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
const success = await removeSequenceLink(
|
||||
mockProj as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
)
|
||||
expect(success).toBe(true)
|
||||
expect(txCount).toBeGreaterThanOrEqual(2)
|
||||
})
|
||||
|
||||
it('skips fallback comment fetch if link endpoint does not match current session endpoint', async () => {
|
||||
localStorage.setItem('shumai_uxp_endpoint', 'https://staging.shumai.one')
|
||||
localStorage.setItem('shumai_uxp_api_key', 'test-key')
|
||||
|
||||
const fetchCommentsSpy = vi.spyOn(commentUtils, 'fetchAssetComments')
|
||||
|
||||
const mockSeq = {
|
||||
guid: 'seq-diff-endpoint',
|
||||
name: 'Diff Endpoint Seq',
|
||||
}
|
||||
const mockProj = {
|
||||
guid: 'proj-diff',
|
||||
lockedAccess: (fn: () => void) => fn(),
|
||||
executeTransaction: () => true,
|
||||
}
|
||||
|
||||
const linkFromLocal: LinkedSequenceAsset = {
|
||||
...sampleLink,
|
||||
sequenceGuid: 'seq-diff-endpoint',
|
||||
endpoint: 'http://localhost:3000',
|
||||
syncedMarkerGuids: [], // Trigger fallback
|
||||
}
|
||||
|
||||
saveSequenceLinkToCache(linkFromLocal, 'proj-diff')
|
||||
|
||||
await removeSequenceLink(mockProj as unknown as Project, mockSeq as unknown as Sequence)
|
||||
expect(fetchCommentsSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('getAllLinkedSequences', () => {
|
||||
it('does not leak cached links across projects when a project has an empty sequence list', async () => {
|
||||
saveSequenceLinkToCache(sampleLink, 'proj-A')
|
||||
const defaultLink: LinkedSequenceAsset = {
|
||||
...sampleLink,
|
||||
sequenceGuid: 'seq-default',
|
||||
sequenceName: 'Default Seq',
|
||||
}
|
||||
saveSequenceLinkToCache(defaultLink, null)
|
||||
|
||||
const mockProjB = {
|
||||
guid: 'proj-B',
|
||||
getSequences: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
|
||||
const results = await getAllLinkedSequences(mockProjB as unknown as Project, [])
|
||||
expect(results).toEqual([])
|
||||
})
|
||||
|
||||
it('restores cached link only if the sequence actually exists in the project', async () => {
|
||||
saveSequenceLinkToCache(sampleLink, 'proj-A')
|
||||
|
||||
const mockSeq1 = { guid: 'seq-guid-1' }
|
||||
const mockSeq2 = { guid: 'seq-guid-2' }
|
||||
|
||||
const mockProjA = {
|
||||
guid: 'proj-A',
|
||||
getSequences: vi.fn().mockResolvedValue([mockSeq1]),
|
||||
}
|
||||
|
||||
const results = await getAllLinkedSequences(mockProjA as unknown as Project, [
|
||||
mockSeq1 as unknown as Sequence,
|
||||
])
|
||||
expect(results).toHaveLength(1)
|
||||
expect(results[0].sequenceGuid).toBe('seq-guid-1')
|
||||
|
||||
const resultsSeq2 = await getAllLinkedSequences(mockProjA as unknown as Project, [
|
||||
mockSeq2 as unknown as Sequence,
|
||||
])
|
||||
expect(resultsSeq2).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeGuid', () => {
|
||||
it('normalizes GUIDs with uppercase, braces, whitespace, and objects', () => {
|
||||
expect(normalizeGuid('{1234-ABCD-5678}')).toBe('1234-abcd-5678')
|
||||
expect(normalizeGuid(' ABC-DEF ')).toBe('abc-def')
|
||||
expect(normalizeGuid({ toString: () => '{Guid-Obj}' })).toBe('guid-obj')
|
||||
expect(normalizeGuid(null)).toBe('')
|
||||
expect(normalizeGuid(undefined)).toBe('')
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,472 @@
|
||||
import type { Marker, Project, Sequence } from '@adobe/premierepro'
|
||||
import { getPremiereModule } from './premiere'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
import { getStoredCredentials } from './storage'
|
||||
import { fetchAssetComments, formatCommentBody } from './commentUtils'
|
||||
import { isSameEndpoint } from '../utils/url'
|
||||
|
||||
export const LINK_STORAGE_PROP_KEY = 'shumai_linked_asset'
|
||||
const STORAGE_PREFIX = '@shumai/premiere-uxp:project-links'
|
||||
|
||||
/**
|
||||
* Normalizes a GUID or string identifier by removing curly braces,
|
||||
* trimming whitespace, and converting to lower case for reliable comparison.
|
||||
*/
|
||||
export function normalizeGuid(guid: unknown): string {
|
||||
if (!guid) return ''
|
||||
const str =
|
||||
typeof guid === 'string'
|
||||
? guid
|
||||
: typeof (guid as { toString?: () => string }).toString === 'function'
|
||||
? (guid as { toString: () => string }).toString()
|
||||
: String(guid)
|
||||
return str.trim().toLowerCase().replace(/[{}]/g, '')
|
||||
}
|
||||
|
||||
function getStorageKey(projectGuid?: string | null): string {
|
||||
return `${STORAGE_PREFIX}:${projectGuid ? normalizeGuid(projectGuid) : 'default'}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all cached sequence links for a project from localStorage.
|
||||
* If projectGuid is omitted or null, aggregates across all project keys in localStorage.
|
||||
*/
|
||||
export function getAllSequenceLinksFromCache(projectGuid?: string | null): LinkedSequenceAsset[] {
|
||||
if (typeof localStorage === 'undefined') return []
|
||||
try {
|
||||
const normProj = projectGuid ? normalizeGuid(projectGuid) : null
|
||||
if (normProj) {
|
||||
const raw = localStorage.getItem(getStorageKey(normProj))
|
||||
if (raw) {
|
||||
const parsed = JSON.parse(raw)
|
||||
if (Array.isArray(parsed)) return parsed
|
||||
if (typeof parsed === 'object' && parsed !== null) {
|
||||
return Object.values(parsed)
|
||||
}
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
// When projectGuid is not provided, aggregate all cached sequence links
|
||||
const results: LinkedSequenceAsset[] = []
|
||||
const seenGuids = new Set<string>()
|
||||
|
||||
// Check default key
|
||||
const defaultRaw = localStorage.getItem(getStorageKey(null))
|
||||
if (defaultRaw) {
|
||||
try {
|
||||
const parsed = JSON.parse(defaultRaw)
|
||||
const items: LinkedSequenceAsset[] = Array.isArray(parsed)
|
||||
? parsed
|
||||
: typeof parsed === 'object' && parsed !== null
|
||||
? Object.values(parsed)
|
||||
: []
|
||||
for (const item of items) {
|
||||
const normSeq = normalizeGuid(item.sequenceGuid)
|
||||
if (normSeq && !seenGuids.has(normSeq)) {
|
||||
seenGuids.add(normSeq)
|
||||
results.push(item)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore JSON error
|
||||
}
|
||||
}
|
||||
|
||||
// Scan all keys matching STORAGE_PREFIX in localStorage
|
||||
if (typeof localStorage.length === 'number') {
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = typeof localStorage.key === 'function' ? localStorage.key(i) : null
|
||||
if (key && key.startsWith(STORAGE_PREFIX)) {
|
||||
const raw = localStorage.getItem(key)
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw)
|
||||
const items: LinkedSequenceAsset[] = Array.isArray(parsed)
|
||||
? parsed
|
||||
: typeof parsed === 'object' && parsed !== null
|
||||
? Object.values(parsed)
|
||||
: []
|
||||
for (const item of items) {
|
||||
const normSeq = normalizeGuid(item.sequenceGuid)
|
||||
if (normSeq && !seenGuids.has(normSeq)) {
|
||||
seenGuids.add(normSeq)
|
||||
results.push(item)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Ignore corrupted item
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Failed to read cached links from localStorage:', err)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a cached sequence link by sequence GUID from localStorage.
|
||||
*/
|
||||
export function getSequenceLinkFromCache(
|
||||
sequenceGuid: string,
|
||||
projectGuid?: string | null,
|
||||
): LinkedSequenceAsset | null {
|
||||
const normSeq = normalizeGuid(sequenceGuid)
|
||||
const all = getAllSequenceLinksFromCache(projectGuid)
|
||||
return all.find((item) => normalizeGuid(item.sequenceGuid) === normSeq) || null
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves a sequence link in the local cache.
|
||||
*/
|
||||
export function saveSequenceLinkToCache(
|
||||
linkData: LinkedSequenceAsset,
|
||||
projectGuid?: string | null,
|
||||
): void {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
try {
|
||||
const normSeq = normalizeGuid(linkData.sequenceGuid)
|
||||
const normalizedData: LinkedSequenceAsset = {
|
||||
...linkData,
|
||||
sequenceGuid: normSeq,
|
||||
...(linkData.syncedMarkerGuids != null
|
||||
? { syncedMarkerGuids: linkData.syncedMarkerGuids.map(normalizeGuid).filter(Boolean) }
|
||||
: {}),
|
||||
}
|
||||
|
||||
if (projectGuid) {
|
||||
const all = getAllSequenceLinksFromCache(projectGuid).filter(
|
||||
(item) => normalizeGuid(item.sequenceGuid) !== normSeq,
|
||||
)
|
||||
all.push(normalizedData)
|
||||
localStorage.setItem(getStorageKey(projectGuid), JSON.stringify(all))
|
||||
}
|
||||
|
||||
// Always also update default key so it's accessible when projectGuid is unknown
|
||||
const defaultAll = getAllSequenceLinksFromCache(null).filter(
|
||||
(item) => normalizeGuid(item.sequenceGuid) !== normSeq,
|
||||
)
|
||||
defaultAll.push(normalizedData)
|
||||
localStorage.setItem(getStorageKey(null), JSON.stringify(defaultAll))
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Failed to save link to localStorage:', err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a sequence link from the local cache.
|
||||
*/
|
||||
export function removeSequenceLinkFromCache(
|
||||
sequenceGuid: string,
|
||||
projectGuid?: string | null,
|
||||
): void {
|
||||
if (typeof localStorage === 'undefined') return
|
||||
try {
|
||||
const normSeq = normalizeGuid(sequenceGuid)
|
||||
if (projectGuid) {
|
||||
const all = getAllSequenceLinksFromCache(projectGuid).filter(
|
||||
(item) => normalizeGuid(item.sequenceGuid) !== normSeq,
|
||||
)
|
||||
localStorage.setItem(getStorageKey(projectGuid), JSON.stringify(all))
|
||||
}
|
||||
|
||||
const defaultAll = getAllSequenceLinksFromCache(null).filter(
|
||||
(item) => normalizeGuid(item.sequenceGuid) !== normSeq,
|
||||
)
|
||||
localStorage.setItem(getStorageKey(null), JSON.stringify(defaultAll))
|
||||
|
||||
// Also remove from any other keys matching STORAGE_PREFIX
|
||||
if (typeof localStorage.length === 'number') {
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = typeof localStorage.key === 'function' ? localStorage.key(i) : null
|
||||
if (key && key.startsWith(STORAGE_PREFIX)) {
|
||||
const raw = localStorage.getItem(key)
|
||||
if (raw) {
|
||||
try {
|
||||
const parsed = JSON.parse(raw)
|
||||
if (Array.isArray(parsed)) {
|
||||
const filtered = parsed.filter(
|
||||
(item) => normalizeGuid(item.sequenceGuid) !== normSeq,
|
||||
)
|
||||
localStorage.setItem(key, JSON.stringify(filtered))
|
||||
}
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Failed to remove link from localStorage:', err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the persistent link metadata from a sequence's properties.
|
||||
*/
|
||||
export async function getSequenceLink(
|
||||
sequence: Sequence,
|
||||
project?: Project | null,
|
||||
): Promise<LinkedSequenceAsset | null> {
|
||||
const ppro = getPremiereModule()
|
||||
const seqGuidStr = normalizeGuid(sequence.guid)
|
||||
const prGuidStr = project?.guid ? normalizeGuid(project.guid) : null
|
||||
|
||||
// Check persistent sequence properties in Premiere
|
||||
if (ppro?.Properties) {
|
||||
try {
|
||||
const properties = await ppro.Properties.getProperties(sequence)
|
||||
const raw = properties.getValue(LINK_STORAGE_PROP_KEY)
|
||||
if (raw) {
|
||||
const parsed = JSON.parse(raw) as LinkedSequenceAsset
|
||||
// Synchronize with cache
|
||||
saveSequenceLinkToCache(parsed, prGuidStr)
|
||||
return parsed
|
||||
}
|
||||
} catch (err) {
|
||||
// Property might not exist or failed to load
|
||||
console.debug('[linkStorage] No persistent property found or failed:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to local cache if sequence property was not available
|
||||
return getSequenceLinkFromCache(seqGuidStr, prGuidStr)
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all linked sequence assets across a project.
|
||||
*/
|
||||
export async function getAllLinkedSequences(
|
||||
project: Project,
|
||||
allSequences?: Sequence[],
|
||||
): Promise<LinkedSequenceAsset[]> {
|
||||
const prGuidStr = project.guid ? normalizeGuid(project.guid) : null
|
||||
const seqs = allSequences || (await project.getSequences()) || []
|
||||
|
||||
const results: LinkedSequenceAsset[] = []
|
||||
const checkedGuids = new Set<string>()
|
||||
|
||||
for (const seq of seqs) {
|
||||
const seqGuid = normalizeGuid(seq.guid)
|
||||
if (seqGuid) checkedGuids.add(seqGuid)
|
||||
const link = await getSequenceLink(seq, project)
|
||||
if (link) {
|
||||
results.push(link)
|
||||
}
|
||||
}
|
||||
|
||||
// Also check cache for any items matching known sequences
|
||||
const cached = getAllSequenceLinksFromCache(prGuidStr)
|
||||
for (const item of cached) {
|
||||
const normItemSeq = normalizeGuid(item.sequenceGuid)
|
||||
if (!results.some((r) => normalizeGuid(r.sequenceGuid) === normItemSeq)) {
|
||||
if (checkedGuids.has(normItemSeq)) {
|
||||
results.push(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the link metadata persistently on the sequence and in the cache.
|
||||
*/
|
||||
export async function saveSequenceLink(
|
||||
project: Project,
|
||||
sequence: Sequence,
|
||||
linkData: LinkedSequenceAsset,
|
||||
): Promise<boolean> {
|
||||
const ppro = getPremiereModule()
|
||||
const prGuidStr = project.guid ? normalizeGuid(project.guid) : null
|
||||
|
||||
// Always update cache first
|
||||
saveSequenceLinkToCache(linkData, prGuidStr)
|
||||
|
||||
if (!ppro?.Properties) {
|
||||
return true
|
||||
}
|
||||
|
||||
try {
|
||||
const properties = await ppro.Properties.getProperties(sequence)
|
||||
const persistentType =
|
||||
ppro.Constants?.PropertyType?.PERSISTENT ?? ppro.Properties.PROPERTY_PERSISTENT ?? 0
|
||||
|
||||
let success = false
|
||||
project.lockedAccess(() => {
|
||||
success = project.executeTransaction((compoundAction) => {
|
||||
const setValAction = properties.createSetValueAction(
|
||||
LINK_STORAGE_PROP_KEY,
|
||||
JSON.stringify(linkData),
|
||||
persistentType,
|
||||
)
|
||||
compoundAction.addAction(setValAction)
|
||||
}, 'Save Shumai Link')
|
||||
})
|
||||
return success
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Failed to set sequence persistent property:', err)
|
||||
return true // Local cache succeeded
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the persistent link metadata from the sequence and cache,
|
||||
* and deletes any markers that were synced from Shumai (matching Frame.io behavior).
|
||||
*/
|
||||
export async function removeSequenceLink(project: Project, sequence: Sequence): Promise<boolean> {
|
||||
const ppro = getPremiereModule()
|
||||
const seqGuidStr = normalizeGuid(sequence.guid)
|
||||
const prGuidStr = project.guid ? normalizeGuid(project.guid) : null
|
||||
|
||||
console.log('[linkStorage] removeSequenceLink called for sequence:', sequence.name || seqGuidStr)
|
||||
|
||||
// Retrieve link metadata before clearing, to identify synced marker GUIDs
|
||||
let linkData = await getSequenceLink(sequence, project)
|
||||
if (!linkData) {
|
||||
const cached = getAllSequenceLinksFromCache(prGuidStr)
|
||||
linkData = cached.find((item) => normalizeGuid(item.sequenceGuid) === seqGuidStr) || null
|
||||
}
|
||||
console.log(
|
||||
'[linkStorage] Retrieved linkData:',
|
||||
linkData ? { assetId: linkData.assetId, guidsCount: linkData.syncedMarkerGuids?.length } : null,
|
||||
)
|
||||
|
||||
// Remove from cache
|
||||
removeSequenceLinkFromCache(seqGuidStr, prGuidStr)
|
||||
|
||||
// Remove synced markers from the sequence timeline
|
||||
if (ppro?.Markers) {
|
||||
try {
|
||||
const sequenceMarkers = await ppro.Markers.getMarkers(sequence)
|
||||
const allMarkers = sequenceMarkers.getMarkers() || []
|
||||
console.log('[linkStorage] Found', allMarkers.length, 'markers on sequence timeline')
|
||||
|
||||
const targetGuids = new Set(
|
||||
(linkData?.syncedMarkerGuids || []).map(normalizeGuid).filter(Boolean),
|
||||
)
|
||||
console.log('[linkStorage] targetGuids count:', targetGuids.size)
|
||||
|
||||
const markersToRemove: Marker[] = []
|
||||
|
||||
// 1. Match markers by GUID
|
||||
if (targetGuids.size > 0) {
|
||||
for (const m of allMarkers) {
|
||||
const g = normalizeGuid(m.guid)
|
||||
if (g && targetGuids.has(g)) {
|
||||
markersToRemove.push(m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback: If targetGuids was empty/missing or didn't find markers, match by asset comments
|
||||
if (markersToRemove.length === 0 && linkData?.assetId) {
|
||||
console.log(
|
||||
'[linkStorage] Fallback: attempting comment-based marker identification for asset:',
|
||||
linkData.assetId,
|
||||
)
|
||||
try {
|
||||
const creds = getStoredCredentials()
|
||||
const canFetchComments =
|
||||
creds?.endpoint &&
|
||||
creds?.apiKey &&
|
||||
(!linkData.endpoint || isSameEndpoint(linkData.endpoint, creds.endpoint))
|
||||
if (canFetchComments) {
|
||||
const comments = await fetchAssetComments(
|
||||
creds.endpoint,
|
||||
creds.apiKey,
|
||||
linkData.assetId,
|
||||
)
|
||||
for (const comm of comments) {
|
||||
const commBody = formatCommentBody(comm)
|
||||
const commAuthor = comm.creator?.name || 'Comment'
|
||||
for (const m of allMarkers) {
|
||||
if (markersToRemove.includes(m)) continue
|
||||
try {
|
||||
const mName = m.getName()
|
||||
const mComments = m.getComments()
|
||||
if (
|
||||
(mName === commAuthor && mComments === commBody) ||
|
||||
(mComments && comm.message && mComments.includes(comm.message))
|
||||
) {
|
||||
markersToRemove.push(m)
|
||||
break
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Fallback comment fetch failed:', err)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[linkStorage] Total markers to remove:', markersToRemove.length)
|
||||
|
||||
if (markersToRemove.length > 0) {
|
||||
let removeSuccess = false
|
||||
try {
|
||||
project.lockedAccess(() => {
|
||||
removeSuccess = project.executeTransaction((compoundAction) => {
|
||||
for (const marker of markersToRemove) {
|
||||
const removeAction = sequenceMarkers.createRemoveMarkerAction(marker)
|
||||
compoundAction.addAction(removeAction)
|
||||
}
|
||||
}, 'Remove Shumai Synced Markers')
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('[linkStorage] executeTransaction batch remove failed:', err)
|
||||
}
|
||||
|
||||
console.log('[linkStorage] Batch remove result:', removeSuccess)
|
||||
|
||||
// If batch compound action did not succeed, attempt individual removals
|
||||
if (!removeSuccess) {
|
||||
console.warn('[linkStorage] Batch remove returned false, attempting individual removals')
|
||||
for (const marker of markersToRemove) {
|
||||
try {
|
||||
project.lockedAccess(() => {
|
||||
project.executeTransaction((compoundAction) => {
|
||||
const removeAction = sequenceMarkers.createRemoveMarkerAction(marker)
|
||||
compoundAction.addAction(removeAction)
|
||||
}, 'Remove Shumai Synced Marker')
|
||||
})
|
||||
} catch (indErr) {
|
||||
console.warn('[linkStorage] Failed individual remove:', indErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Failed to remove synced markers from sequence:', err)
|
||||
}
|
||||
}
|
||||
|
||||
if (!ppro?.Properties) {
|
||||
return true
|
||||
}
|
||||
|
||||
try {
|
||||
const properties = await ppro.Properties.getProperties(sequence)
|
||||
let success = false
|
||||
project.lockedAccess(() => {
|
||||
success = project.executeTransaction((compoundAction) => {
|
||||
const clearAction = properties.createClearValueAction(LINK_STORAGE_PROP_KEY)
|
||||
compoundAction.addAction(clearAction)
|
||||
}, 'Unlink Shumai Asset')
|
||||
})
|
||||
console.log('[linkStorage] Clear property result:', success)
|
||||
return success
|
||||
} catch (err) {
|
||||
console.warn('[linkStorage] Failed to clear sequence persistent property:', err)
|
||||
return true // Cache was cleared
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,405 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { formatCommentBody, syncCommentsToSequence } from './markers'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
|
||||
const localStorageMock = (() => {
|
||||
let store: Record<string, string> = {}
|
||||
return {
|
||||
getItem: (key: string) => store[key] || null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store[key] = value.toString()
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
delete store[key]
|
||||
},
|
||||
clear: () => {
|
||||
store = {}
|
||||
},
|
||||
}
|
||||
})()
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: localStorageMock,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
})
|
||||
|
||||
describe('markers service', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
vi.restoreAllMocks()
|
||||
// Reset global require
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (globalThis as any).require
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (globalThis as any).window
|
||||
})
|
||||
|
||||
describe('formatCommentBody', () => {
|
||||
it('formats simple comment without replies', () => {
|
||||
const comment: Partial<CommentInfo> = {
|
||||
message: 'This is a test comment',
|
||||
replies: [],
|
||||
}
|
||||
expect(formatCommentBody(comment as CommentInfo)).toBe('This is a test comment')
|
||||
})
|
||||
|
||||
it('appends formatted replies beneath message', () => {
|
||||
const comment: Partial<CommentInfo> = {
|
||||
message: 'Original cut feedback',
|
||||
replies: [
|
||||
{
|
||||
creator: { id: 'u2', name: 'Alice' },
|
||||
message: 'Fixed in v2',
|
||||
} as unknown as CommentInfo,
|
||||
{
|
||||
creator: { id: 'u3', name: 'Bob' },
|
||||
message: 'Looks great now',
|
||||
} as unknown as CommentInfo,
|
||||
],
|
||||
}
|
||||
const formatted = formatCommentBody(comment as CommentInfo)
|
||||
expect(formatted).toContain('Original cut feedback')
|
||||
expect(formatted).toContain('--- Replies ---')
|
||||
expect(formatted).toContain('Alice: Fixed in v2')
|
||||
expect(formatted).toContain('Bob: Looks great now')
|
||||
})
|
||||
})
|
||||
|
||||
describe('syncCommentsToSequence', () => {
|
||||
const existingLink: LinkedSequenceAsset = {
|
||||
sequenceGuid: 'seq-guid-1',
|
||||
sequenceName: 'Seq 1',
|
||||
assetId: 'asset-1',
|
||||
assetName: 'test.mp4',
|
||||
syncedCommentIds: ['comm-1'],
|
||||
lastSyncAt: 1000,
|
||||
totalCommentsSynced: 1,
|
||||
}
|
||||
|
||||
it('returns without creating markers if no new comments exist', async () => {
|
||||
const comments: Partial<CommentInfo>[] = [
|
||||
{ id: 'comm-1', second: 10, message: 'Already synced' },
|
||||
]
|
||||
|
||||
const mockProject = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn(),
|
||||
executeTransaction: vi.fn(),
|
||||
}
|
||||
const mockSeq = { guid: 'seq-guid-1' }
|
||||
|
||||
const result = await syncCommentsToSequence(
|
||||
mockProject as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
comments as CommentInfo[],
|
||||
existingLink,
|
||||
)
|
||||
|
||||
expect(result.addedCount).toBe(0)
|
||||
expect(result.updatedLink.syncedCommentIds).toEqual(['comm-1'])
|
||||
expect(mockProject.executeTransaction).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('creates markers for new comments, placing non-timestamped comments at time 0 (zeroPoint)', async () => {
|
||||
const mockCompoundAction = { addAction: vi.fn() }
|
||||
let callCount = 0
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockImplementation(() => {
|
||||
callCount++
|
||||
if (callCount === 1) {
|
||||
return [{ guid: 'old-guid-1' }]
|
||||
}
|
||||
return [{ guid: 'old-guid-1' }, { guid: 'marker-guid-2' }, { guid: 'marker-guid-3' }]
|
||||
}),
|
||||
createAddMarkerAction: vi.fn().mockImplementation((name, type, time, dur, comment) => {
|
||||
return { name, type, time, dur, comment }
|
||||
}),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Marker: { MARKER_TYPE_COMMENT: 'CommentMarkerType' },
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
TickTime: {
|
||||
TIME_ZERO: { ticks: '0' },
|
||||
createWithSeconds: vi.fn((sec) => ({ seconds: sec })),
|
||||
},
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue({
|
||||
createSetValueAction: vi.fn().mockReturnValue({}),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const comments: Partial<CommentInfo>[] = [
|
||||
{ id: 'comm-1', second: 10, message: 'Already synced' },
|
||||
{
|
||||
id: 'comm-2',
|
||||
second: 15.5,
|
||||
message: 'New timestamped comment',
|
||||
creator: { id: 'u1', name: 'Director' } as unknown as CommentInfo['creator'],
|
||||
replies: [],
|
||||
},
|
||||
{
|
||||
id: 'comm-3',
|
||||
second: null,
|
||||
message: 'General comment without timestamp',
|
||||
creator: { id: 'u2', name: 'Producer' } as unknown as CommentInfo['creator'],
|
||||
replies: [],
|
||||
},
|
||||
]
|
||||
|
||||
const mockProject = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn((cb) => {
|
||||
cb(mockCompoundAction)
|
||||
return true
|
||||
}),
|
||||
}
|
||||
const mockSeq = {
|
||||
guid: 'seq-guid-1',
|
||||
getZeroPoint: vi.fn().mockResolvedValue({ seconds: 3600 }), // 1hr timecode start
|
||||
}
|
||||
|
||||
const result = await syncCommentsToSequence(
|
||||
mockProject as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
comments as CommentInfo[],
|
||||
existingLink,
|
||||
)
|
||||
|
||||
expect(result.addedCount).toBe(2)
|
||||
expect(result.updatedLink.syncedCommentIds).toEqual(['comm-1', 'comm-2', 'comm-3'])
|
||||
expect(result.updatedLink.syncedMarkerGuids).toEqual(['marker-guid-2', 'marker-guid-3'])
|
||||
expect(result.updatedLink.totalCommentsSynced).toBe(3)
|
||||
|
||||
// Time should be offset by zeroPoint (3600 + 15.5 = 3615.5 for comm-2, 3600 + 0 = 3600 for comm-3)
|
||||
expect(mockPpro.TickTime.createWithSeconds).toHaveBeenCalledWith(3615.5)
|
||||
expect(mockPpro.TickTime.createWithSeconds).toHaveBeenCalledWith(3600)
|
||||
expect(mockSeqMarkers.createAddMarkerAction).toHaveBeenCalledWith(
|
||||
'Director',
|
||||
'CommentMarkerType',
|
||||
{ seconds: 3615.5 },
|
||||
mockPpro.TickTime.TIME_ZERO,
|
||||
'New timestamped comment',
|
||||
)
|
||||
expect(mockSeqMarkers.createAddMarkerAction).toHaveBeenCalledWith(
|
||||
'Producer',
|
||||
'CommentMarkerType',
|
||||
{ seconds: 3600 },
|
||||
mockPpro.TickTime.TIME_ZERO,
|
||||
'General comment without timestamp',
|
||||
)
|
||||
expect(mockSeqMarkers.createAddMarkerAction).toHaveBeenCalledTimes(2)
|
||||
expect(mockCompoundAction.addAction).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('backfills missing marker GUIDs from sequence when syncedMarkerGuids is incomplete', async () => {
|
||||
const existingLink: LinkedSequenceAsset = {
|
||||
sequenceGuid: 'seq-guid-1',
|
||||
sequenceName: 'Sequence 01',
|
||||
assetId: 'asset-1',
|
||||
assetName: 'video.mp4',
|
||||
syncedCommentIds: ['comm-1'],
|
||||
syncedMarkerGuids: [], // missing GUIDs from previous sync
|
||||
totalCommentsSynced: 1,
|
||||
lastSyncAt: 1000,
|
||||
}
|
||||
|
||||
const mockLegacyMarker = {
|
||||
guid: '{LEGACY-MARKER-GUID-1}',
|
||||
getName: () => 'Director',
|
||||
getComments: () => 'Existing comment message',
|
||||
}
|
||||
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockReturnValue([mockLegacyMarker]),
|
||||
createAddMarkerAction: vi.fn(),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Marker: { MARKER_TYPE_COMMENT: 'CommentMarkerType' },
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
TickTime: {
|
||||
TIME_ZERO: { ticks: '0' },
|
||||
createWithSeconds: vi.fn((sec) => ({ seconds: sec })),
|
||||
},
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue({
|
||||
createSetValueAction: vi.fn().mockReturnValue({}),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const comments: Partial<CommentInfo>[] = [
|
||||
{
|
||||
id: 'comm-1',
|
||||
second: 10,
|
||||
message: 'Existing comment message',
|
||||
creator: { id: 'u1', name: 'Director' } as unknown as CommentInfo['creator'],
|
||||
replies: [],
|
||||
},
|
||||
]
|
||||
|
||||
const mockProject = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn(),
|
||||
}
|
||||
const mockSeq = {
|
||||
guid: 'seq-guid-1',
|
||||
getZeroPoint: vi.fn().mockResolvedValue({ seconds: 0 }),
|
||||
}
|
||||
|
||||
const result = await syncCommentsToSequence(
|
||||
mockProject as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
comments as CommentInfo[],
|
||||
existingLink,
|
||||
)
|
||||
|
||||
expect(result.addedCount).toBe(0)
|
||||
expect(result.updatedLink.syncedMarkerGuids).toEqual(['legacy-marker-guid-1'])
|
||||
expect(mockSeqMarkers.createAddMarkerAction).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not advance synced comments when executeTransaction returns false', async () => {
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockReturnValue([]),
|
||||
createAddMarkerAction: vi.fn().mockReturnValue({}),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Marker: { MARKER_TYPE_COMMENT: 'CommentMarkerType' },
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
TickTime: {
|
||||
TIME_ZERO: { ticks: '0' },
|
||||
createWithSeconds: vi.fn((sec) => ({ seconds: sec })),
|
||||
},
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue({
|
||||
createSetValueAction: vi.fn().mockReturnValue({}),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const comments: Partial<CommentInfo>[] = [
|
||||
{ id: 'comm-1', second: 10, message: 'Already synced' },
|
||||
{ id: 'comm-2', second: 20, message: 'New comment' },
|
||||
]
|
||||
|
||||
const mockProject = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn((cb) => cb()),
|
||||
executeTransaction: vi.fn().mockReturnValue(false),
|
||||
}
|
||||
const mockSeq = {
|
||||
guid: 'seq-guid-1',
|
||||
getZeroPoint: vi.fn().mockResolvedValue({ seconds: 0 }),
|
||||
}
|
||||
|
||||
const result = await syncCommentsToSequence(
|
||||
mockProject as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
comments as CommentInfo[],
|
||||
existingLink,
|
||||
)
|
||||
|
||||
expect(result.addedCount).toBe(0)
|
||||
expect(result.updatedLink.syncedCommentIds).toEqual(['comm-1'])
|
||||
expect(result.updatedLink.totalCommentsSynced).toBe(1)
|
||||
})
|
||||
|
||||
it('does not advance synced comments when executeTransaction throws an error', async () => {
|
||||
const mockSeqMarkers = {
|
||||
getMarkers: vi.fn().mockReturnValue([]),
|
||||
createAddMarkerAction: vi.fn().mockReturnValue({}),
|
||||
}
|
||||
|
||||
const mockPpro = {
|
||||
Marker: { MARKER_TYPE_COMMENT: 'CommentMarkerType' },
|
||||
Markers: {
|
||||
getMarkers: vi.fn().mockResolvedValue(mockSeqMarkers),
|
||||
},
|
||||
TickTime: {
|
||||
TIME_ZERO: { ticks: '0' },
|
||||
createWithSeconds: vi.fn((sec) => ({ seconds: sec })),
|
||||
},
|
||||
Properties: {
|
||||
getProperties: vi.fn().mockResolvedValue({
|
||||
createSetValueAction: vi.fn().mockReturnValue({}),
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const comments: Partial<CommentInfo>[] = [
|
||||
{ id: 'comm-1', second: 10, message: 'Already synced' },
|
||||
{ id: 'comm-2', second: 20, message: 'New comment' },
|
||||
]
|
||||
|
||||
const mockProject = {
|
||||
guid: 'proj-1',
|
||||
lockedAccess: vi.fn(() => {
|
||||
throw new Error('Transaction execution crashed')
|
||||
}),
|
||||
executeTransaction: vi.fn(),
|
||||
}
|
||||
const mockSeq = {
|
||||
guid: 'seq-guid-1',
|
||||
getZeroPoint: vi.fn().mockResolvedValue({ seconds: 0 }),
|
||||
}
|
||||
|
||||
const result = await syncCommentsToSequence(
|
||||
mockProject as unknown as Project,
|
||||
mockSeq as unknown as Sequence,
|
||||
comments as CommentInfo[],
|
||||
existingLink,
|
||||
)
|
||||
|
||||
expect(result.addedCount).toBe(0)
|
||||
expect(result.updatedLink.syncedCommentIds).toEqual(['comm-1'])
|
||||
expect(result.updatedLink.totalCommentsSynced).toBe(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,179 @@
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import { getPremiereModule } from './premiere'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
import { normalizeGuid, saveSequenceLink } from './linkStorage'
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
import { fetchAssetComments, formatCommentBody } from './commentUtils'
|
||||
|
||||
export { fetchAssetComments, formatCommentBody }
|
||||
|
||||
export interface SyncCommentsResult {
|
||||
updatedLink: LinkedSequenceAsset
|
||||
addedCount: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes new Shumai comments to a Premiere Pro sequence as markers.
|
||||
* Comments without timestamps (`second == null`) default to time 0 (sequence start),
|
||||
* matching Frame.io convention. Newly created marker GUIDs are captured and stored
|
||||
* so they can be accurately removed when the sequence is unlinked.
|
||||
*/
|
||||
export async function syncCommentsToSequence(
|
||||
project: Project,
|
||||
sequence: Sequence,
|
||||
comments: CommentInfo[],
|
||||
existingLink: LinkedSequenceAsset,
|
||||
): Promise<SyncCommentsResult> {
|
||||
const ppro = getPremiereModule()
|
||||
const now = Date.now()
|
||||
|
||||
// Filter comments that have not been synced yet; non-timestamped comments default to time 0
|
||||
const alreadySyncedSet = new Set(existingLink.syncedCommentIds)
|
||||
const newComments = comments.filter((c) => !alreadySyncedSet.has(c.id))
|
||||
|
||||
const currentMarkerGuids = (existingLink.syncedMarkerGuids || [])
|
||||
.map(normalizeGuid)
|
||||
.filter(Boolean)
|
||||
const needsGuidBackfill =
|
||||
currentMarkerGuids.length < (existingLink.syncedCommentIds?.length || 0) &&
|
||||
ppro?.Markers != null
|
||||
|
||||
if (newComments.length === 0 && !needsGuidBackfill) {
|
||||
const updatedLink: LinkedSequenceAsset = {
|
||||
...existingLink,
|
||||
lastSyncAt: now,
|
||||
}
|
||||
await saveSequenceLink(project, sequence, updatedLink)
|
||||
return { updatedLink, addedCount: 0 }
|
||||
}
|
||||
|
||||
if (!ppro?.Markers || !ppro?.TickTime) {
|
||||
console.warn('[markers] premierepro Markers or TickTime module not available')
|
||||
return { updatedLink: existingLink, addedCount: 0 }
|
||||
}
|
||||
|
||||
const newMarkerGuids: string[] = []
|
||||
|
||||
try {
|
||||
const sequenceMarkers = await ppro.Markers.getMarkers(sequence)
|
||||
let zeroPointSeconds = 0
|
||||
|
||||
try {
|
||||
const zeroPoint = await sequence.getZeroPoint()
|
||||
if (zeroPoint && typeof zeroPoint.seconds === 'number') {
|
||||
zeroPointSeconds = zeroPoint.seconds
|
||||
}
|
||||
} catch {
|
||||
// zeroPoint defaults to 0
|
||||
}
|
||||
|
||||
// Capture existing marker GUIDs before adding new markers
|
||||
let beforeGuids = new Set<string>()
|
||||
try {
|
||||
const beforeMarkers = sequenceMarkers.getMarkers() || []
|
||||
beforeGuids = new Set(beforeMarkers.map((m) => normalizeGuid(m.guid)).filter(Boolean))
|
||||
console.log('[markers] Existing markers before sync:', beforeMarkers.length)
|
||||
} catch (err) {
|
||||
console.warn('[markers] Could not get existing markers before sync:', err)
|
||||
}
|
||||
|
||||
if (newComments.length > 0) {
|
||||
let txSuccess = false
|
||||
project.lockedAccess(() => {
|
||||
txSuccess =
|
||||
project.executeTransaction((compoundAction) => {
|
||||
for (const comment of newComments) {
|
||||
const markerSeconds = zeroPointSeconds + (comment.second ?? 0)
|
||||
const startTime = ppro.TickTime.createWithSeconds(markerSeconds)
|
||||
const duration = ppro.TickTime.TIME_ZERO
|
||||
const markerName = comment.creator?.name || 'Comment'
|
||||
const markerText = formatCommentBody(comment)
|
||||
|
||||
const addMarkerAction = sequenceMarkers.createAddMarkerAction(
|
||||
markerName,
|
||||
ppro.Marker.MARKER_TYPE_COMMENT,
|
||||
startTime,
|
||||
duration,
|
||||
markerText,
|
||||
)
|
||||
compoundAction.addAction(addMarkerAction)
|
||||
}
|
||||
}, 'Sync Shumai Comments') === true
|
||||
})
|
||||
console.log('[markers] executeTransaction result:', txSuccess)
|
||||
|
||||
if (!txSuccess) {
|
||||
console.warn('[markers] Failed to execute add markers transaction (returned false)')
|
||||
return { updatedLink: existingLink, addedCount: 0 }
|
||||
}
|
||||
}
|
||||
|
||||
// Re-fetch fresh Markers object after transaction to ensure newly committed markers are seen
|
||||
const freshSequenceMarkers = await ppro.Markers.getMarkers(sequence)
|
||||
const afterMarkers = freshSequenceMarkers.getMarkers() || []
|
||||
console.log('[markers] Markers after sync transaction:', afterMarkers.length)
|
||||
|
||||
// 1. Identify newly added markers by GUID difference
|
||||
for (const m of afterMarkers) {
|
||||
const guidStr = normalizeGuid(m.guid)
|
||||
if (guidStr && !beforeGuids.has(guidStr) && !newMarkerGuids.includes(guidStr)) {
|
||||
newMarkerGuids.push(guidStr)
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Fallback / Backfill: Match any comment markers by content/author
|
||||
const allExpectedComments = [...newComments]
|
||||
if (needsGuidBackfill) {
|
||||
const alreadySyncedComments = comments.filter((c) => alreadySyncedSet.has(c.id))
|
||||
allExpectedComments.push(...alreadySyncedComments)
|
||||
}
|
||||
|
||||
const currentKnownGuids = new Set([...currentMarkerGuids, ...newMarkerGuids])
|
||||
for (const comment of allExpectedComments) {
|
||||
const commentBody = formatCommentBody(comment)
|
||||
const commentAuthor = comment.creator?.name || 'Comment'
|
||||
for (const m of afterMarkers) {
|
||||
const g = normalizeGuid(m.guid)
|
||||
if (!g || currentKnownGuids.has(g)) continue
|
||||
try {
|
||||
const mName = m.getName()
|
||||
const mComments = m.getComments()
|
||||
if (
|
||||
(mName === commentAuthor && mComments === commentBody) ||
|
||||
(mComments && comment.message && mComments.includes(comment.message))
|
||||
) {
|
||||
newMarkerGuids.push(g)
|
||||
currentKnownGuids.add(g)
|
||||
break
|
||||
}
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log(
|
||||
'[markers] Total newly captured/backfilled marker GUIDs:',
|
||||
newMarkerGuids.length,
|
||||
newMarkerGuids,
|
||||
)
|
||||
|
||||
const updatedMarkerGuids = Array.from(
|
||||
new Set([...currentMarkerGuids, ...newMarkerGuids.map(normalizeGuid)]),
|
||||
)
|
||||
|
||||
const updatedLink: LinkedSequenceAsset = {
|
||||
...existingLink,
|
||||
syncedCommentIds: [...existingLink.syncedCommentIds, ...newComments.map((c) => c.id)],
|
||||
syncedMarkerGuids: updatedMarkerGuids,
|
||||
totalCommentsSynced: existingLink.totalCommentsSynced + newComments.length,
|
||||
lastSyncAt: now,
|
||||
}
|
||||
|
||||
await saveSequenceLink(project, sequence, updatedLink)
|
||||
return { updatedLink, addedCount: newComments.length }
|
||||
} catch (err) {
|
||||
console.error('[markers] Failed to execute add markers transaction:', err)
|
||||
return { updatedLink: existingLink, addedCount: 0 }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import {
|
||||
getActiveProject,
|
||||
importFilesIntoProject,
|
||||
promptSelectFolder,
|
||||
promptSaveFile,
|
||||
writeBinaryFile,
|
||||
getPremiereModule,
|
||||
getUxpModule,
|
||||
} from './premiere'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
|
||||
describe('premiere service', () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
// Reset any global require mocks on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (globalThis as any).require
|
||||
// Reset window mock on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
delete (globalThis as any).window
|
||||
})
|
||||
|
||||
describe('module getters', () => {
|
||||
it('returns null when premierepro is not available', () => {
|
||||
expect(getPremiereModule()).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null when uxp is not available', () => {
|
||||
expect(getUxpModule()).toBeNull()
|
||||
})
|
||||
|
||||
it('resolves premiere module from global require when present', () => {
|
||||
const mockPpro = { Project: { getActiveProject: vi.fn() } }
|
||||
// Mocking UXP window environment on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') return mockPpro
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
expect(getPremiereModule()).toBe(mockPpro)
|
||||
})
|
||||
})
|
||||
|
||||
describe('getActiveProject', () => {
|
||||
it('returns null when module is missing', async () => {
|
||||
const project = await getActiveProject()
|
||||
expect(project).toBeNull()
|
||||
})
|
||||
|
||||
it('returns active project when available', async () => {
|
||||
const mockProject = { name: 'MyProject.prproj' }
|
||||
// Mocking UXP window environment on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'premierepro') {
|
||||
return {
|
||||
Project: {
|
||||
getActiveProject: vi.fn().mockResolvedValue(mockProject),
|
||||
},
|
||||
}
|
||||
}
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const project = await getActiveProject()
|
||||
expect(project).toBe(mockProject)
|
||||
})
|
||||
})
|
||||
|
||||
describe('importFilesIntoProject', () => {
|
||||
it('returns false when filePaths is empty', async () => {
|
||||
const project = { importFiles: vi.fn() } as unknown as Project
|
||||
const success = await importFilesIntoProject(project, [])
|
||||
expect(success).toBe(false)
|
||||
expect(project.importFiles).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('calls project.importFiles with suppressUI true', async () => {
|
||||
const project = {
|
||||
importFiles: vi.fn().mockResolvedValue(true),
|
||||
} as unknown as Project
|
||||
|
||||
const success = await importFilesIntoProject(project, ['/path/to/video.mp4'])
|
||||
expect(success).toBe(true)
|
||||
expect(project.importFiles).toHaveBeenCalledWith(['/path/to/video.mp4'], true, null, false)
|
||||
})
|
||||
|
||||
it('handles import error gracefully', async () => {
|
||||
const project = {
|
||||
importFiles: vi.fn().mockRejectedValue(new Error('Import failed in host')),
|
||||
} as unknown as Project
|
||||
|
||||
const success = await importFilesIntoProject(project, ['/path/to/video.mp4'])
|
||||
expect(success).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('promptSelectFolder', () => {
|
||||
it('throws when UXP storage is unavailable', async () => {
|
||||
await expect(promptSelectFolder()).rejects.toThrow('UXP storage')
|
||||
})
|
||||
|
||||
it('delegates to uxp.storage.localFileSystem.getFolder', async () => {
|
||||
const mockFolder: UxpFolderEntry = {
|
||||
isFile: false,
|
||||
isFolder: true,
|
||||
name: 'Downloads',
|
||||
nativePath: '/Users/test/Downloads',
|
||||
createFile: vi.fn(),
|
||||
getEntries: vi.fn().mockResolvedValue([]),
|
||||
}
|
||||
// Mocking UXP window environment on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'uxp') {
|
||||
return {
|
||||
storage: {
|
||||
localFileSystem: {
|
||||
getFolder: vi.fn().mockResolvedValue(mockFolder),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const folder = await promptSelectFolder()
|
||||
expect(folder).toBe(mockFolder)
|
||||
})
|
||||
})
|
||||
|
||||
describe('promptSaveFile', () => {
|
||||
it('throws when UXP storage is unavailable', async () => {
|
||||
await expect(promptSaveFile('test.mp4')).rejects.toThrow('UXP storage')
|
||||
})
|
||||
|
||||
it('delegates to uxp.storage.localFileSystem.getFileForSaving', async () => {
|
||||
const mockFile: UxpFileEntry = {
|
||||
isFile: true,
|
||||
isFolder: false,
|
||||
name: 'test.mp4',
|
||||
nativePath: '/path/test.mp4',
|
||||
write: vi.fn(),
|
||||
}
|
||||
// Mocking UXP window environment on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'uxp') {
|
||||
return {
|
||||
storage: {
|
||||
localFileSystem: {
|
||||
getFileForSaving: vi.fn().mockResolvedValue(mockFile),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const file = await promptSaveFile('test.mp4')
|
||||
expect(file).toBe(mockFile)
|
||||
})
|
||||
})
|
||||
|
||||
describe('writeBinaryFile', () => {
|
||||
it('calls file.write with binary format option', async () => {
|
||||
const mockFile: UxpFileEntry = {
|
||||
isFile: true,
|
||||
isFolder: false,
|
||||
name: 'test.mp4',
|
||||
nativePath: '/path/test.mp4',
|
||||
write: vi.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
|
||||
// Mocking UXP window environment on globalThis
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
;(globalThis as any).window = {
|
||||
require: vi.fn().mockImplementation((name: string) => {
|
||||
if (name === 'uxp') {
|
||||
return {
|
||||
storage: {
|
||||
formats: { binary: 'binary-format-token' },
|
||||
},
|
||||
}
|
||||
}
|
||||
return null
|
||||
}),
|
||||
}
|
||||
|
||||
const dummyBuffer = new ArrayBuffer(16)
|
||||
await writeBinaryFile(mockFile, dummyBuffer)
|
||||
expect(mockFile.write).toHaveBeenCalledWith(dummyBuffer, { format: 'binary-format-token' })
|
||||
})
|
||||
})
|
||||
|
||||
describe('sequence functions', () => {
|
||||
it('getActiveSequence returns active sequence from project', async () => {
|
||||
const { getActiveSequence } = await import('./premiere')
|
||||
const mockSeq = { name: 'Seq 1', guid: 'guid-1' }
|
||||
const mockProject = {
|
||||
getActiveSequence: vi.fn().mockResolvedValue(mockSeq),
|
||||
}
|
||||
|
||||
const seq = await getActiveSequence(mockProject as unknown as Project)
|
||||
expect(seq).toBe(mockSeq)
|
||||
})
|
||||
|
||||
it('getAllSequences returns array of sequences', async () => {
|
||||
const { getAllSequences } = await import('./premiere')
|
||||
const mockSeq1 = { name: 'Seq 1', guid: 'guid-1' }
|
||||
const mockSeq2 = { name: 'Seq 2', guid: 'guid-2' }
|
||||
const mockProject = {
|
||||
getSequences: vi.fn().mockResolvedValue([mockSeq1, mockSeq2]),
|
||||
}
|
||||
|
||||
const seqs = await getAllSequences(mockProject as unknown as Project)
|
||||
expect(seqs).toHaveLength(2)
|
||||
expect(seqs[0].name).toBe('Seq 1')
|
||||
})
|
||||
|
||||
it('openSequenceInTimeline opens and activates sequence', async () => {
|
||||
const { openSequenceInTimeline } = await import('./premiere')
|
||||
const mockSeq = { name: 'Seq 1', guid: 'guid-1' }
|
||||
const mockProject = {
|
||||
openSequence: vi.fn().mockResolvedValue(true),
|
||||
setActiveSequence: vi.fn().mockResolvedValue(true),
|
||||
}
|
||||
|
||||
const result = await openSequenceInTimeline(
|
||||
mockSeq as unknown as Sequence,
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
expect(result).toBe(true)
|
||||
expect(mockProject.openSequence).toHaveBeenCalledWith(mockSeq)
|
||||
expect(mockProject.setActiveSequence).toHaveBeenCalledWith(mockSeq)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,178 @@
|
||||
import type { Project, Sequence, premierepro } from '@adobe/premierepro'
|
||||
|
||||
/**
|
||||
* Safely resolves the Premiere Pro host module (`premierepro`).
|
||||
*/
|
||||
export function getPremiereModule(): premierepro | null {
|
||||
try {
|
||||
// In UXP, host modules are available via require()
|
||||
if (typeof window !== 'undefined' && 'require' in window) {
|
||||
// Dynamic runtime property injected on window by Adobe UXP
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return (window as any).require('premierepro')
|
||||
}
|
||||
if (typeof require !== 'undefined') {
|
||||
// Adobe UXP host modules must be resolved dynamically at runtime via CommonJS require
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
return require('premierepro')
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[UXP] premierepro module not available:', err)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Safely resolves the UXP environment module (`uxp`).
|
||||
*/
|
||||
export function getUxpModule(): UxpModule | null {
|
||||
try {
|
||||
if (typeof window !== 'undefined' && 'require' in window) {
|
||||
// Dynamic runtime property injected on window by Adobe UXP
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
return (window as any).require('uxp')
|
||||
}
|
||||
if (typeof require !== 'undefined') {
|
||||
// Adobe UXP host modules must be resolved dynamically at runtime via CommonJS require
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
return require('uxp')
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[UXP] uxp module not available:', err)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the currently active project in Premiere Pro.
|
||||
*/
|
||||
export async function getActiveProject(): Promise<Project | null> {
|
||||
const ppro = getPremiereModule()
|
||||
if (!ppro?.Project) {
|
||||
return null
|
||||
}
|
||||
try {
|
||||
return await ppro.Project.getActiveProject()
|
||||
} catch (err) {
|
||||
console.error('Failed to get active project:', err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the currently active sequence of the project.
|
||||
*/
|
||||
export async function getActiveSequence(project?: Project | null): Promise<Sequence | null> {
|
||||
const pr = project || (await getActiveProject())
|
||||
if (!pr) return null
|
||||
try {
|
||||
const seq = await pr.getActiveSequence()
|
||||
return seq || null
|
||||
} catch (err) {
|
||||
console.error('Failed to get active sequence:', err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all sequences in the project.
|
||||
*/
|
||||
export async function getAllSequences(project?: Project | null): Promise<Sequence[]> {
|
||||
const pr = project || (await getActiveProject())
|
||||
if (!pr) return []
|
||||
try {
|
||||
const seqs = await pr.getSequences()
|
||||
return seqs || []
|
||||
} catch (err) {
|
||||
console.error('Failed to get all sequences:', err)
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens and activates a sequence in the Premiere Pro timeline.
|
||||
*/
|
||||
export async function openSequenceInTimeline(
|
||||
sequence: Sequence,
|
||||
project?: Project | null,
|
||||
): Promise<boolean> {
|
||||
const pr = project || (await getActiveProject())
|
||||
if (!pr) return false
|
||||
try {
|
||||
const opened = await pr.openSequence(sequence)
|
||||
try {
|
||||
await pr.setActiveSequence(sequence)
|
||||
} catch {
|
||||
// setActiveSequence may not be required if openSequence already focuses it
|
||||
}
|
||||
return opened ?? true
|
||||
} catch (err) {
|
||||
console.error('Failed to open sequence in timeline:', err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports one or more files into the Premiere Pro project root.
|
||||
*/
|
||||
export async function importFilesIntoProject(
|
||||
project: Project,
|
||||
filePaths: string[],
|
||||
): Promise<boolean> {
|
||||
if (!filePaths.length) return false
|
||||
try {
|
||||
return await project.importFiles(
|
||||
filePaths,
|
||||
true, // suppressUI
|
||||
// @ts-expect-error Premiere Pro UXP requires null instead of undefined to default to project root
|
||||
null, // targetBin; `null` defaults to project root
|
||||
false, // asNumberedStills
|
||||
)
|
||||
} catch (err) {
|
||||
console.error('Failed to import files into Premiere project:', err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the native OS folder picker to ask the user where to save files.
|
||||
* Returns the selected UxpFolderEntry, or null if the user cancelled.
|
||||
*/
|
||||
export async function promptSelectFolder(): Promise<UxpFolderEntry | null> {
|
||||
const uxp = getUxpModule()
|
||||
if (!uxp?.storage?.localFileSystem) {
|
||||
throw new Error('UXP storage.localFileSystem is not available.')
|
||||
}
|
||||
try {
|
||||
return await uxp.storage.localFileSystem.getFolder()
|
||||
} catch (err) {
|
||||
console.error('Error in promptSelectFolder:', err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the native OS file picker to ask the user where to save a file.
|
||||
* Returns the selected UxpFileEntry, or null if the user cancelled.
|
||||
*/
|
||||
export async function promptSaveFile(defaultName: string): Promise<UxpFileEntry | null> {
|
||||
const uxp = getUxpModule()
|
||||
if (!uxp?.storage?.localFileSystem) {
|
||||
throw new Error('UXP storage.localFileSystem is not available.')
|
||||
}
|
||||
try {
|
||||
return await uxp.storage.localFileSystem.getFileForSaving(defaultName)
|
||||
} catch (err) {
|
||||
console.error('Error in promptSaveFile:', err)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an ArrayBuffer into a UXP File entry as binary.
|
||||
*/
|
||||
export async function writeBinaryFile(file: UxpFileEntry, data: ArrayBuffer): Promise<void> {
|
||||
const uxp = getUxpModule()
|
||||
const format = uxp?.storage?.formats?.binary
|
||||
await file.write(data, { format })
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest'
|
||||
import { getStoredCredentials, saveStoredCredentials, clearStoredCredentials } from './storage'
|
||||
|
||||
const localStorageMock = (() => {
|
||||
let store: Record<string, string> = {}
|
||||
return {
|
||||
getItem: (key: string) => store[key] || null,
|
||||
setItem: (key: string, value: string) => {
|
||||
store[key] = value.toString()
|
||||
},
|
||||
removeItem: (key: string) => {
|
||||
delete store[key]
|
||||
},
|
||||
clear: () => {
|
||||
store = {}
|
||||
},
|
||||
}
|
||||
})()
|
||||
|
||||
Object.defineProperty(globalThis, 'localStorage', {
|
||||
value: localStorageMock,
|
||||
configurable: true,
|
||||
writable: true,
|
||||
})
|
||||
|
||||
describe('Storage Service', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
it('returns null when no credentials are stored', () => {
|
||||
expect(getStoredCredentials()).toBeNull()
|
||||
})
|
||||
|
||||
it('saves and retrieves credentials correctly', () => {
|
||||
saveStoredCredentials('http://localhost:3000', 'test-api-key')
|
||||
const creds = getStoredCredentials()
|
||||
expect(creds).toEqual({
|
||||
endpoint: 'http://localhost:3000',
|
||||
apiKey: 'test-api-key',
|
||||
})
|
||||
})
|
||||
|
||||
it('normalizes endpoint URL by stripping trailing slashes', () => {
|
||||
saveStoredCredentials('https://api.shumai.io///', 'test-api-key')
|
||||
const creds = getStoredCredentials()
|
||||
expect(creds?.endpoint).toBe('https://api.shumai.io')
|
||||
})
|
||||
|
||||
it('clears stored credentials', () => {
|
||||
saveStoredCredentials('http://localhost:3000', 'test-api-key')
|
||||
clearStoredCredentials()
|
||||
expect(getStoredCredentials()).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
export interface StoredCredentials {
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
}
|
||||
|
||||
const STORAGE_KEY_ENDPOINT = 'shumai_uxp_endpoint'
|
||||
const STORAGE_KEY_API_KEY = 'shumai_uxp_api_key'
|
||||
|
||||
export function getStoredCredentials(): StoredCredentials | null {
|
||||
try {
|
||||
const endpoint = localStorage.getItem(STORAGE_KEY_ENDPOINT)
|
||||
const apiKey = localStorage.getItem(STORAGE_KEY_API_KEY)
|
||||
if (endpoint && apiKey) {
|
||||
return { endpoint, apiKey }
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to read credentials from localStorage:', err)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export function saveStoredCredentials(endpoint: string, apiKey: string): void {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY_ENDPOINT, endpoint.trim().replace(/\/+$/, ''))
|
||||
localStorage.setItem(STORAGE_KEY_API_KEY, apiKey.trim())
|
||||
} catch (err) {
|
||||
console.error('Failed to save credentials to localStorage:', err)
|
||||
}
|
||||
}
|
||||
|
||||
export function clearStoredCredentials(): void {
|
||||
try {
|
||||
localStorage.removeItem(STORAGE_KEY_ENDPOINT)
|
||||
localStorage.removeItem(STORAGE_KEY_API_KEY)
|
||||
} catch (err) {
|
||||
console.error('Failed to clear credentials from localStorage:', err)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export interface LinkedSequenceAsset {
|
||||
sequenceGuid: string
|
||||
sequenceName: string
|
||||
assetId: string
|
||||
assetName: string
|
||||
assetThumbnailUrl?: string
|
||||
endpoint?: string
|
||||
projectId?: string
|
||||
syncedCommentIds: string[]
|
||||
syncedMarkerGuids?: string[]
|
||||
lastSyncAt: number
|
||||
totalCommentsSynced: number
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
export function formatDateAgo(dateInput?: string | number | Date | null): string {
|
||||
if (!dateInput) return ''
|
||||
const date =
|
||||
typeof dateInput === 'string' || typeof dateInput === 'number' ? new Date(dateInput) : dateInput
|
||||
if (isNaN(date.getTime())) return ''
|
||||
|
||||
const now = new Date()
|
||||
const diffSec = Math.max(0, Math.floor((now.getTime() - date.getTime()) / 1000))
|
||||
|
||||
if (diffSec < 60) return 'just now'
|
||||
|
||||
const diffMin = Math.floor(diffSec / 60)
|
||||
if (diffMin < 60) return `${diffMin}m ago`
|
||||
|
||||
const diffHours = Math.floor(diffMin / 60)
|
||||
if (diffHours < 24) return `${diffHours}h ago`
|
||||
|
||||
const diffDays = Math.floor(diffHours / 24)
|
||||
if (diffDays === 1) return 'yesterday'
|
||||
if (diffDays < 30) return `${diffDays}d ago`
|
||||
|
||||
const diffMonths = Math.floor(diffDays / 30)
|
||||
if (diffMonths < 12) return `${diffMonths}mo ago`
|
||||
|
||||
const diffYears = Math.floor(diffMonths / 12)
|
||||
return `${diffYears}y ago`
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { formatBytes, formatDuration } from './format'
|
||||
|
||||
describe('formatBytes', () => {
|
||||
it('handles null, undefined, 0 and invalid inputs', () => {
|
||||
expect(formatBytes(null)).toBe('0 B')
|
||||
expect(formatBytes(undefined)).toBe('0 B')
|
||||
expect(formatBytes(0)).toBe('0 B')
|
||||
expect(formatBytes(-100)).toBe('0 B')
|
||||
expect(formatBytes(NaN)).toBe('0 B')
|
||||
})
|
||||
|
||||
it('formats bytes correctly', () => {
|
||||
expect(formatBytes(500)).toBe('500 B')
|
||||
expect(formatBytes(1024)).toBe('1.0 KB')
|
||||
expect(formatBytes(1536)).toBe('1.5 KB')
|
||||
expect(formatBytes(1048576)).toBe('1.0 MB')
|
||||
expect(formatBytes(1073741824)).toBe('1.0 GB')
|
||||
})
|
||||
})
|
||||
|
||||
describe('formatDuration', () => {
|
||||
it('returns null for invalid or non-positive durations', () => {
|
||||
expect(formatDuration(null)).toBeNull()
|
||||
expect(formatDuration(undefined)).toBeNull()
|
||||
expect(formatDuration(0)).toBeNull()
|
||||
expect(formatDuration(-15)).toBeNull()
|
||||
expect(formatDuration(NaN)).toBeNull()
|
||||
})
|
||||
|
||||
it('formats seconds into MM:SS format', () => {
|
||||
expect(formatDuration(5.4)).toBe('00:05')
|
||||
expect(formatDuration(59)).toBe('00:59')
|
||||
expect(formatDuration(60)).toBe('01:00')
|
||||
expect(formatDuration(65)).toBe('01:05')
|
||||
expect(formatDuration(3599)).toBe('59:59')
|
||||
})
|
||||
|
||||
it('formats hours into H:MM:SS format', () => {
|
||||
expect(formatDuration(3600)).toBe('1:00:00')
|
||||
expect(formatDuration(3665)).toBe('1:01:05')
|
||||
expect(formatDuration(36665)).toBe('10:11:05')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Formats a byte count into a human-readable size string (e.g. 1.2 MB, 450 KB).
|
||||
*/
|
||||
export function formatBytes(bytes?: number | null): string {
|
||||
if (bytes == null || bytes === 0 || isNaN(bytes) || bytes < 0) return '0 B'
|
||||
const units = ['B', 'KB', 'MB', 'GB', 'TB']
|
||||
const i = Math.floor(Math.log(bytes) / Math.log(1024))
|
||||
const safeIndex = Math.min(Math.max(0, i), units.length - 1)
|
||||
return `${(bytes / Math.pow(1024, safeIndex)).toFixed(safeIndex === 0 ? 0 : 1)} ${units[safeIndex]}`
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats duration in seconds into MM:SS or H:MM:SS format (e.g. 02:45, 1:12:30).
|
||||
* Returns null if duration is invalid, zero or negative.
|
||||
*/
|
||||
export function formatDuration(seconds?: number | null): string | null {
|
||||
if (seconds == null || isNaN(seconds) || seconds <= 0) return null
|
||||
const totalSecs = Math.round(seconds)
|
||||
const hours = Math.floor(totalSecs / 3600)
|
||||
const minutes = Math.floor((totalSecs % 3600) / 60)
|
||||
const secs = totalSecs % 60
|
||||
if (hours > 0) {
|
||||
return `${hours}:${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
|
||||
}
|
||||
return `${minutes.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { resolveAssetUrl, normalizeEndpoint, isSameEndpoint } from './url'
|
||||
|
||||
describe('resolveAssetUrl', () => {
|
||||
it('returns undefined for empty or null inputs', () => {
|
||||
expect(resolveAssetUrl(null, 'http://localhost:3000')).toBeUndefined()
|
||||
expect(resolveAssetUrl(undefined, 'http://localhost:3000')).toBeUndefined()
|
||||
expect(resolveAssetUrl('', 'http://localhost:3000')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('returns original url if endpoint is not provided', () => {
|
||||
expect(resolveAssetUrl('/files/123')).toBe('/files/123')
|
||||
expect(resolveAssetUrl('http://example.com/img.png')).toBe('http://example.com/img.png')
|
||||
})
|
||||
|
||||
it('prepends endpoint to relative paths', () => {
|
||||
expect(resolveAssetUrl('/files/shumai/cat.png', 'http://localhost:3000')).toBe(
|
||||
'http://localhost:3000/files/shumai/cat.png',
|
||||
)
|
||||
expect(resolveAssetUrl('/files/shumai/cat.png', 'http://localhost:3000/')).toBe(
|
||||
'http://localhost:3000/files/shumai/cat.png',
|
||||
)
|
||||
})
|
||||
|
||||
it('preserves absolute URLs intact even when hosts differ', () => {
|
||||
const localRaw = 'http://localhost:3000/files/shumai/files/cat.webp'
|
||||
const endpoint = 'http://127.0.0.1:3000'
|
||||
expect(resolveAssetUrl(localRaw, endpoint)).toBe(localRaw)
|
||||
|
||||
const remoteEndpoint = 'https://shumai.example.com'
|
||||
expect(resolveAssetUrl(localRaw, remoteEndpoint)).toBe(localRaw)
|
||||
})
|
||||
|
||||
it('keeps matching absolute URLs intact', () => {
|
||||
const raw = 'http://localhost:3000/files/shumai/cat.png'
|
||||
expect(resolveAssetUrl(raw, 'http://localhost:3000')).toBe(raw)
|
||||
})
|
||||
|
||||
it('preserves remote cloud storage presigned URLs without rewriting host', () => {
|
||||
const r2Url =
|
||||
'https://04e37a3c563610bccea6a3ce6f8618ca.r2.cloudflarestorage.com/shumai/files/01KYKNT8NEJ3Q1G6A6K08M2XHC/Float%2002-480p.jpeg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Signature=8112ab30'
|
||||
const endpoint = 'https://staging.shumai.one'
|
||||
expect(resolveAssetUrl(r2Url, endpoint)).toBe(r2Url)
|
||||
})
|
||||
})
|
||||
|
||||
describe('normalizeEndpoint', () => {
|
||||
it('handles empty and null values', () => {
|
||||
expect(normalizeEndpoint('')).toBe('')
|
||||
expect(normalizeEndpoint(null)).toBe('')
|
||||
expect(normalizeEndpoint(undefined)).toBe('')
|
||||
})
|
||||
|
||||
it('trims whitespace and trailing slashes and converts to lower case', () => {
|
||||
expect(normalizeEndpoint(' https://STAGING.shumai.one/// ')).toBe('https://staging.shumai.one')
|
||||
expect(normalizeEndpoint('http://localhost:3000/')).toBe('http://localhost:3000')
|
||||
})
|
||||
})
|
||||
|
||||
describe('isSameEndpoint', () => {
|
||||
it('returns true when endpoints match ignoring slashes and casing', () => {
|
||||
expect(isSameEndpoint('https://staging.shumai.one/', 'https://STAGING.shumai.one')).toBe(true)
|
||||
expect(isSameEndpoint('http://localhost:3000', 'http://localhost:3000/')).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false when endpoints differ', () => {
|
||||
expect(isSameEndpoint('http://localhost:3000', 'https://staging.shumai.one')).toBe(false)
|
||||
expect(isSameEndpoint('http://localhost:3000', 'http://127.0.0.1:3000')).toBe(false)
|
||||
expect(isSameEndpoint('', 'http://localhost:3000')).toBe(false)
|
||||
expect(isSameEndpoint(null, undefined)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Utility functions for URL manipulation and resolution in UXP plugins.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Resolves an asset URL (such as a thumbnail or file download) against
|
||||
* the user-configured Shumai endpoint.
|
||||
*
|
||||
* Handles:
|
||||
* - Relative paths (/files/..., /api/...) by prepending the endpoint.
|
||||
* - Absolute URLs (http://, https://) are preserved as-is.
|
||||
*/
|
||||
export function resolveAssetUrl(url?: string | null, endpoint?: string): string | undefined {
|
||||
if (!url) return undefined
|
||||
if (!endpoint) return url
|
||||
|
||||
const cleanEndpoint = endpoint.replace(/\/+$/, '')
|
||||
|
||||
// Handle relative URLs (e.g. /files/..., /api/...)
|
||||
if (url.startsWith('/') && !url.startsWith('//')) {
|
||||
return `${cleanEndpoint}${url}`
|
||||
}
|
||||
|
||||
return url
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes an endpoint URL by trimming whitespace, stripping trailing slashes,
|
||||
* and converting to lower case for reliable comparison.
|
||||
*/
|
||||
export function normalizeEndpoint(endpoint?: string | null): string {
|
||||
if (!endpoint) return ''
|
||||
return endpoint.trim().replace(/\/+$/, '').toLowerCase()
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if two endpoints refer to the same server URL.
|
||||
*/
|
||||
export function isSameEndpoint(ep1?: string | null, ep2?: string | null): boolean {
|
||||
const n1 = normalizeEndpoint(ep1)
|
||||
const n2 = normalizeEndpoint(ep2)
|
||||
return Boolean(n1 && n2 && n1 === n2)
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
import React, { useState } from 'react'
|
||||
import { getShumaiClient } from '../api/client'
|
||||
import { saveStoredCredentials } from '../services/storage'
|
||||
import { Button } from '@swc-react/button'
|
||||
import { Textfield } from '@swc-react/textfield'
|
||||
import { FieldLabel } from '@swc-react/field-label'
|
||||
import { HelpText } from '@swc-react/help-text'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
|
||||
interface AuthViewProps {
|
||||
initialEndpoint?: string
|
||||
initialApiKey?: string
|
||||
onConnectSuccess: (endpoint: string, apiKey: string) => void
|
||||
}
|
||||
|
||||
export const AuthView: React.FC<AuthViewProps> = ({
|
||||
initialEndpoint = 'http://localhost:3000',
|
||||
initialApiKey = '',
|
||||
onConnectSuccess,
|
||||
}) => {
|
||||
const [endpoint, setEndpoint] = useState(initialEndpoint)
|
||||
const [apiKey, setApiKey] = useState(initialApiKey)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [errorMessage, setErrorMessage] = useState<string | null>(null)
|
||||
|
||||
const handleConnect = async (e?: React.SyntheticEvent) => {
|
||||
if (e) {
|
||||
e.preventDefault()
|
||||
}
|
||||
setErrorMessage(null)
|
||||
|
||||
const trimmedEndpoint = endpoint.trim().replace(/\/+$/, '')
|
||||
const trimmedKey = apiKey.trim()
|
||||
|
||||
if (!trimmedEndpoint) {
|
||||
setErrorMessage('Please enter your Shumai server endpoint.')
|
||||
return
|
||||
}
|
||||
|
||||
if (!trimmedKey) {
|
||||
setErrorMessage('Please enter your Shumai API key.')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
new URL(trimmedEndpoint)
|
||||
} catch {
|
||||
setErrorMessage(
|
||||
'Invalid endpoint URL. Example: http://localhost:3000 or https://shumai.example.com',
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
setLoading(true)
|
||||
console.log('[Shumai UXP] Connecting to:', trimmedEndpoint)
|
||||
|
||||
try {
|
||||
const client = getShumaiClient(trimmedEndpoint, trimmedKey)
|
||||
const res = await client.api.projects.$get({
|
||||
query: { first: '1' },
|
||||
})
|
||||
|
||||
console.log('[Shumai UXP] Response status:', res.status)
|
||||
|
||||
if (res.status === 401) {
|
||||
setErrorMessage('Unauthorized: Invalid API Key. Please verify your token.')
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
if (!res.ok) {
|
||||
const errorData = (await res.json().catch(() => ({}))) as { error?: string }
|
||||
setErrorMessage(errorData.error || `Connection failed with status ${res.status}`)
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
// Validated successfully
|
||||
saveStoredCredentials(trimmedEndpoint, trimmedKey)
|
||||
onConnectSuccess(trimmedEndpoint, trimmedKey)
|
||||
} catch (err) {
|
||||
console.error('[Shumai UXP] Failed to connect to Shumai server:', err)
|
||||
setErrorMessage(
|
||||
err instanceof Error
|
||||
? `Cannot reach server: ${err.message}`
|
||||
: 'Could not connect to the Shumai server. Please check the URL and your network connection.',
|
||||
)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
handleConnect(e)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="view-content" style={{ justifyContent: 'center' }}>
|
||||
<div className="auth-container">
|
||||
<div className="auth-header">
|
||||
<h2>Connect to Shumai</h2>
|
||||
<p>Enter your server URL and API key to integrate Premiere Pro with your workspace.</p>
|
||||
</div>
|
||||
|
||||
{errorMessage && (
|
||||
<div style={{ marginBottom: '12px' }}>
|
||||
<HelpText variant="negative" icon>
|
||||
{errorMessage}
|
||||
</HelpText>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="auth-form">
|
||||
<div className="form-group">
|
||||
<FieldLabel for="endpoint-input">Server Endpoint</FieldLabel>
|
||||
<Textfield
|
||||
id="endpoint-input"
|
||||
style={{ width: '100%' }}
|
||||
placeholder="https://shumai.example.com"
|
||||
value={endpoint}
|
||||
onInput={(e: React.FormEvent<HTMLElement>) =>
|
||||
setEndpoint((e.target as HTMLInputElement).value)
|
||||
}
|
||||
onKeyDown={handleKeyDown}
|
||||
disabled={loading}
|
||||
invalid={Boolean(errorMessage && !endpoint.trim())}
|
||||
/>
|
||||
<HelpText>The base URL of your Shumai backend instance.</HelpText>
|
||||
</div>
|
||||
|
||||
<div className="form-group">
|
||||
<FieldLabel for="api-key-input">API Key</FieldLabel>
|
||||
<Textfield
|
||||
id="api-key-input"
|
||||
type="password"
|
||||
style={{ width: '100%' }}
|
||||
placeholder="Paste your API key here"
|
||||
value={apiKey}
|
||||
onInput={(e: React.FormEvent<HTMLElement>) =>
|
||||
setApiKey((e.target as HTMLInputElement).value)
|
||||
}
|
||||
onKeyDown={handleKeyDown}
|
||||
disabled={loading}
|
||||
invalid={Boolean(errorMessage && !apiKey.trim())}
|
||||
/>
|
||||
<HelpText>Generate an API key in Shumai: Settings > Developer.</HelpText>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="accent"
|
||||
onClick={handleConnect}
|
||||
style={{ width: '100%', marginTop: '8px' }}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Connecting...' : 'Connect Workspace'}
|
||||
{loading ? (
|
||||
<ProgressCircle indeterminate size="s" static-color="white" slot="icon" />
|
||||
) : (
|
||||
<sp-icon-arrow-right size="s" slot="icon"></sp-icon-arrow-right>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,790 @@
|
||||
import React, { useEffect, useState, useCallback } from 'react'
|
||||
import { getShumaiClient } from '../api/client'
|
||||
import { Breadcrumb, BreadcrumbCrumb } from '../components/Breadcrumb'
|
||||
import { FileCardItem, AssetSummary } from '../components/FileItem'
|
||||
import { ImportVideoDialog } from '../components/ImportVideoDialog'
|
||||
import { LinkSequenceDialog } from '../components/LinkSequenceDialog'
|
||||
import {
|
||||
getAllSequenceLinksFromCache,
|
||||
getAllLinkedSequences,
|
||||
normalizeGuid,
|
||||
removeSequenceLink,
|
||||
removeSequenceLinkFromCache,
|
||||
} from '../services/linkStorage'
|
||||
import { getActiveProject, getAllSequences } from '../services/premiere'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
import { importAssetIntoPremiere, type ProxyOption } from '../services/import'
|
||||
import { ProjectSummary } from './ProjectsView'
|
||||
import { isSameEndpoint } from '../utils/url'
|
||||
import { ActionButton } from '@swc-react/action-button'
|
||||
import { Button } from '@swc-react/button'
|
||||
import { Search } from '@swc-react/search'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
import { StatusLight } from '@swc-react/status-light'
|
||||
import { IllustratedMessage } from '@swc-react/illustrated-message'
|
||||
import { Divider } from '@swc-react/divider'
|
||||
import type { SearchCondition, SearchSort } from '@shumai/dtos'
|
||||
|
||||
const PAGE_SIZE = 20
|
||||
|
||||
interface FileListViewProps {
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
project: ProjectSummary
|
||||
onBackToProjects: () => void
|
||||
onLinkCountChange?: (count: number) => void
|
||||
}
|
||||
|
||||
export const FileListView: React.FC<FileListViewProps> = ({
|
||||
endpoint,
|
||||
apiKey,
|
||||
project,
|
||||
onBackToProjects,
|
||||
onLinkCountChange,
|
||||
}) => {
|
||||
const [currentFolderId, setCurrentFolderId] = useState<string | null>(project.rootFolder || null)
|
||||
const [crumbs, setCrumbs] = useState<BreadcrumbCrumb[]>([])
|
||||
|
||||
// Folders state
|
||||
const [folders, setFolders] = useState<AssetSummary[]>([])
|
||||
const [foldersTotal, setFoldersTotal] = useState<number | null>(null)
|
||||
const [foldersCursor, setFoldersCursor] = useState<string | null>(null)
|
||||
const [foldersHasNext, setFoldersHasNext] = useState(false)
|
||||
const [foldersExpanded, setFoldersExpanded] = useState(true)
|
||||
const [loadingMoreFolders, setLoadingMoreFolders] = useState(false)
|
||||
|
||||
// Files state
|
||||
const [files, setFiles] = useState<AssetSummary[]>([])
|
||||
const [filesTotal, setFilesTotal] = useState<number | null>(null)
|
||||
const [filesCursor, setFilesCursor] = useState<string | null>(null)
|
||||
const [filesHasNext, setFilesHasNext] = useState(false)
|
||||
const [filesExpanded, setFilesExpanded] = useState(true)
|
||||
const [loadingMoreFiles, setLoadingMoreFiles] = useState(false)
|
||||
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [searchTerm, setSearchTerm] = useState('')
|
||||
const [debouncedSearch, setDebouncedSearch] = useState('')
|
||||
const [videoForDialog, setVideoForDialog] = useState<AssetSummary | null>(null)
|
||||
const [assetForLinkDialog, setAssetForLinkDialog] = useState<AssetSummary | null>(null)
|
||||
const [linkedAssetsMap, setLinkedAssetsMap] = useState<Record<string, LinkedSequenceAsset>>({})
|
||||
|
||||
// Refresh links from cache and active Premiere project
|
||||
const refreshLinkedAssets = useCallback(async () => {
|
||||
// 1. Immediately read from cache (fast, non-blocking)
|
||||
const cachedLinks = getAllSequenceLinksFromCache()
|
||||
if (cachedLinks.length > 0) {
|
||||
const map: Record<string, LinkedSequenceAsset> = {}
|
||||
for (const link of cachedLinks) {
|
||||
if (!link.endpoint || isSameEndpoint(link.endpoint, endpoint)) {
|
||||
map[link.assetId] = link
|
||||
}
|
||||
}
|
||||
setLinkedAssetsMap((prev) => ({ ...prev, ...map }))
|
||||
onLinkCountChange?.(Object.keys(map).length)
|
||||
}
|
||||
|
||||
// 2. Query active project in Premiere Pro for live persistent links
|
||||
try {
|
||||
const pr = await getActiveProject()
|
||||
if (pr) {
|
||||
const liveLinks = await getAllLinkedSequences(pr)
|
||||
const liveMap: Record<string, LinkedSequenceAsset> = {}
|
||||
for (const link of liveLinks) {
|
||||
if (!link.endpoint || isSameEndpoint(link.endpoint, endpoint)) {
|
||||
liveMap[link.assetId] = link
|
||||
}
|
||||
}
|
||||
setLinkedAssetsMap(liveMap)
|
||||
onLinkCountChange?.(Object.keys(liveMap).length)
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[FileListView] Could not get linked sequences from active project:', err)
|
||||
}
|
||||
}, [endpoint, onLinkCountChange])
|
||||
|
||||
useEffect(() => {
|
||||
void refreshLinkedAssets()
|
||||
}, [refreshLinkedAssets])
|
||||
|
||||
const handleUnlinkAsset = useCallback(
|
||||
async (asset: AssetSummary) => {
|
||||
const link = linkedAssetsMap[asset.id]
|
||||
if (!link) return
|
||||
|
||||
// Optimistically remove from state immediately
|
||||
setLinkedAssetsMap((prev) => {
|
||||
const copy = { ...prev }
|
||||
delete copy[asset.id]
|
||||
return copy
|
||||
})
|
||||
|
||||
try {
|
||||
const pr = await getActiveProject()
|
||||
if (pr) {
|
||||
const allSeqs = await getAllSequences(pr)
|
||||
const targetSeq = allSeqs.find(
|
||||
(s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid),
|
||||
)
|
||||
if (targetSeq) {
|
||||
await removeSequenceLink(pr, targetSeq)
|
||||
} else {
|
||||
removeSequenceLinkFromCache(link.sequenceGuid, pr.guid ? pr.guid.toString() : null)
|
||||
}
|
||||
} else {
|
||||
removeSequenceLinkFromCache(link.sequenceGuid)
|
||||
}
|
||||
void refreshLinkedAssets()
|
||||
setImportStatus({
|
||||
id: Date.now().toString(),
|
||||
fileName: asset.name,
|
||||
status: 'success',
|
||||
message: `Unlinked from "${link.sequenceName}".`,
|
||||
})
|
||||
setTimeout(() => {
|
||||
setImportStatus((prev) => (prev?.fileName === asset.name ? null : prev))
|
||||
}, 3000)
|
||||
} catch (err) {
|
||||
console.error('Failed to unlink asset:', err)
|
||||
void refreshLinkedAssets()
|
||||
setImportStatus({
|
||||
id: Date.now().toString(),
|
||||
fileName: asset.name,
|
||||
status: 'error',
|
||||
message: 'Failed to unlink sequence.',
|
||||
})
|
||||
setTimeout(() => {
|
||||
setImportStatus((prev) => (prev?.fileName === asset.name ? null : prev))
|
||||
}, 4000)
|
||||
}
|
||||
},
|
||||
[linkedAssetsMap, refreshLinkedAssets],
|
||||
)
|
||||
|
||||
// Import task state
|
||||
const [importStatus, setImportStatus] = useState<{
|
||||
id: string
|
||||
fileName: string
|
||||
status: 'importing' | 'success' | 'error'
|
||||
message: string
|
||||
} | null>(null)
|
||||
|
||||
const runImport = async (asset: AssetSummary, type: 'raw' | 'proxy', proxyItem?: ProxyOption) => {
|
||||
const taskId = Date.now().toString()
|
||||
const label = type === 'raw' ? asset.name : `${asset.name} (${proxyItem?.label || 'Proxy'})`
|
||||
setImportStatus({
|
||||
id: taskId,
|
||||
fileName: label,
|
||||
status: 'importing',
|
||||
message: 'Starting import...',
|
||||
})
|
||||
|
||||
try {
|
||||
const result = await importAssetIntoPremiere({
|
||||
endpoint,
|
||||
apiKey,
|
||||
asset,
|
||||
type,
|
||||
proxyItem,
|
||||
onProgress: (msg) => {
|
||||
setImportStatus((prev) => (prev?.id === taskId ? { ...prev, message: msg } : prev))
|
||||
},
|
||||
})
|
||||
|
||||
if (result.cancelled) {
|
||||
setImportStatus(null)
|
||||
return
|
||||
}
|
||||
|
||||
if (result.success) {
|
||||
setImportStatus({
|
||||
id: taskId,
|
||||
fileName: result.fileName || label,
|
||||
status: 'success',
|
||||
message: result.message,
|
||||
})
|
||||
setTimeout(() => {
|
||||
setImportStatus((prev) => (prev?.id === taskId ? null : prev))
|
||||
}, 4000)
|
||||
} else {
|
||||
setImportStatus({
|
||||
id: taskId,
|
||||
fileName: label,
|
||||
status: 'error',
|
||||
message: result.message,
|
||||
})
|
||||
setTimeout(() => {
|
||||
setImportStatus((prev) => (prev?.id === taskId ? null : prev))
|
||||
}, 6000)
|
||||
}
|
||||
} catch (err) {
|
||||
setImportStatus({
|
||||
id: taskId,
|
||||
fileName: label,
|
||||
status: 'error',
|
||||
message: err instanceof Error ? err.message : 'Import failed.',
|
||||
})
|
||||
setTimeout(() => {
|
||||
setImportStatus((prev) => (prev?.id === taskId ? null : prev))
|
||||
}, 6000)
|
||||
}
|
||||
}
|
||||
|
||||
const handleImportRaw = (asset: AssetSummary) => {
|
||||
runImport(asset, 'raw')
|
||||
}
|
||||
|
||||
const handleImportProxy = (asset: AssetSummary, proxy: ProxyOption) => {
|
||||
runImport(asset, 'proxy', proxy)
|
||||
}
|
||||
|
||||
// Debounce search term by 300ms
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setDebouncedSearch(searchTerm.trim())
|
||||
}, 300)
|
||||
return () => clearTimeout(timer)
|
||||
}, [searchTerm])
|
||||
|
||||
// Initial fetch of both folders and files
|
||||
const fetchContents = useCallback(
|
||||
async (folderId: string, query: string) => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
const isSearching = Boolean(query)
|
||||
|
||||
const conditions: SearchCondition[] = isSearching
|
||||
? [{ field: 'name', operator: 'contains', value: query }]
|
||||
: []
|
||||
|
||||
const sort: SearchSort = { field: 'name', order: 'asc' }
|
||||
|
||||
// Fetch first page of folders and files in parallel
|
||||
const [foldersRes, filesRes] = await Promise.all([
|
||||
client.api.folders[':folderId'].search.$post({
|
||||
param: { folderId },
|
||||
json: {
|
||||
assetType: 'folder',
|
||||
recursively: isSearching,
|
||||
conditions,
|
||||
sort,
|
||||
first: PAGE_SIZE,
|
||||
previewFormat: 'jpeg',
|
||||
},
|
||||
}),
|
||||
client.api.folders[':folderId'].search.$post({
|
||||
param: { folderId },
|
||||
json: {
|
||||
assetType: 'file',
|
||||
recursively: isSearching,
|
||||
conditions,
|
||||
sort,
|
||||
first: PAGE_SIZE,
|
||||
previewFormat: 'jpeg',
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
if (!foldersRes.ok) {
|
||||
const errData = (await foldersRes.json().catch(() => ({}))) as { error?: string }
|
||||
throw new Error(errData.error || `Failed to search folders (${foldersRes.status})`)
|
||||
}
|
||||
if (!filesRes.ok) {
|
||||
const errData = (await filesRes.json().catch(() => ({}))) as { error?: string }
|
||||
throw new Error(errData.error || `Failed to search files (${filesRes.status})`)
|
||||
}
|
||||
|
||||
const foldersBody = await foldersRes.json()
|
||||
const filesBody = await filesRes.json()
|
||||
|
||||
const folderItems = (foldersBody.data || []) as AssetSummary[]
|
||||
const fileItems = (filesBody.data || []) as AssetSummary[]
|
||||
|
||||
setFolders(folderItems)
|
||||
setFoldersCursor(foldersBody.pageInfo?.cursor || null)
|
||||
setFoldersHasNext(Boolean(foldersBody.pageInfo?.cursor))
|
||||
setFoldersTotal(foldersBody.pageInfo?.total ?? folderItems.length)
|
||||
|
||||
setFiles(fileItems)
|
||||
setFilesCursor(filesBody.pageInfo?.cursor || null)
|
||||
setFilesHasNext(Boolean(filesBody.pageInfo?.cursor))
|
||||
setFilesTotal(filesBody.pageInfo?.total ?? fileItems.length)
|
||||
} catch (err) {
|
||||
console.error('Error fetching folder contents via search API:', err)
|
||||
setError(err instanceof Error ? err.message : 'Failed to load folder contents.')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
},
|
||||
[endpoint, apiKey],
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (currentFolderId) {
|
||||
fetchContents(currentFolderId, debouncedSearch)
|
||||
} else {
|
||||
setError('Root folder ID not available for this project.')
|
||||
setLoading(false)
|
||||
}
|
||||
}, [currentFolderId, debouncedSearch, fetchContents])
|
||||
|
||||
// Paginate next files
|
||||
const fetchNextFilesPage = useCallback(async () => {
|
||||
if (!currentFolderId || !filesHasNext || loadingMoreFiles || loading) return
|
||||
setLoadingMoreFiles(true)
|
||||
try {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
const isSearching = Boolean(debouncedSearch)
|
||||
const conditions: SearchCondition[] = isSearching
|
||||
? [{ field: 'name', operator: 'contains', value: debouncedSearch }]
|
||||
: []
|
||||
const sort: SearchSort = { field: 'name', order: 'asc' }
|
||||
|
||||
const res = await client.api.folders[':folderId'].search.$post({
|
||||
param: { folderId: currentFolderId },
|
||||
json: {
|
||||
assetType: 'file',
|
||||
recursively: isSearching,
|
||||
conditions,
|
||||
sort,
|
||||
first: PAGE_SIZE,
|
||||
after: filesCursor || undefined,
|
||||
previewFormat: 'jpeg',
|
||||
},
|
||||
})
|
||||
if (res.ok) {
|
||||
const body = await res.json()
|
||||
const newFiles = (body.data || []) as AssetSummary[]
|
||||
setFiles((prev) => [...prev, ...newFiles])
|
||||
setFilesCursor(body.pageInfo?.cursor || null)
|
||||
setFilesHasNext(Boolean(body.pageInfo?.cursor))
|
||||
if (body.pageInfo?.total != null) {
|
||||
setFilesTotal(body.pageInfo.total)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching next files page:', err)
|
||||
} finally {
|
||||
setLoadingMoreFiles(false)
|
||||
}
|
||||
}, [
|
||||
currentFolderId,
|
||||
filesHasNext,
|
||||
loadingMoreFiles,
|
||||
loading,
|
||||
endpoint,
|
||||
apiKey,
|
||||
debouncedSearch,
|
||||
filesCursor,
|
||||
])
|
||||
|
||||
// Paginate next folders
|
||||
const fetchNextFoldersPage = useCallback(async () => {
|
||||
if (!currentFolderId || !foldersHasNext || loadingMoreFolders || loading) return
|
||||
setLoadingMoreFolders(true)
|
||||
try {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
const isSearching = Boolean(debouncedSearch)
|
||||
const conditions: SearchCondition[] = isSearching
|
||||
? [{ field: 'name', operator: 'contains', value: debouncedSearch }]
|
||||
: []
|
||||
const sort: SearchSort = { field: 'name', order: 'asc' }
|
||||
|
||||
const res = await client.api.folders[':folderId'].search.$post({
|
||||
param: { folderId: currentFolderId },
|
||||
json: {
|
||||
assetType: 'folder',
|
||||
recursively: isSearching,
|
||||
conditions,
|
||||
sort,
|
||||
first: PAGE_SIZE,
|
||||
after: foldersCursor || undefined,
|
||||
previewFormat: 'jpeg',
|
||||
},
|
||||
})
|
||||
if (res.ok) {
|
||||
const body = await res.json()
|
||||
const newFolders = (body.data || []) as AssetSummary[]
|
||||
setFolders((prev) => [...prev, ...newFolders])
|
||||
setFoldersCursor(body.pageInfo?.cursor || null)
|
||||
setFoldersHasNext(Boolean(body.pageInfo?.cursor))
|
||||
if (body.pageInfo?.total != null) {
|
||||
setFoldersTotal(body.pageInfo.total)
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error fetching next folders page:', err)
|
||||
} finally {
|
||||
setLoadingMoreFolders(false)
|
||||
}
|
||||
}, [
|
||||
currentFolderId,
|
||||
foldersHasNext,
|
||||
loadingMoreFolders,
|
||||
loading,
|
||||
endpoint,
|
||||
apiKey,
|
||||
debouncedSearch,
|
||||
foldersCursor,
|
||||
])
|
||||
|
||||
// Infinite scroll listener
|
||||
const handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
|
||||
const target = e.currentTarget
|
||||
const threshold = 120
|
||||
const isNearBottom = target.scrollHeight - target.scrollTop - target.clientHeight <= threshold
|
||||
if (isNearBottom) {
|
||||
if (filesExpanded && filesHasNext && !loadingMoreFiles) {
|
||||
fetchNextFilesPage()
|
||||
} else if (
|
||||
foldersExpanded &&
|
||||
foldersHasNext &&
|
||||
!loadingMoreFolders &&
|
||||
(!filesExpanded || files.length === 0)
|
||||
) {
|
||||
fetchNextFoldersPage()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleFolderClick = (folder: AssetSummary) => {
|
||||
setCrumbs((prev) => [...prev, { id: folder.id, name: folder.name }])
|
||||
setCurrentFolderId(folder.id)
|
||||
setSearchTerm('')
|
||||
}
|
||||
|
||||
const handleCrumbNavigate = (crumbIndex: number) => {
|
||||
setSearchTerm('')
|
||||
if (crumbIndex === -1) {
|
||||
setCrumbs([])
|
||||
if (project.rootFolder) {
|
||||
setCurrentFolderId(project.rootFolder)
|
||||
}
|
||||
} else {
|
||||
const targetCrumb = crumbs[crumbIndex]
|
||||
setCrumbs((prev) => prev.slice(0, crumbIndex + 1))
|
||||
setCurrentFolderId(targetCrumb.id)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flex: 1,
|
||||
minHeight: 0,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<Breadcrumb
|
||||
projectName={project.name}
|
||||
crumbs={crumbs}
|
||||
onNavigateToProjects={onBackToProjects}
|
||||
onNavigateToCrumb={handleCrumbNavigate}
|
||||
/>
|
||||
|
||||
{/* Sticky Header: Search input & Refresh button */}
|
||||
<div className="view-sticky-header">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
gap: '8px',
|
||||
marginBottom: '8px',
|
||||
}}
|
||||
>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Search
|
||||
style={{ width: '100%' }}
|
||||
placeholder="Search files and folders..."
|
||||
value={searchTerm}
|
||||
onInput={(e: React.FormEvent<HTMLElement>) =>
|
||||
setSearchTerm((e.target as HTMLInputElement).value)
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<sp-button
|
||||
quiet
|
||||
variant="secondary"
|
||||
size="s"
|
||||
label="Refresh folder"
|
||||
icon-only
|
||||
onClick={() => {
|
||||
if (currentFolderId) {
|
||||
fetchContents(currentFolderId, debouncedSearch)
|
||||
void refreshLinkedAssets()
|
||||
}
|
||||
}}
|
||||
title="Refresh folder"
|
||||
disabled={loading || !currentFolderId}
|
||||
>
|
||||
<sp-icon-refresh
|
||||
slot="icon"
|
||||
size="s"
|
||||
className={loading ? 'spin' : ''}
|
||||
></sp-icon-refresh>
|
||||
</sp-button>
|
||||
</div>
|
||||
<Divider size="s" />
|
||||
</div>
|
||||
|
||||
<div className="view-content" onScroll={handleScroll}>
|
||||
{loading && (
|
||||
<div className="state-container">
|
||||
<ProgressCircle indeterminate size="m" label="Loading folder contents..." />
|
||||
<p style={{ marginTop: '8px' }}>Loading folder contents...</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && !loading && (
|
||||
<div className="state-container">
|
||||
<IllustratedMessage heading="Error loading folder" description={error}>
|
||||
<sp-icon-alert-circle
|
||||
size="xxl"
|
||||
style={{ color: 'var(--accent-red)' }}
|
||||
></sp-icon-alert-circle>
|
||||
</IllustratedMessage>
|
||||
{currentFolderId && (
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => fetchContents(currentFolderId, debouncedSearch)}
|
||||
style={{ marginTop: '12px' }}
|
||||
>
|
||||
Try Again
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && folders.length === 0 && files.length === 0 && (
|
||||
<div className="state-container">
|
||||
<IllustratedMessage
|
||||
heading={searchTerm ? 'No matching items' : 'Folder is empty'}
|
||||
description={
|
||||
searchTerm
|
||||
? `No files or subfolders match "${searchTerm}".`
|
||||
: 'No files or subfolders found in this directory.'
|
||||
}
|
||||
>
|
||||
<sp-icon-folder-open size="xxl" style={{ color: '#999999' }}></sp-icon-folder-open>
|
||||
</IllustratedMessage>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && (folders.length > 0 || files.length > 0) && (
|
||||
<>
|
||||
{/* Folders Section */}
|
||||
{folders.length > 0 && (
|
||||
<div className="section-container">
|
||||
<div
|
||||
className="section-header"
|
||||
onClick={() => setFoldersExpanded(!foldersExpanded)}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
title={foldersExpanded ? 'Collapse Folders' : 'Expand Folders'}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
setFoldersExpanded(!foldersExpanded)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="section-header-left">
|
||||
<sp-button
|
||||
quiet
|
||||
variant="secondary"
|
||||
size="xs"
|
||||
label={foldersExpanded ? 'Collapse Folders' : 'Expand Folders'}
|
||||
icon-only
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
setFoldersExpanded(!foldersExpanded)
|
||||
}}
|
||||
>
|
||||
{foldersExpanded ? (
|
||||
<sp-icon-chevron-down slot="icon" size="xs"></sp-icon-chevron-down>
|
||||
) : (
|
||||
<sp-icon-chevron-right slot="icon" size="xs"></sp-icon-chevron-right>
|
||||
)}
|
||||
</sp-button>
|
||||
<span className="section-title">Folders</span>
|
||||
<span className="count-badge">{foldersTotal ?? folders.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{foldersExpanded && (
|
||||
<>
|
||||
<div className="file-card-list">
|
||||
{folders.map((folder) => (
|
||||
<FileCardItem
|
||||
key={folder.id}
|
||||
asset={folder}
|
||||
endpoint={endpoint}
|
||||
onClick={() => handleFolderClick(folder)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{foldersHasNext && (
|
||||
<div style={{ display: 'flex', justifyContent: 'center', padding: '6px 0' }}>
|
||||
{loadingMoreFolders ? (
|
||||
<ProgressCircle indeterminate size="s" label="Loading more folders..." />
|
||||
) : (
|
||||
<ActionButton quiet size="s" onClick={fetchNextFoldersPage}>
|
||||
Load more folders
|
||||
</ActionButton>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Files Section */}
|
||||
{files.length > 0 && (
|
||||
<div
|
||||
className="section-container"
|
||||
style={{ marginTop: folders.length > 0 && foldersExpanded ? '14px' : '4px' }}
|
||||
>
|
||||
<div
|
||||
className="section-header"
|
||||
onClick={() => setFilesExpanded(!filesExpanded)}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
title={filesExpanded ? 'Collapse Files' : 'Expand Files'}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault()
|
||||
setFilesExpanded(!filesExpanded)
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="section-header-left">
|
||||
<sp-button
|
||||
quiet
|
||||
variant="secondary"
|
||||
size="xs"
|
||||
label={filesExpanded ? 'Collapse Files' : 'Expand Files'}
|
||||
icon-only
|
||||
onClick={(e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
setFilesExpanded(!filesExpanded)
|
||||
}}
|
||||
>
|
||||
{filesExpanded ? (
|
||||
<sp-icon-chevron-down slot="icon" size="xs"></sp-icon-chevron-down>
|
||||
) : (
|
||||
<sp-icon-chevron-right slot="icon" size="xs"></sp-icon-chevron-right>
|
||||
)}
|
||||
</sp-button>
|
||||
<span className="section-title">Files</span>
|
||||
<span className="count-badge">{filesTotal ?? files.length}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{filesExpanded && (
|
||||
<>
|
||||
<div className="file-card-list">
|
||||
{files.map((file) => (
|
||||
<FileCardItem
|
||||
key={file.id}
|
||||
asset={file}
|
||||
endpoint={endpoint}
|
||||
apiKey={apiKey}
|
||||
onClick={() => {}}
|
||||
onImportRaw={handleImportRaw}
|
||||
onSelectVideoForImport={setVideoForDialog}
|
||||
onLinkSequence={setAssetForLinkDialog}
|
||||
onUnlinkSequence={handleUnlinkAsset}
|
||||
isLinked={Boolean(linkedAssetsMap[file.id])}
|
||||
linkedSequenceName={linkedAssetsMap[file.id]?.sequenceName}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{loadingMoreFiles && (
|
||||
<div style={{ display: 'flex', justifyContent: 'center', padding: '10px 0' }}>
|
||||
<ProgressCircle indeterminate size="s" label="Loading more files..." />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{filesHasNext && !loadingMoreFiles && (
|
||||
<div style={{ display: 'flex', justifyContent: 'center', padding: '6px 0' }}>
|
||||
<ActionButton quiet size="s" onClick={fetchNextFilesPage}>
|
||||
Load more files
|
||||
</ActionButton>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Video Import Modal Dialog */}
|
||||
<ImportVideoDialog
|
||||
asset={videoForDialog}
|
||||
endpoint={endpoint}
|
||||
apiKey={apiKey}
|
||||
isOpen={videoForDialog != null}
|
||||
onClose={() => setVideoForDialog(null)}
|
||||
onImportRaw={handleImportRaw}
|
||||
onImportProxy={handleImportProxy}
|
||||
/>
|
||||
|
||||
{/* Sequence Linking Modal Dialog */}
|
||||
<LinkSequenceDialog
|
||||
asset={assetForLinkDialog}
|
||||
endpoint={endpoint}
|
||||
apiKey={apiKey}
|
||||
isOpen={assetForLinkDialog != null}
|
||||
onClose={() => setAssetForLinkDialog(null)}
|
||||
onLinkSuccess={(newLink, addedCount) => {
|
||||
setLinkedAssetsMap((prev) => ({
|
||||
...prev,
|
||||
[newLink.assetId]: newLink,
|
||||
}))
|
||||
void refreshLinkedAssets()
|
||||
setImportStatus({
|
||||
id: Date.now().toString(),
|
||||
fileName: newLink.assetName,
|
||||
status: 'success',
|
||||
message: `Linked to "${newLink.sequenceName}". Synced ${addedCount} comment ${addedCount === 1 ? 'marker' : 'markers'}.`,
|
||||
})
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Toast Notification for Import Progress & Status */}
|
||||
{importStatus && (
|
||||
<div className={`shumai-import-toast ${importStatus.status}`}>
|
||||
<div className="shumai-toast-left">
|
||||
{importStatus.status === 'importing' && (
|
||||
<ProgressCircle indeterminate size="s" label="Importing..." />
|
||||
)}
|
||||
{importStatus.status === 'success' && <StatusLight variant="positive"></StatusLight>}
|
||||
{importStatus.status === 'error' && <StatusLight variant="negative"></StatusLight>}
|
||||
<div className="shumai-toast-text">
|
||||
<span className="shumai-toast-title">{importStatus.fileName}</span>
|
||||
<span className="shumai-toast-msg">{importStatus.message}</span>
|
||||
</div>
|
||||
</div>
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
onClick={() => setImportStatus(null)}
|
||||
title="Dismiss notification"
|
||||
>
|
||||
×
|
||||
</sp-action-button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { getShumaiClient } from '../api/client'
|
||||
import { ProjectCard } from '../components/ProjectCard'
|
||||
import { Button } from '@swc-react/button'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
import { IllustratedMessage } from '@swc-react/illustrated-message'
|
||||
import { Divider } from '@swc-react/divider'
|
||||
|
||||
export interface ProjectSummary {
|
||||
id: string
|
||||
name: string
|
||||
teamId: string
|
||||
rootFolder?: string | null
|
||||
coverImage?: string | null
|
||||
updatedAt?: string | Date
|
||||
}
|
||||
|
||||
interface ProjectsViewProps {
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
onSelectProject: (project: ProjectSummary) => void
|
||||
}
|
||||
|
||||
export const ProjectsView: React.FC<ProjectsViewProps> = ({
|
||||
endpoint,
|
||||
apiKey,
|
||||
onSelectProject,
|
||||
}) => {
|
||||
const [projects, setProjects] = useState<ProjectSummary[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const fetchProjects = async () => {
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const client = getShumaiClient(endpoint, apiKey)
|
||||
const res = await client.api.projects.$get({
|
||||
query: { first: '200', previewFormat: 'jpeg' },
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
const errData = (await res.json().catch(() => ({}))) as { error?: string }
|
||||
throw new Error(errData.error || `Failed to fetch projects (${res.status})`)
|
||||
}
|
||||
|
||||
const body = await res.json()
|
||||
setProjects((body.data || []) as ProjectSummary[])
|
||||
} catch (err) {
|
||||
console.error('Error fetching projects:', err)
|
||||
setError(err instanceof Error ? err.message : 'Failed to load projects.')
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchProjects()
|
||||
}, [endpoint, apiKey])
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flex: 1,
|
||||
minHeight: 0,
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
{/* Sticky Title Bar */}
|
||||
<div className="view-sticky-header">
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'space-between',
|
||||
marginBottom: '8px',
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '6px' }}>
|
||||
<h2 style={{ fontSize: '13px', fontWeight: 600 }}>Projects</h2>
|
||||
{!loading && <span className="count-badge">{projects.length}</span>}
|
||||
</div>
|
||||
|
||||
<sp-button
|
||||
quiet
|
||||
variant="secondary"
|
||||
size="s"
|
||||
label="Refresh projects"
|
||||
icon-only
|
||||
onClick={fetchProjects}
|
||||
title="Refresh projects"
|
||||
disabled={loading}
|
||||
>
|
||||
<sp-icon-refresh
|
||||
slot="icon"
|
||||
size="s"
|
||||
className={loading ? 'spin' : ''}
|
||||
></sp-icon-refresh>
|
||||
</sp-button>
|
||||
</div>
|
||||
<Divider size="s" />
|
||||
</div>
|
||||
|
||||
<div className="view-content">
|
||||
{loading && (
|
||||
<div className="state-container">
|
||||
<ProgressCircle indeterminate size="m" label="Loading projects..." />
|
||||
<p style={{ marginTop: '8px' }}>Loading projects...</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && !loading && (
|
||||
<div className="state-container">
|
||||
<IllustratedMessage heading="Error loading projects" description={error}>
|
||||
<sp-icon-alert-circle
|
||||
size="xxl"
|
||||
style={{ color: 'var(--accent-red)' }}
|
||||
></sp-icon-alert-circle>
|
||||
</IllustratedMessage>
|
||||
<Button variant="secondary" onClick={fetchProjects} style={{ marginTop: '12px' }}>
|
||||
Try Again
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && projects.length === 0 && (
|
||||
<div className="state-container">
|
||||
<IllustratedMessage
|
||||
heading="No projects found"
|
||||
description="Create a project in your Shumai workspace to get started."
|
||||
>
|
||||
<sp-icon-briefcase size="xxl" style={{ color: '#999999' }}></sp-icon-briefcase>
|
||||
</IllustratedMessage>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!loading && !error && projects.length > 0 && (
|
||||
<div className="project-card-list">
|
||||
{projects.map((project) => (
|
||||
<ProjectCard
|
||||
key={project.id}
|
||||
project={project}
|
||||
endpoint={endpoint}
|
||||
onClick={() => onSelectProject(project)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React, { act } from 'react'
|
||||
import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent, cleanup } from '@testing-library/react'
|
||||
import { SequencesView } from './SequencesView'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import * as premiereService from '../services/premiere'
|
||||
import * as linkStorage from '../services/linkStorage'
|
||||
import * as markersService from '../services/markers'
|
||||
import type { CommentInfo } from '@shumai/dtos'
|
||||
|
||||
// Configure React 19 act environment for happy-dom
|
||||
;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
|
||||
|
||||
describe('SequencesView Component', () => {
|
||||
const mockOnLinkCountChange = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
})
|
||||
|
||||
it('renders unified empty state when no sequences are linked', async () => {
|
||||
const mockSeq = { guid: 'seq-1', name: 'Sequence 01' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(mockSeq as unknown as Sequence)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([mockSeq as unknown as Sequence])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([])
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<SequencesView
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
onLinkCountChange={mockOnLinkCountChange}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
expect(screen.getByText('No Linked Sequences')).toBeDefined()
|
||||
expect(screen.getByText(/Sequence 01/i)).toBeDefined()
|
||||
expect(screen.queryByText('Browse Assets to Link')).toBeNull()
|
||||
})
|
||||
|
||||
it('renders linked sequence card and handles unlink', async () => {
|
||||
const mockSeq = { guid: 'seq-1', name: 'Sequence 01' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
const mockLink = {
|
||||
sequenceGuid: 'seq-1',
|
||||
sequenceName: 'Sequence 01',
|
||||
assetId: 'asset-1',
|
||||
assetName: 'final_edit.mp4',
|
||||
syncedCommentIds: ['comm-1'],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced: 1,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(mockSeq as unknown as Sequence)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([mockSeq as unknown as Sequence])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([mockLink])
|
||||
vi.spyOn(linkStorage, 'removeSequenceLink').mockResolvedValue(true)
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<SequencesView
|
||||
endpoint="https://api.shumai.test"
|
||||
apiKey="test-key"
|
||||
onLinkCountChange={mockOnLinkCountChange}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
expect(screen.getAllByText('Sequence 01').length).toBeGreaterThan(0)
|
||||
expect(screen.getAllByText(/Asset: final_edit.mp4/i).length).toBeGreaterThan(0)
|
||||
|
||||
const unlinkButtons = screen.getAllByTitle('Unlink sequence')
|
||||
expect(unlinkButtons.length).toBeGreaterThan(0)
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.click(unlinkButtons[0])
|
||||
})
|
||||
|
||||
expect(linkStorage.removeSequenceLink).toHaveBeenCalledWith(mockProject, mockSeq)
|
||||
})
|
||||
|
||||
it('filters out foreign endpoint links from the view and link count', async () => {
|
||||
const mockSeq1 = { guid: 'seq-1', name: 'Sequence Foreign' }
|
||||
const mockSeq2 = { guid: 'seq-2', name: 'Sequence Staging' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
const foreignLink = {
|
||||
sequenceGuid: 'seq-1',
|
||||
sequenceName: 'Sequence Foreign',
|
||||
assetId: 'asset-dev',
|
||||
assetName: 'dev_asset.mp4',
|
||||
endpoint: 'http://localhost:3000',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
const stagingLink = {
|
||||
sequenceGuid: 'seq-2',
|
||||
sequenceName: 'Sequence Staging',
|
||||
assetId: 'asset-staging',
|
||||
assetName: 'staging_asset.mp4',
|
||||
endpoint: 'https://staging.shumai.one',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(
|
||||
mockSeq1 as unknown as Sequence,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([
|
||||
mockSeq1 as unknown as Sequence,
|
||||
mockSeq2 as unknown as Sequence,
|
||||
])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([foreignLink, stagingLink])
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<SequencesView
|
||||
endpoint="https://staging.shumai.one"
|
||||
apiKey="staging-key"
|
||||
onLinkCountChange={mockOnLinkCountChange}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
// Foreign link should be completely hidden
|
||||
expect(screen.queryByText('dev_asset.mp4')).toBeNull()
|
||||
expect(screen.queryByText(/Server:/i)).toBeNull()
|
||||
|
||||
// Matching link should be visible
|
||||
expect(screen.getAllByText(/staging_asset.mp4/i).length).toBeGreaterThan(0)
|
||||
|
||||
// Active sequence (seq-1) is linked to foreign server, so current sequence card should show unlinked state
|
||||
expect(screen.getByText('This sequence is not linked to any Shumai asset.')).toBeDefined()
|
||||
|
||||
// Link count reported to parent should only count staging link (1)
|
||||
expect(mockOnLinkCountChange).toHaveBeenCalledWith(1)
|
||||
})
|
||||
|
||||
it('shows error toast when manual sync fails', async () => {
|
||||
const mockSeq = { guid: 'seq-1', name: 'Sequence 01' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
const mockLink = {
|
||||
sequenceGuid: 'seq-1',
|
||||
sequenceName: 'Sequence 01',
|
||||
assetId: 'asset-missing',
|
||||
assetName: 'missing.mp4',
|
||||
endpoint: 'https://staging.shumai.one',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(mockSeq as unknown as Sequence)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([mockSeq as unknown as Sequence])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([mockLink])
|
||||
|
||||
vi.spyOn(markersService, 'fetchAssetComments').mockRejectedValue(
|
||||
new Error('Asset not found on this server (HTTP 404)'),
|
||||
)
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<SequencesView
|
||||
endpoint="https://staging.shumai.one"
|
||||
apiKey="staging-key"
|
||||
onLinkCountChange={mockOnLinkCountChange}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
const syncButtons = screen.getAllByTitle('Sync comments now')
|
||||
expect(syncButtons[0].hasAttribute('disabled')).toBe(false)
|
||||
|
||||
await act(async () => {
|
||||
fireEvent.click(syncButtons[0])
|
||||
})
|
||||
|
||||
expect(markersService.fetchAssetComments).toHaveBeenCalledWith(
|
||||
'https://staging.shumai.one',
|
||||
'staging-key',
|
||||
'asset-missing',
|
||||
)
|
||||
expect(screen.getByText('Asset not found on this server (HTTP 404)')).toBeDefined()
|
||||
})
|
||||
|
||||
it('shows success toast when manual sync succeeds', async () => {
|
||||
const mockSeq = { guid: 'seq-1', name: 'Sequence 01' }
|
||||
const mockProject = { guid: 'proj-1' }
|
||||
const mockLink = {
|
||||
sequenceGuid: 'seq-1',
|
||||
sequenceName: 'Sequence 01',
|
||||
assetId: 'asset-1',
|
||||
assetName: 'final.mp4',
|
||||
endpoint: 'https://staging.shumai.one',
|
||||
syncedCommentIds: [],
|
||||
lastSyncAt: Date.now(),
|
||||
totalCommentsSynced: 0,
|
||||
}
|
||||
|
||||
vi.spyOn(premiereService, 'getActiveProject').mockResolvedValue(
|
||||
mockProject as unknown as Project,
|
||||
)
|
||||
vi.spyOn(premiereService, 'getActiveSequence').mockResolvedValue(mockSeq as unknown as Sequence)
|
||||
vi.spyOn(premiereService, 'getAllSequences').mockResolvedValue([mockSeq as unknown as Sequence])
|
||||
vi.spyOn(linkStorage, 'getAllLinkedSequences').mockResolvedValue([mockLink])
|
||||
|
||||
vi.spyOn(markersService, 'fetchAssetComments').mockResolvedValue([
|
||||
{ id: 'comm-1', second: 10, message: 'Fix color' } as unknown as CommentInfo,
|
||||
])
|
||||
vi.spyOn(markersService, 'syncCommentsToSequence').mockResolvedValue({
|
||||
updatedLink: { ...mockLink, syncedCommentIds: ['comm-1'], totalCommentsSynced: 1 },
|
||||
addedCount: 1,
|
||||
})
|
||||
|
||||
await act(async () => {
|
||||
render(
|
||||
<SequencesView
|
||||
endpoint="https://staging.shumai.one"
|
||||
apiKey="staging-key"
|
||||
onLinkCountChange={mockOnLinkCountChange}
|
||||
/>,
|
||||
)
|
||||
})
|
||||
|
||||
const syncButtons = screen.getAllByTitle('Sync comments now')
|
||||
await act(async () => {
|
||||
fireEvent.click(syncButtons[0])
|
||||
})
|
||||
|
||||
expect(screen.getByText('Synced 1 new comment marker for "Sequence 01".')).toBeDefined()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,524 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react'
|
||||
import type { Project, Sequence } from '@adobe/premierepro'
|
||||
import type { LinkedSequenceAsset } from '../types/link'
|
||||
import {
|
||||
getActiveProject,
|
||||
getActiveSequence,
|
||||
getAllSequences,
|
||||
openSequenceInTimeline,
|
||||
getPremiereModule,
|
||||
} from '../services/premiere'
|
||||
import { getAllLinkedSequences, normalizeGuid, removeSequenceLink } from '../services/linkStorage'
|
||||
import { fetchAssetComments, syncCommentsToSequence } from '../services/markers'
|
||||
import { resolveAssetUrl, isSameEndpoint } from '../utils/url'
|
||||
import { formatDateAgo } from '../utils/date'
|
||||
import { ProgressCircle } from '@swc-react/progress-circle'
|
||||
|
||||
export interface SequencesViewProps {
|
||||
endpoint: string
|
||||
apiKey: string
|
||||
onLinkCountChange?: (count: number) => void
|
||||
}
|
||||
|
||||
export const SequencesView: React.FC<SequencesViewProps> = ({
|
||||
endpoint,
|
||||
apiKey,
|
||||
onLinkCountChange,
|
||||
}) => {
|
||||
const [project, setProject] = useState<Project | null>(null)
|
||||
const [activeSeq, setActiveSeq] = useState<Sequence | null>(null)
|
||||
const [allSeqs, setAllSeqs] = useState<Sequence[]>([])
|
||||
const [linkedSequences, setLinkedSequences] = useState<LinkedSequenceAsset[]>([])
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [syncingGuid, setSyncingGuid] = useState<string | null>(null)
|
||||
const [unlinkingGuid, setUnlinkingGuid] = useState<string | null>(null)
|
||||
const [toast, setToast] = useState<{ type: 'success' | 'error'; message: string } | null>(null)
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
try {
|
||||
const pr = await getActiveProject()
|
||||
setProject(pr)
|
||||
if (!pr) {
|
||||
setActiveSeq(null)
|
||||
setAllSeqs([])
|
||||
setLinkedSequences([])
|
||||
onLinkCountChange?.(0)
|
||||
return
|
||||
}
|
||||
|
||||
const [currentActive, seqsList] = await Promise.all([
|
||||
getActiveSequence(pr),
|
||||
getAllSequences(pr),
|
||||
])
|
||||
|
||||
setActiveSeq(currentActive)
|
||||
setAllSeqs(seqsList)
|
||||
|
||||
const allLinks = await getAllLinkedSequences(pr, seqsList)
|
||||
// Hide foreign links entirely: only show sequences linked to the current endpoint
|
||||
const currentServerLinks = allLinks.filter(
|
||||
(link) => !link.endpoint || isSameEndpoint(link.endpoint, endpoint),
|
||||
)
|
||||
setLinkedSequences(currentServerLinks)
|
||||
onLinkCountChange?.(currentServerLinks.length)
|
||||
} catch (err) {
|
||||
console.error('[SequencesView] Failed to load sequences data:', err)
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [endpoint, onLinkCountChange])
|
||||
|
||||
useEffect(() => {
|
||||
void loadData()
|
||||
|
||||
// Listen for sequence activation events in Premiere Pro
|
||||
const ppro = getPremiereModule()
|
||||
if (ppro?.EventManager && ppro.Constants?.SequenceEvent?.ACTIVATED) {
|
||||
const handleActivated = () => {
|
||||
void loadData()
|
||||
}
|
||||
try {
|
||||
ppro.EventManager.addGlobalEventListener(
|
||||
ppro.Constants.SequenceEvent.ACTIVATED,
|
||||
handleActivated,
|
||||
true,
|
||||
)
|
||||
return () => {
|
||||
try {
|
||||
ppro.EventManager.removeGlobalEventListener(
|
||||
ppro.Constants.SequenceEvent.ACTIVATED,
|
||||
handleActivated,
|
||||
)
|
||||
} catch {
|
||||
// Ignore error on unmount
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn('[SequencesView] Could not add SequenceEvent listener:', err)
|
||||
}
|
||||
}
|
||||
}, [loadData])
|
||||
|
||||
const showToast = (type: 'success' | 'error', message: string, duration = 4000) => {
|
||||
setToast({ type, message })
|
||||
setTimeout(() => {
|
||||
setToast((prev) => (prev?.message === message ? null : prev))
|
||||
}, duration)
|
||||
}
|
||||
|
||||
// Sync Now handler
|
||||
const handleSyncNow = async (link: LinkedSequenceAsset) => {
|
||||
if (!project || syncingGuid) return
|
||||
if (link.endpoint && !isSameEndpoint(link.endpoint, endpoint)) {
|
||||
showToast(
|
||||
'error',
|
||||
`Cannot sync comments: sequence was linked to "${link.endpoint}". Connect to that server to sync.`,
|
||||
5000,
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const targetSeq =
|
||||
allSeqs.find((s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid)) ||
|
||||
(await getAllSequences(project)).find(
|
||||
(s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid),
|
||||
)
|
||||
if (!targetSeq) return
|
||||
|
||||
setSyncingGuid(link.sequenceGuid)
|
||||
try {
|
||||
const comments = await fetchAssetComments(endpoint, apiKey, link.assetId)
|
||||
const { updatedLink, addedCount } = await syncCommentsToSequence(
|
||||
project,
|
||||
targetSeq,
|
||||
comments,
|
||||
link,
|
||||
)
|
||||
|
||||
setLinkedSequences((prev) =>
|
||||
prev.map((item) =>
|
||||
normalizeGuid(item.sequenceGuid) === normalizeGuid(updatedLink.sequenceGuid)
|
||||
? updatedLink
|
||||
: item,
|
||||
),
|
||||
)
|
||||
|
||||
showToast(
|
||||
'success',
|
||||
addedCount > 0
|
||||
? `Synced ${addedCount} new comment ${addedCount === 1 ? 'marker' : 'markers'} for "${link.sequenceName}".`
|
||||
: `All comments are already synced for "${link.sequenceName}".`,
|
||||
)
|
||||
} catch (err) {
|
||||
console.error('[SequencesView] Failed to sync comments:', err)
|
||||
showToast(
|
||||
'error',
|
||||
err instanceof Error ? err.message : 'Failed to sync comments from server.',
|
||||
5000,
|
||||
)
|
||||
} finally {
|
||||
setSyncingGuid(null)
|
||||
}
|
||||
}
|
||||
|
||||
// Unlink handler
|
||||
const handleUnlink = async (link: LinkedSequenceAsset) => {
|
||||
if (!project || unlinkingGuid) return
|
||||
const targetSeq =
|
||||
allSeqs.find((s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid)) ||
|
||||
(await getAllSequences(project)).find(
|
||||
(s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid),
|
||||
)
|
||||
if (!targetSeq) return
|
||||
|
||||
setUnlinkingGuid(link.sequenceGuid)
|
||||
try {
|
||||
await removeSequenceLink(project, targetSeq)
|
||||
setLinkedSequences((prev) => {
|
||||
const next = prev.filter(
|
||||
(item) => normalizeGuid(item.sequenceGuid) !== normalizeGuid(link.sequenceGuid),
|
||||
)
|
||||
onLinkCountChange?.(next.length)
|
||||
return next
|
||||
})
|
||||
showToast('success', `Unlinked "${link.sequenceName}" from "${link.assetName}".`, 3000)
|
||||
} catch (err) {
|
||||
console.error('[SequencesView] Failed to unlink sequence:', err)
|
||||
showToast('error', 'Failed to unlink sequence.', 4000)
|
||||
} finally {
|
||||
setUnlinkingGuid(null)
|
||||
}
|
||||
}
|
||||
|
||||
// Open Sequence in Timeline handler
|
||||
const handleOpenSequence = async (link: LinkedSequenceAsset) => {
|
||||
if (!project) return
|
||||
const targetSeq =
|
||||
allSeqs.find((s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid)) ||
|
||||
(await getAllSequences(project)).find(
|
||||
(s) => normalizeGuid(s.guid) === normalizeGuid(link.sequenceGuid),
|
||||
)
|
||||
if (!targetSeq) return
|
||||
|
||||
await openSequenceInTimeline(targetSeq, project)
|
||||
setActiveSeq(targetSeq)
|
||||
}
|
||||
|
||||
const renderToast = () => {
|
||||
if (!toast) return null
|
||||
const isError = toast.type === 'error'
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
marginBottom: 10,
|
||||
padding: '6px 10px',
|
||||
borderRadius: 4,
|
||||
backgroundColor: isError ? 'rgba(239, 68, 68, 0.15)' : 'rgba(59, 130, 246, 0.15)',
|
||||
border: isError
|
||||
? '1px solid rgba(239, 68, 68, 0.3)'
|
||||
: '1px solid rgba(59, 130, 246, 0.3)',
|
||||
color: isError ? '#f87171' : '#60a5fa',
|
||||
fontSize: 11,
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
}}
|
||||
>
|
||||
{isError ? (
|
||||
<sp-icon-alert-circle
|
||||
size="s"
|
||||
style={{ marginRight: 6, flexShrink: 0 }}
|
||||
></sp-icon-alert-circle>
|
||||
) : (
|
||||
<sp-icon-checkmark-circle
|
||||
size="s"
|
||||
style={{ marginRight: 6, flexShrink: 0 }}
|
||||
></sp-icon-checkmark-circle>
|
||||
)}
|
||||
<span>{toast.message}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<div
|
||||
className="sequences-view-container"
|
||||
style={{ justifyContent: 'center', alignItems: 'center' }}
|
||||
>
|
||||
<ProgressCircle indeterminate size="m" label="Loading sequences..." />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const activeGuidStr = normalizeGuid(activeSeq?.guid)
|
||||
const currentSequenceLink = linkedSequences.find(
|
||||
(item) => normalizeGuid(item.sequenceGuid) === activeGuidStr,
|
||||
)
|
||||
|
||||
if (linkedSequences.length === 0) {
|
||||
return (
|
||||
<div className="sequences-view-container sequences-empty-container">
|
||||
{renderToast()}
|
||||
|
||||
<div className="sequence-empty-state unified-empty">
|
||||
<sp-icon-movie-camera
|
||||
size="xxl"
|
||||
style={{ color: '#60a5fa', opacity: 0.7, marginBottom: 12 }}
|
||||
></sp-icon-movie-camera>
|
||||
<div className="sequence-empty-state-title" style={{ fontSize: 14, marginBottom: 6 }}>
|
||||
No Linked Sequences
|
||||
</div>
|
||||
<div style={{ fontSize: 11, marginBottom: 8, maxWidth: 280, lineHeight: 1.4 }}>
|
||||
{activeSeq
|
||||
? `Active sequence "${activeSeq.name}" is not linked to any Shumai asset.`
|
||||
: 'Open a sequence in Premiere Pro and link it to a Shumai asset.'}
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
fontSize: 11,
|
||||
color: 'var(--text-secondary)',
|
||||
marginBottom: 0,
|
||||
maxWidth: 280,
|
||||
lineHeight: 1.4,
|
||||
}}
|
||||
>
|
||||
Linking a sequence enables automatic synchronization of comments from Shumai as timeline
|
||||
markers.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="sequences-view-container">
|
||||
{/* Toast Notification */}
|
||||
{renderToast()}
|
||||
|
||||
{/* SECTION 1: Current Sequence Asset */}
|
||||
<div className="sequence-section">
|
||||
<div className="sequence-section-title">Current Sequence Asset</div>
|
||||
|
||||
{currentSequenceLink ? (
|
||||
<div className="sequence-link-card current-active">
|
||||
<div className="sequence-card-row">
|
||||
<div className="sequence-card-left">
|
||||
<div className="sequence-card-thumb">
|
||||
{currentSequenceLink.assetThumbnailUrl ? (
|
||||
<img
|
||||
src={resolveAssetUrl(
|
||||
currentSequenceLink.assetThumbnailUrl,
|
||||
currentSequenceLink.endpoint || endpoint,
|
||||
)}
|
||||
alt={currentSequenceLink.assetName}
|
||||
/>
|
||||
) : (
|
||||
<sp-icon-movie-camera
|
||||
size="m"
|
||||
style={{ color: '#3b82f6' }}
|
||||
></sp-icon-movie-camera>
|
||||
)}
|
||||
</div>
|
||||
<div className="sequence-card-info">
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="sequence-card-title">{currentSequenceLink.sequenceName}</span>
|
||||
<span
|
||||
style={{
|
||||
fontSize: '9px',
|
||||
marginLeft: 6,
|
||||
padding: '1px 4px',
|
||||
borderRadius: 3,
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.2)',
|
||||
color: '#60a5fa',
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
Active
|
||||
</span>
|
||||
</div>
|
||||
<span className="sequence-card-subtitle" title={currentSequenceLink.assetName}>
|
||||
Asset: {currentSequenceLink.assetName}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="sequence-card-actions">
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
label="Sync comments now"
|
||||
title="Sync comments now"
|
||||
disabled={syncingGuid === currentSequenceLink.sequenceGuid}
|
||||
onClick={() => handleSyncNow(currentSequenceLink)}
|
||||
>
|
||||
{syncingGuid === currentSequenceLink.sequenceGuid ? (
|
||||
<ProgressCircle indeterminate size="s" slot="icon" label="Syncing..." />
|
||||
) : (
|
||||
<sp-icon-refresh size="s" slot="icon"></sp-icon-refresh>
|
||||
)}
|
||||
</sp-action-button>
|
||||
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
label="Unlink sequence"
|
||||
title="Unlink sequence"
|
||||
disabled={unlinkingGuid === currentSequenceLink.sequenceGuid}
|
||||
onClick={() => handleUnlink(currentSequenceLink)}
|
||||
>
|
||||
{unlinkingGuid === currentSequenceLink.sequenceGuid ? (
|
||||
<ProgressCircle indeterminate size="s" slot="icon" label="Unlinking..." />
|
||||
) : (
|
||||
<sp-icon-unlink
|
||||
size="s"
|
||||
slot="icon"
|
||||
style={{ color: '#f87171' }}
|
||||
></sp-icon-unlink>
|
||||
)}
|
||||
</sp-action-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="sequence-card-footer">
|
||||
<span>
|
||||
{currentSequenceLink.totalCommentsSynced}{' '}
|
||||
{currentSequenceLink.totalCommentsSynced === 1 ? 'comment' : 'comments'} synced
|
||||
</span>
|
||||
<span>Last sync: {formatDateAgo(currentSequenceLink.lastSyncAt) || 'Just now'}</span>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="sequence-empty-state compact">
|
||||
<sp-icon-movie-camera
|
||||
size="l"
|
||||
style={{ color: '#60a5fa', opacity: 0.6, marginBottom: 4 }}
|
||||
></sp-icon-movie-camera>
|
||||
<div className="sequence-empty-state-title">
|
||||
{activeSeq ? activeSeq.name : 'No Active Sequence'}
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: 'var(--text-secondary)', marginBottom: 8 }}>
|
||||
{activeSeq
|
||||
? 'This sequence is not linked to any Shumai asset.'
|
||||
: 'Open a sequence in the timeline to view its linked asset.'}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* SECTION 2: All Sequence Assets */}
|
||||
<div className="sequence-section" style={{ marginTop: 8 }}>
|
||||
<div className="sequence-section-title">All Sequence Assets ({linkedSequences.length})</div>
|
||||
|
||||
{linkedSequences.map((link) => {
|
||||
const isActive = normalizeGuid(link.sequenceGuid) === activeGuidStr
|
||||
const isSyncing = syncingGuid === link.sequenceGuid
|
||||
const isUnlinking = unlinkingGuid === link.sequenceGuid
|
||||
|
||||
return (
|
||||
<div
|
||||
key={link.sequenceGuid}
|
||||
className={`sequence-link-card ${isActive ? 'current-active' : ''}`}
|
||||
>
|
||||
<div className="sequence-card-row">
|
||||
<div className="sequence-card-left">
|
||||
<div className="sequence-card-thumb">
|
||||
{link.assetThumbnailUrl ? (
|
||||
<img
|
||||
src={resolveAssetUrl(link.assetThumbnailUrl, link.endpoint || endpoint)}
|
||||
alt={link.assetName}
|
||||
/>
|
||||
) : (
|
||||
<sp-icon-movie-camera
|
||||
size="m"
|
||||
style={{ color: '#60a5fa' }}
|
||||
></sp-icon-movie-camera>
|
||||
)}
|
||||
</div>
|
||||
<div className="sequence-card-info">
|
||||
<div style={{ display: 'flex', alignItems: 'center' }}>
|
||||
<span className="sequence-card-title">{link.sequenceName}</span>
|
||||
{isActive && (
|
||||
<span
|
||||
style={{
|
||||
fontSize: '9px',
|
||||
marginLeft: 6,
|
||||
padding: '1px 4px',
|
||||
borderRadius: 3,
|
||||
backgroundColor: 'rgba(59, 130, 246, 0.2)',
|
||||
color: '#60a5fa',
|
||||
fontWeight: 600,
|
||||
}}
|
||||
>
|
||||
Active
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="sequence-card-subtitle" title={link.assetName}>
|
||||
Asset: {link.assetName}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="sequence-card-actions">
|
||||
{!isActive && (
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
label="Open sequence in timeline"
|
||||
title="Open sequence in timeline"
|
||||
onClick={() => handleOpenSequence(link)}
|
||||
>
|
||||
<sp-icon-link-out size="s" slot="icon"></sp-icon-link-out>
|
||||
</sp-action-button>
|
||||
)}
|
||||
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
label="Sync comments now"
|
||||
title="Sync comments now"
|
||||
disabled={isSyncing}
|
||||
onClick={() => handleSyncNow(link)}
|
||||
>
|
||||
{isSyncing ? (
|
||||
<ProgressCircle indeterminate size="s" slot="icon" label="Syncing..." />
|
||||
) : (
|
||||
<sp-icon-refresh size="s" slot="icon"></sp-icon-refresh>
|
||||
)}
|
||||
</sp-action-button>
|
||||
|
||||
<sp-action-button
|
||||
quiet
|
||||
size="xs"
|
||||
label="Unlink sequence"
|
||||
title="Unlink sequence"
|
||||
disabled={isUnlinking}
|
||||
onClick={() => handleUnlink(link)}
|
||||
>
|
||||
{isUnlinking ? (
|
||||
<ProgressCircle indeterminate size="s" slot="icon" label="Unlinking..." />
|
||||
) : (
|
||||
<sp-icon-unlink
|
||||
size="s"
|
||||
slot="icon"
|
||||
style={{ color: '#f87171' }}
|
||||
></sp-icon-unlink>
|
||||
)}
|
||||
</sp-action-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="sequence-card-footer">
|
||||
<span>
|
||||
{link.totalCommentsSynced}{' '}
|
||||
{link.totalCommentsSynced === 1 ? 'comment' : 'comments'} synced
|
||||
</span>
|
||||
<span>Last sync: {formatDateAgo(link.lastSyncAt) || 'Just now'}</span>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react",
|
||||
"types": ["bun", "node", "@adobe/premierepro"]
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@shumai/transcode-app",
|
||||
"version": "0.2.2",
|
||||
"version": "0.5.2",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"bin": {
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
# Web App E2E Tests
|
||||
|
||||
Fullstack end-to-end tests for the Shumai web app. They run against a real backend
|
||||
(pgvector container + local S3 storage) served on `http://localhost:5200` and are
|
||||
executed with Playwright via `bun run test:e2e:app`.
|
||||
|
||||
## Structure
|
||||
|
||||
```
|
||||
apps/web/e2e/
|
||||
├── fixtures.ts # prisma / owner / project / file fixtures
|
||||
├── serve.ts # starts the test DB container + web app
|
||||
├── global-teardown.ts # stops the container and cleans up storage
|
||||
├── helpers/
|
||||
│ ├── auth.ts # signup / auth-state injection helpers
|
||||
│ ├── project.ts # project creation helpers
|
||||
│ ├── files.ts # share link API helpers
|
||||
│ ├── team.ts # team member seeding helpers
|
||||
│ └── ui.ts # common UI flows (signup, login, members dialog)
|
||||
└── tests/<domain>/ # domain-scoped specs (auth, team, project)
|
||||
```
|
||||
|
||||
## Fixtures
|
||||
|
||||
- `prisma` — auto fixture that truncates all tables before each test. Also the
|
||||
direct way to read/write DB state for assertions and seeding.
|
||||
- `owner` — an authenticated team owner (seeded through the API), with the session
|
||||
cookie and auth state injected into the browser context, opened on the team page.
|
||||
- `project` — `owner` plus a project created through the API (`projectId`,
|
||||
`projectName`).
|
||||
- `file` — `project` plus a seeded processed file asset in the project root
|
||||
(`fileId`, `fileName`). The media kind is configurable per test via
|
||||
`fileOptions` (default `binary`):
|
||||
|
||||
```ts
|
||||
// default binary file (no extension, no proxy)
|
||||
test('...', async ({ file }) => {})
|
||||
|
||||
// type-scoped file for future viewer/transcode tests
|
||||
test('...', { fileOptions: { mediaType: 'image' } }, async ({ file }) => {})
|
||||
```
|
||||
|
||||
| mediaType | filename | notes |
|
||||
|---|---|---|
|
||||
| `binary` (default) | `test-file-<ts>` | never transcoded, no proxy |
|
||||
| `text` | `test-file-<ts>.txt` | gets a PDF proxy in real usage |
|
||||
| `image` | `test-file-<ts>.png` | |
|
||||
| `video` | `test-file-<ts>.mp4` | |
|
||||
| `pdf` | `test-file-<ts>.pdf` | |
|
||||
| `audio` | `test-file-<ts>.wav` | |
|
||||
|
||||
## Test Cases
|
||||
|
||||
### auth
|
||||
| Test | File |
|
||||
|---|---|
|
||||
| Sign up as the first user and become the team owner | `tests/auth/signup.spec.ts` |
|
||||
| Log in with existing credentials | `tests/auth/login.spec.ts` |
|
||||
| Show error when accessing reset-password page without token | `tests/auth/reset-password.spec.ts` |
|
||||
| Reset password with valid token and allow logging in with new password | `tests/auth/reset-password.spec.ts` |
|
||||
|
||||
### team
|
||||
| Test | File |
|
||||
|---|---|
|
||||
| Owner invites a member via invite link and the invitee joins | `tests/team/invite-member.spec.ts` |
|
||||
| Owner removes a member via the members dialog; the membership is deleted from the DB | `tests/team/remove-member.spec.ts` |
|
||||
| Owner changes a team member role in the members dialog and permissions update | `tests/team/change-member-role.spec.ts` |
|
||||
| Owner manages resource quotas in settings and resets usage from the dashboard | `tests/team/quotas-settings.spec.ts` |
|
||||
|
||||
### project
|
||||
| Test | File |
|
||||
|---|---|
|
||||
| Owner creates a project with a cover image | `tests/project/create-project.spec.ts` |
|
||||
| Owner uploads a file or an unsupported file via the "Upload File" context menu action | `tests/project/upload-file.spec.ts` |
|
||||
| Owner deletes a file, finds it in recently deleted, and restores it | `tests/project/delete-restore.spec.ts` |
|
||||
| Owner deletes a folder and still sees its contents preview and countdown in recently deleted | `tests/project/delete-restore.spec.ts` |
|
||||
| Owner deletes a version stack and restores it from recently deleted | `tests/project/delete-restore.spec.ts` |
|
||||
| Owner creates a share link from a file context menu and lands on the share page | `tests/project/create-share-link.spec.ts` |
|
||||
| Owner protects a share with a password; guests must enter it to view | `tests/project/share-password.spec.ts` |
|
||||
| Owner creates a collection from the sidebar; the collection shows project files | `tests/project/create-collection.spec.ts` |
|
||||
| Owner invites a member to a project; the member only sees the invited project | `tests/project/invite-member.spec.ts` |
|
||||
| Owner changes a project member role in the members dialog and permissions update | `tests/project/change-member-role.spec.ts` |
|
||||
| Owner adds team member to project with role override and permissions enforce project role | `tests/project/role-override.spec.ts` |
|
||||
| Owner deletes a member from project via the members dialog and project access is revoked | `tests/project/remove-member.spec.ts` |
|
||||
| Owner drags a file into a folder and a folder into another folder | `tests/project/move-folder-file.spec.ts` |
|
||||
| Owner drags a file onto a file to create a version stack | `tests/project/version-stack-create.spec.ts` |
|
||||
| Owner drags a file onto a version stack to add a new version | `tests/project/version-stack-add-version.spec.ts` |
|
||||
| Owner manages version stack: removes version from 3-version stack | `tests/project/version-stack-manage.spec.ts` |
|
||||
| Owner removes version from 2-version stack which dissolves into standalone files | `tests/project/version-stack-manage.spec.ts` |
|
||||
| Dissolving a shared version stack renders the remaining standalone file name on the share page | `tests/project/version-stack-manage.spec.ts` |
|
||||
| Moving a shared file into a shared version stack leaves only 1 stack card on the share page | `tests/project/version-stack-manage.spec.ts` |
|
||||
| Owner searches the file list by an English name keyword | `tests/project/search-file-list.spec.ts` |
|
||||
| Owner searches the file list by Chinese, Japanese, and Korean name keywords | `tests/project/search-file-list.spec.ts` |
|
||||
| Owner searches the file list with a keyword and a filter condition | `tests/project/search-file-list.spec.ts` |
|
||||
| Owner saves a search result as a collection | `tests/project/save-search-collection.spec.ts` |
|
||||
| Image share with watermark + download disabled: no download buttons on public list/detail pages, watermarked proxy served, download-url rejected | `tests/project/share-watermark-no-download.spec.ts` |
|
||||
| Video share with watermark + download disabled: no download buttons on public list/detail pages, watermarked proxy served, download-url rejected | `tests/project/share-watermark-no-download.spec.ts` |
|
||||
| Owner views a file and it appears in recents | `tests/project/recents.spec.ts` |
|
||||
|
||||
### file
|
||||
| Test | File |
|
||||
|---|---|
|
||||
| Create a comment on a binary file | `tests/file/binary-comment.spec.ts` |
|
||||
| Upload a txt file, wait for transcode, and create a comment with draw | `tests/file/txt-draw-comment.spec.ts` |
|
||||
| Upload an image file, wait for transcode, and create a comment with draw | `tests/file/image-draw-comment.spec.ts` |
|
||||
| Upload a video file, wait for transcode, and create a comment with draw at a non-zero timestamp | `tests/file/video-draw-comment.spec.ts` |
|
||||
| Upload an audio file, wait for transcode, and create a comment at a non-zero timestamp | `tests/file/audio-timestamp-comment.spec.ts` |
|
||||
| Show a breathing poster preview and "Preparing..." while a video is still transcoding | `tests/file/processing-preview.spec.ts` |
|
||||
| Show a preparing circle before the poster is generated | `tests/file/processing-preview.spec.ts` |
|
||||
|
||||
## Conventions
|
||||
|
||||
|
||||
- Seed data via fixtures/API/DB; use the UI only for the flow under test.
|
||||
- Each test truncates all tables via the auto `prisma` fixture, so fixtures must
|
||||
create their data per-test.
|
||||
- App projects run with `workers: 1` because all tests share a single database.
|
||||
- Every new test case MUST be documented in this README.
|
||||
+153
-12
@@ -1,31 +1,114 @@
|
||||
import { test as base } from '@playwright/test'
|
||||
import type { BrowserContext, Page } from '@playwright/test'
|
||||
import { PrismaClient } from '../../../packages/db/src/generated/prisma/client'
|
||||
import { PrismaPg } from '@prisma/adapter-pg'
|
||||
import { Pool } from 'pg'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import {
|
||||
E2E_APP_URL,
|
||||
E2E_PASSWORD,
|
||||
apiSignup,
|
||||
injectAuthState,
|
||||
resolveTeamId,
|
||||
uniqueEmail,
|
||||
} from './helpers/auth'
|
||||
import { apiCreateProject, uniqueProjectName } from './helpers/project'
|
||||
import { apiUploadFile } from './helpers/files'
|
||||
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
||||
const envPath = path.resolve(currentDir, '.env.e2e')
|
||||
const fixturesDir = path.resolve(currentDir, '../../../packages/e2e/fixtures')
|
||||
|
||||
// Load E2E environment variables if present
|
||||
if (fs.existsSync(envPath)) {
|
||||
const content = fs.readFileSync(envPath, 'utf8')
|
||||
content.split('\n').forEach((line) => {
|
||||
const parts = line.split('=')
|
||||
if (parts.length >= 2) {
|
||||
const key = parts[0].trim()
|
||||
const value = parts.slice(1).join('=').trim()
|
||||
process.env[key] = value
|
||||
}
|
||||
})
|
||||
function loadEnv() {
|
||||
if (fs.existsSync(envPath)) {
|
||||
const content = fs.readFileSync(envPath, 'utf8')
|
||||
content.split('\n').forEach((line) => {
|
||||
const parts = line.split('=')
|
||||
if (parts.length >= 2) {
|
||||
const key = parts[0].trim()
|
||||
const value = parts.slice(1).join('=').trim()
|
||||
process.env[key] = value
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const test = base.extend<{ prisma: PrismaClient }>({
|
||||
// Load E2E environment variables if present
|
||||
loadEnv()
|
||||
|
||||
export interface OwnerFixture {
|
||||
/** Page opened in a browser context logged in as the team owner. */
|
||||
page: Page
|
||||
context: BrowserContext
|
||||
teamId: string
|
||||
email: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export interface ProjectFixture extends OwnerFixture {
|
||||
projectId: string
|
||||
projectName: string
|
||||
/** The project's root folder asset id. */
|
||||
rootFolderId: string
|
||||
}
|
||||
|
||||
/** The media kind of a seeded test file. */
|
||||
export type FileMediaType = 'text' | 'binary' | 'image' | 'video' | 'pdf' | 'audio'
|
||||
|
||||
export interface FileFixtureOptions {
|
||||
/** Defaults to `binary` (no extension, never transcoded, no proxy). */
|
||||
mediaType?: FileMediaType
|
||||
}
|
||||
|
||||
export interface FileFixture extends ProjectFixture {
|
||||
fileId: string
|
||||
fileName: string
|
||||
fileMediaType: FileMediaType
|
||||
}
|
||||
|
||||
const FILE_TYPE_MAP: Record<FileMediaType, { ext: string; mime: string }> = {
|
||||
text: { ext: 'txt', mime: 'text/plain' },
|
||||
binary: { ext: '', mime: 'application/octet-stream' },
|
||||
image: { ext: 'png', mime: 'image/png' },
|
||||
video: { ext: 'mp4', mime: 'video/mp4' },
|
||||
pdf: { ext: 'pdf', mime: 'application/pdf' },
|
||||
audio: { ext: 'wav', mime: 'audio/wav' },
|
||||
}
|
||||
|
||||
function getFileBuffer(mediaType: FileMediaType): Buffer {
|
||||
switch (mediaType) {
|
||||
case 'image':
|
||||
return fs.readFileSync(path.join(fixturesDir, 'small.png'))
|
||||
case 'video':
|
||||
return fs.readFileSync(path.join(fixturesDir, 'small.mp4'))
|
||||
case 'audio':
|
||||
return fs.readFileSync(path.join(fixturesDir, 'small.wav'))
|
||||
case 'pdf':
|
||||
return fs.readFileSync(path.join(fixturesDir, 'test.pdf'))
|
||||
case 'text':
|
||||
return Buffer.from(
|
||||
'Sample text content for PDF proxy transcode test.\nSecond line of text content.',
|
||||
)
|
||||
case 'binary':
|
||||
default:
|
||||
return Buffer.from('binary-file-content-sample')
|
||||
}
|
||||
}
|
||||
|
||||
export const test = base.extend<{
|
||||
prisma: PrismaClient
|
||||
owner: OwnerFixture
|
||||
project: ProjectFixture
|
||||
fileOptions: FileFixtureOptions
|
||||
file: FileFixture
|
||||
}>({
|
||||
fileOptions: [{ mediaType: 'binary' }, { option: true }],
|
||||
prisma: [
|
||||
// eslint-disable-next-line no-empty-pattern
|
||||
async ({}, use) => {
|
||||
loadEnv()
|
||||
const connectionString = process.env.DATABASE_URL
|
||||
const pool = new Pool({ connectionString })
|
||||
const adapter = new PrismaPg(pool)
|
||||
@@ -51,6 +134,64 @@ export const test = base.extend<{ prisma: PrismaClient }>({
|
||||
},
|
||||
{ auto: true },
|
||||
],
|
||||
/**
|
||||
* Sets up an authenticated team owner through the API (fast, no UI): creates
|
||||
* the user, stores the session cookie in the browser context, injects the
|
||||
* persisted auth state, and opens the team page.
|
||||
*/
|
||||
owner: async ({ browser }, use) => {
|
||||
const context = await browser.newContext({
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
baseURL: E2E_APP_URL,
|
||||
})
|
||||
const email = uniqueEmail('owner')
|
||||
const password = E2E_PASSWORD
|
||||
try {
|
||||
// Create the owner via the API so the session cookie lands in the context
|
||||
const user = await apiSignup(context.request, email, password)
|
||||
await injectAuthState(context, user)
|
||||
const teamId = await resolveTeamId(context.request)
|
||||
|
||||
// Open the app already logged in on the team page
|
||||
const page = await context.newPage()
|
||||
await page.goto(`/teams/${teamId}`)
|
||||
|
||||
await use({ page, context, teamId, email, password })
|
||||
} finally {
|
||||
await context.close()
|
||||
}
|
||||
},
|
||||
/** Sets up an authenticated team owner plus a project created via the API. */
|
||||
project: async ({ owner, prisma }, use) => {
|
||||
const name = uniqueProjectName()
|
||||
const project = await apiCreateProject(owner.context.request, owner.teamId, name)
|
||||
const projectRow = await prisma.project.findUnique({ where: { id: project.id } })
|
||||
const rootFolderId = projectRow?.rootFolderId
|
||||
if (!rootFolderId) throw new Error('Project has no root folder')
|
||||
await use({ ...owner, projectId: project.id, projectName: name, rootFolderId })
|
||||
},
|
||||
/**
|
||||
* Sets up an owner + project with an uploaded file asset under the
|
||||
* project root folder via the API upload task endpoints. The media type is configurable per test via
|
||||
* `fileOptions` (defaults to `binary`).
|
||||
*/
|
||||
file: async ({ project, fileOptions }, use) => {
|
||||
const mediaType: FileMediaType = fileOptions.mediaType ?? 'binary'
|
||||
const { ext, mime } = FILE_TYPE_MAP[mediaType]
|
||||
const fileName = `test-file-${Date.now()}${ext ? `.${ext}` : ''}`
|
||||
const buffer = getFileBuffer(mediaType)
|
||||
|
||||
const uploaded = await apiUploadFile(
|
||||
project.context.request,
|
||||
project.teamId,
|
||||
project.rootFolderId,
|
||||
fileName,
|
||||
mime,
|
||||
buffer,
|
||||
)
|
||||
|
||||
await use({ ...project, fileId: uploaded.fileId, fileName, fileMediaType: mediaType })
|
||||
},
|
||||
})
|
||||
|
||||
export { expect } from '@playwright/test'
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import type { PrismaClient } from '../../../../packages/db/src/generated/prisma/client'
|
||||
|
||||
/**
|
||||
* Seeds a folder asset directly through the database (fast, no UI). The folder
|
||||
* is placed under `parentId` (usually a project's root folder).
|
||||
*/
|
||||
export async function seedFolder(
|
||||
prisma: PrismaClient,
|
||||
projectId: string,
|
||||
parentId: string,
|
||||
name: string,
|
||||
) {
|
||||
return prisma.asset.create({
|
||||
data: { name, type: 'folder', status: 'processed', projectId, parentId },
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds a processed file asset directly through the database (fast, no UI).
|
||||
* The file is placed under `parentId` (a folder or a version stack).
|
||||
*/
|
||||
export async function seedFile(
|
||||
prisma: PrismaClient,
|
||||
projectId: string,
|
||||
parentId: string,
|
||||
name: string,
|
||||
) {
|
||||
return prisma.asset.create({
|
||||
data: { name, type: 'file', status: 'processed', sizeByte: 10, projectId, parentId },
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import type { APIRequestContext, BrowserContext } from '@playwright/test'
|
||||
|
||||
/** Base URL of the fullstack app under test (must match playwright.config.ts). */
|
||||
export const E2E_APP_URL = process.env.E2E_APP_URL || 'http://localhost:5200'
|
||||
|
||||
export const E2E_PASSWORD = 'Password123!'
|
||||
|
||||
export function uniqueEmail(prefix = 'user'): string {
|
||||
return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}@shumai.local`
|
||||
}
|
||||
|
||||
export interface AuthUser {
|
||||
id: string
|
||||
email: string
|
||||
name: string
|
||||
}
|
||||
|
||||
interface SignupResponse {
|
||||
token?: string | null
|
||||
user?: AuthUser
|
||||
error?: { message?: string } | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a user through the better-auth API.
|
||||
* When passed a `context.request`, the session cookie is stored in the browser
|
||||
* context and the user is logged in.
|
||||
*/
|
||||
export async function apiSignup(
|
||||
request: APIRequestContext,
|
||||
email: string,
|
||||
password: string,
|
||||
options: { inviteCode?: string } = {},
|
||||
): Promise<AuthUser> {
|
||||
const res = await request.post('/api/auth/sign-up/email', {
|
||||
data: {
|
||||
name: email,
|
||||
email,
|
||||
password,
|
||||
...(options.inviteCode ? { inviteCode: options.inviteCode } : {}),
|
||||
},
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`Signup API failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
const body = (await res.json()) as SignupResponse
|
||||
if (!body.user) {
|
||||
throw new Error(`Signup API returned no user: ${JSON.stringify(body)}`)
|
||||
}
|
||||
return body.user
|
||||
}
|
||||
|
||||
/**
|
||||
* Injects the persisted auth state (zustand `auth-storage`) so the app
|
||||
* considers the session logged in. The session cookie must already be present
|
||||
* in the context (created via `context.request`).
|
||||
*/
|
||||
export async function injectAuthState(context: BrowserContext, user: AuthUser): Promise<void> {
|
||||
await context.addInitScript((u) => {
|
||||
localStorage.setItem('auth-storage', JSON.stringify({ state: { user: u }, version: 0 }))
|
||||
}, user)
|
||||
}
|
||||
|
||||
/** Resolves the id of the first team for the authenticated request context. */
|
||||
export async function resolveTeamId(request: APIRequestContext): Promise<string> {
|
||||
const res = await request.get('/api/teams')
|
||||
if (!res.ok()) {
|
||||
throw new Error(`GET /api/teams failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
const body = (await res.json()) as { data: { id: string }[] }
|
||||
const teamId = body.data?.[0]?.id
|
||||
if (!teamId) {
|
||||
throw new Error(`No team found in /api/teams response: ${JSON.stringify(body)}`)
|
||||
}
|
||||
return teamId
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import type { Locator, Page } from '@playwright/test'
|
||||
|
||||
/**
|
||||
* Performs a pointer drag from one card to another. dnd-kit v6 uses a
|
||||
* `PointerSensor` with a 10px distance activation constraint, and WebKit only
|
||||
* reliably starts the drag when pointer moves are delivered in separate,
|
||||
* awaited batches (a single fast `mouse.move(steps)` can be coalesced before
|
||||
* the drag activates, losing the drop). Moves are therefore chunked with
|
||||
* intermediate waits so the activation and drag move handlers run between
|
||||
* batches on every browser.
|
||||
*/
|
||||
export async function dragCard(page: Page, source: Locator, target: Locator): Promise<void> {
|
||||
const sourceBox = (await source.boundingBox())!
|
||||
const targetBox = (await target.boundingBox())!
|
||||
if (!sourceBox || !targetBox) {
|
||||
throw new Error('Drag source or target has no bounding box')
|
||||
}
|
||||
|
||||
const fromX = sourceBox.x + sourceBox.width / 2
|
||||
const fromY = sourceBox.y + sourceBox.height / 2
|
||||
const toX = targetBox.x + targetBox.width / 2
|
||||
const toY = targetBox.y + targetBox.height / 2
|
||||
|
||||
await page.mouse.move(fromX, fromY)
|
||||
await page.mouse.down()
|
||||
|
||||
const dx = toX - fromX
|
||||
const dy = toY - fromY
|
||||
const dist = Math.hypot(dx, dy)
|
||||
|
||||
// Step past the 10px activation constraint to trigger drag activation
|
||||
// and give the browser a brief moment for status to become 'dragging'
|
||||
const activationRatio = dist > 0 ? Math.min(1, 15 / dist) : 1
|
||||
await page.mouse.move(fromX + dx * activationRatio, fromY + dy * activationRatio)
|
||||
await page.waitForTimeout(50)
|
||||
|
||||
// Move in several chunks so the intermediate dragmove handlers run
|
||||
const chunks = 8
|
||||
for (let i = 1; i <= chunks; i++) {
|
||||
const x = fromX + (dx * i) / chunks
|
||||
const y = fromY + (dy * i) / chunks
|
||||
await page.mouse.move(x, y)
|
||||
await page.waitForTimeout(20)
|
||||
}
|
||||
|
||||
// Ensure pointer is directly over target center and allow requestAnimationFrame
|
||||
// and collision microtasks to settle before triggering drop
|
||||
await page.mouse.move(toX, toY)
|
||||
await page.evaluate(
|
||||
() => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))),
|
||||
)
|
||||
await page.waitForTimeout(100)
|
||||
|
||||
await page.mouse.up()
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
import type { APIRequestContext, Locator, Page } from '@playwright/test'
|
||||
|
||||
interface CreateShareResponse {
|
||||
id?: string
|
||||
name?: string
|
||||
rootFolderId?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates a file/folder card by its name. Matches both read-only text nodes
|
||||
* and active EditableText inputs. The returned locator points at the card
|
||||
* wrapper div (right-clickable to open the card context menu).
|
||||
*/
|
||||
export function fileCard(page: Page, name: string): Locator {
|
||||
return page
|
||||
.locator('[data-testid="file-card"]')
|
||||
.filter({
|
||||
has: page.locator(`input[value="${name}"]`).or(page.getByText(name, { exact: true })),
|
||||
})
|
||||
.first()
|
||||
}
|
||||
|
||||
/** Creates a share link through the API for the authenticated request context. */
|
||||
export async function apiCreateShare(
|
||||
request: APIRequestContext,
|
||||
projectId: string,
|
||||
name: string,
|
||||
): Promise<{ id: string; name: string; rootFolderId: string }> {
|
||||
const res = await request.post(`/api/projects/${projectId}/shares`, {
|
||||
data: { name },
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`Create share API failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
const body = (await res.json()) as CreateShareResponse
|
||||
if (!body.id || !body.name || !body.rootFolderId) {
|
||||
throw new Error(`Create share returned an unexpected response: ${JSON.stringify(body)}`)
|
||||
}
|
||||
return { id: body.id, name: body.name, rootFolderId: body.rootFolderId }
|
||||
}
|
||||
|
||||
/** Adds assets to a share link through the API. */
|
||||
export async function apiAddAssetsToShare(
|
||||
request: APIRequestContext,
|
||||
shareId: string,
|
||||
assetIds: string[],
|
||||
): Promise<void> {
|
||||
const res = await request.post(`/api/shares/${shareId}/assets`, {
|
||||
data: { assetIds },
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`Add assets to share API failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
}
|
||||
|
||||
/** Updates share link settings (e.g. `allowDownload`) through the API. */
|
||||
export async function apiUpdateShare(
|
||||
request: APIRequestContext,
|
||||
shareId: string,
|
||||
patch: { allowDownload?: boolean },
|
||||
): Promise<void> {
|
||||
const res = await request.put(`/api/shares/${shareId}`, { data: patch })
|
||||
if (!res.ok()) {
|
||||
throw new Error(`Update share API failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables a text watermark on the share link through the API. Uses the same
|
||||
* default block shape the watermark editor produces (a "CONFIDENTIAL" text
|
||||
* block), so the transcode workflow runs against a realistic config.
|
||||
*/
|
||||
export async function apiEnableShareWatermark(
|
||||
request: APIRequestContext,
|
||||
shareId: string,
|
||||
): Promise<void> {
|
||||
const res = await request.put(`/api/shares/${shareId}/watermark`, {
|
||||
data: {
|
||||
enabled: true,
|
||||
config: {
|
||||
blocks: [
|
||||
{
|
||||
id: `wm-${Date.now()}`,
|
||||
type: 'text',
|
||||
text: 'CONFIDENTIAL',
|
||||
x: 0.5,
|
||||
y: 0.5,
|
||||
// size is a fraction (0..1) of the canvas width
|
||||
size: 0.05,
|
||||
color: '#999999',
|
||||
opacity: 0.5,
|
||||
rotation: -30,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`Enable share watermark API failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
}
|
||||
|
||||
/** Requests a public download URL. Returns status + body for assertions. */
|
||||
export async function apiPublicDownloadUrl(
|
||||
request: APIRequestContext,
|
||||
shareId: string,
|
||||
fileId: string,
|
||||
key: string,
|
||||
): Promise<{ status: number; body: unknown }> {
|
||||
const res = await request.post(`/api/shares/${shareId}/files/${fileId}/download-url`, {
|
||||
data: { key },
|
||||
})
|
||||
return { status: res.status(), body: await res.json().catch(() => null) }
|
||||
}
|
||||
|
||||
/** Uploads a file asset through the official API upload task endpoints. */
|
||||
export async function apiUploadFile(
|
||||
request: APIRequestContext,
|
||||
teamId: string,
|
||||
parentId: string,
|
||||
fileName: string,
|
||||
mimeType: string,
|
||||
buffer: Buffer,
|
||||
): Promise<{ fileId: string; fileName: string }> {
|
||||
const tempId = `temp-${Date.now()}`
|
||||
const createRes = await request.post(`/api/teams/${teamId}/upload/tasks`, {
|
||||
data: {
|
||||
parentId,
|
||||
files: [
|
||||
{
|
||||
id: tempId,
|
||||
name: fileName,
|
||||
type: 'file',
|
||||
size: buffer.length,
|
||||
mediaType: mimeType,
|
||||
children: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
if (!createRes.ok()) {
|
||||
throw new Error(`Create upload task failed (${createRes.status()}): ${await createRes.text()}`)
|
||||
}
|
||||
const taskData = (await createRes.json()) as {
|
||||
taskId: string
|
||||
presignedUrls: Array<{ id: string; fileId: string; url: string }>
|
||||
createdAssets?: Array<{ tempId: string; assetId: string }>
|
||||
}
|
||||
const presigned = taskData.presignedUrls.find((p) => p.id === tempId)
|
||||
const createdAssetId =
|
||||
taskData.createdAssets?.find((c) => c.tempId === tempId)?.assetId || presigned?.fileId
|
||||
if (!presigned || !createdAssetId) {
|
||||
throw new Error('Create upload task did not return presigned URL or asset ID')
|
||||
}
|
||||
|
||||
// Upload file buffer to presigned URL
|
||||
const uploadRes = await request.put(presigned.url, {
|
||||
headers: {
|
||||
'Content-Type': mimeType,
|
||||
},
|
||||
data: buffer,
|
||||
})
|
||||
if (!uploadRes.ok()) {
|
||||
throw new Error(
|
||||
`Upload to S3 presigned URL failed (${uploadRes.status()}): ${await uploadRes.text()}`,
|
||||
)
|
||||
}
|
||||
|
||||
// Confirm upload task
|
||||
const confirmRes = await request.patch(`/api/teams/${teamId}/upload/tasks/${taskData.taskId}`, {
|
||||
data: {
|
||||
fileId: createdAssetId,
|
||||
status: 'success',
|
||||
},
|
||||
})
|
||||
if (!confirmRes.ok()) {
|
||||
throw new Error(
|
||||
`Confirm upload task failed (${confirmRes.status()}): ${await confirmRes.text()}`,
|
||||
)
|
||||
}
|
||||
|
||||
return { fileId: createdAssetId, fileName }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { APIRequestContext } from '@playwright/test'
|
||||
|
||||
export function uniqueProjectName(): string {
|
||||
return `Project ${Date.now()}-${Math.random().toString(36).slice(2, 6)}`
|
||||
}
|
||||
|
||||
interface CreateProjectResponse {
|
||||
id?: string
|
||||
name?: string
|
||||
}
|
||||
|
||||
/** Creates a project through the API for the authenticated request context. */
|
||||
export async function apiCreateProject(
|
||||
request: APIRequestContext,
|
||||
teamId: string,
|
||||
name: string,
|
||||
): Promise<{ id: string; name: string }> {
|
||||
const res = await request.post(`/api/teams/${teamId}/projects`, {
|
||||
data: { name },
|
||||
})
|
||||
if (!res.ok()) {
|
||||
throw new Error(`Create project API failed (${res.status()}): ${await res.text()}`)
|
||||
}
|
||||
const body = (await res.json()) as CreateProjectResponse
|
||||
if (!body.id || !body.name) {
|
||||
throw new Error(`Create project returned an unexpected response: ${JSON.stringify(body)}`)
|
||||
}
|
||||
return { id: body.id, name: body.name }
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
import type { Browser, BrowserContext } from '@playwright/test'
|
||||
import type { PrismaClient } from '../../../../packages/db/src/generated/prisma/client'
|
||||
import { E2E_APP_URL, E2E_PASSWORD, apiSignup, injectAuthState, uniqueEmail } from './auth'
|
||||
|
||||
export interface SeededMember {
|
||||
userId: string
|
||||
email: string
|
||||
teamMemberId: string
|
||||
context?: BrowserContext
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds a new user with a team membership of the given role.
|
||||
* If `browser` and `ownerContext` are provided, generates an invite code via the owner's request context
|
||||
* so `apiSignup` succeeds and session cookies/auth state are initialized.
|
||||
*/
|
||||
export async function seedTeamMember(
|
||||
prisma: PrismaClient,
|
||||
teamId: string,
|
||||
role: 'owner' | 'editor' | 'reviewer',
|
||||
browser?: Browser,
|
||||
ownerContext?: BrowserContext,
|
||||
): Promise<SeededMember> {
|
||||
if (browser && ownerContext) {
|
||||
const inviteRes = await ownerContext.request.post(`/api/teams/${teamId}/invite`, {
|
||||
data: { role: role === 'owner' ? 'editor' : role },
|
||||
})
|
||||
if (!inviteRes.ok()) {
|
||||
throw new Error(`Failed to generate team invite code: ${await inviteRes.text()}`)
|
||||
}
|
||||
const inviteBody = (await inviteRes.json()) as { code: string }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const context = await browser.newContext({ baseURL: E2E_APP_URL })
|
||||
const email = uniqueEmail(`member-${role}`)
|
||||
const user = await apiSignup(context.request, email, E2E_PASSWORD, {
|
||||
inviteCode: inviteBody.code,
|
||||
})
|
||||
await injectAuthState(context, user)
|
||||
|
||||
const tm = await prisma.teamMember.findUnique({
|
||||
where: { teamIdUserId: { teamId, userId: user.id } },
|
||||
})
|
||||
if (tm && tm.role !== role) {
|
||||
await prisma.teamMember.update({
|
||||
where: { id: tm.id },
|
||||
data: { role, scope: 'team' },
|
||||
})
|
||||
}
|
||||
return { userId: user.id, email, teamMemberId: tm!.id, context }
|
||||
}
|
||||
|
||||
const email = uniqueEmail(`member-${role}`)
|
||||
const user = await prisma.user.create({
|
||||
data: { name: email, email, password: 'Password123!' },
|
||||
})
|
||||
const tm = await prisma.teamMember.create({
|
||||
data: { teamId, userId: user.id, role, scope: 'team' },
|
||||
})
|
||||
return { userId: user.id, email, teamMemberId: tm.id }
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds a new user with a project membership of the given role.
|
||||
* If `browser` and `ownerContext` are provided, generates an invite code via the owner's request context
|
||||
* so `apiSignup` succeeds and session cookies/auth state are initialized.
|
||||
*/
|
||||
export async function seedProjectMember(
|
||||
prisma: PrismaClient,
|
||||
teamId: string,
|
||||
projectId: string,
|
||||
role: 'editor' | 'reviewer',
|
||||
scope: 'team' | 'project' = 'project',
|
||||
browser?: Browser,
|
||||
ownerContext?: BrowserContext,
|
||||
): Promise<SeededMember & { projectMemberId: string }> {
|
||||
if (browser && ownerContext) {
|
||||
const inviteRes = await ownerContext.request.post(`/api/projects/${projectId}/invite`, {
|
||||
data: { role },
|
||||
})
|
||||
if (!inviteRes.ok()) {
|
||||
throw new Error(`Failed to generate project invite code: ${await inviteRes.text()}`)
|
||||
}
|
||||
const inviteBody = (await inviteRes.json()) as { code: string }
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
const context = await browser.newContext({ baseURL: E2E_APP_URL })
|
||||
const email = uniqueEmail(`proj-member-${role}`)
|
||||
const user = await apiSignup(context.request, email, E2E_PASSWORD, {
|
||||
inviteCode: inviteBody.code,
|
||||
})
|
||||
await injectAuthState(context, user)
|
||||
|
||||
const tm = await prisma.teamMember.findUnique({
|
||||
where: { teamIdUserId: { teamId, userId: user.id } },
|
||||
})
|
||||
const pm = await prisma.projectMember.findFirst({
|
||||
where: { projectId, teamMemberId: tm!.id },
|
||||
})
|
||||
if (pm && pm.role !== role) {
|
||||
await prisma.projectMember.update({
|
||||
where: { id: pm.id },
|
||||
data: { role },
|
||||
})
|
||||
}
|
||||
|
||||
return { userId: user.id, email, teamMemberId: tm!.id, projectMemberId: pm!.id, context }
|
||||
}
|
||||
|
||||
const email = uniqueEmail(`proj-member-${role}`)
|
||||
const user = await prisma.user.create({
|
||||
data: { name: email, email, password: 'Password123!' },
|
||||
})
|
||||
const tm = await prisma.teamMember.create({
|
||||
data: { teamId, userId: user.id, role: scope === 'team' ? 'editor' : 'reviewer', scope },
|
||||
})
|
||||
const pm = await prisma.projectMember.create({
|
||||
data: { projectId, teamMemberId: tm.id, role },
|
||||
})
|
||||
return { userId: user.id, email, teamMemberId: tm.id, projectMemberId: pm.id }
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { expect, type Locator, type Page } from '@playwright/test'
|
||||
|
||||
export function parseTeamIdFromUrl(url: string): string {
|
||||
const match = url.match(/\/teams\/([^/]+)/)
|
||||
if (!match) throw new Error(`Could not parse teamId from URL: ${url}`)
|
||||
return match[1]
|
||||
}
|
||||
|
||||
/** Performs the signup UI flow and waits for the redirect to the team page. */
|
||||
export async function signupViaUi(page: Page, email: string, password: string): Promise<string> {
|
||||
await page.goto('/signup')
|
||||
await page.fill('#email', email)
|
||||
await page.fill('#password', password)
|
||||
await page.click('button[type="submit"]')
|
||||
await page.waitForURL(/\/teams\/[^/]+/)
|
||||
return parseTeamIdFromUrl(page.url())
|
||||
}
|
||||
|
||||
/** Performs the login UI flow and waits for the redirect to the team page. */
|
||||
export async function loginViaUi(page: Page, email: string, password: string): Promise<string> {
|
||||
await page.goto('/login')
|
||||
await page.fill('#email', email)
|
||||
await page.fill('#password', password)
|
||||
await page.click('button[type="submit"]')
|
||||
await page.waitForURL(/\/teams\/[^/]+/)
|
||||
return parseTeamIdFromUrl(page.url())
|
||||
}
|
||||
|
||||
/** Opens the team members dialog from the team page header. */
|
||||
export async function openMembersDialog(page: Page): Promise<Locator> {
|
||||
await page.getByTestId('team-members-trigger').click()
|
||||
const dialog = page.locator('[role="dialog"]')
|
||||
await expect(dialog).toBeVisible()
|
||||
return dialog
|
||||
}
|
||||
|
||||
/** Opens the project members dialog from the project file-browser toolbar. */
|
||||
export async function openProjectMembersDialog(page: Page): Promise<Locator> {
|
||||
await page.getByTestId('project-members-trigger').click()
|
||||
const dialog = page.locator('[role="dialog"]')
|
||||
await expect(dialog).toBeVisible()
|
||||
return dialog
|
||||
}
|
||||
|
||||
/** Clicks "Generate Link" in the members dialog and returns the invite link. */
|
||||
export async function generateInviteLink(dialog: Locator): Promise<string> {
|
||||
await dialog.getByRole('button', { name: 'Generate Link' }).click()
|
||||
const inviteInput = dialog.locator('input[readonly]')
|
||||
await expect(inviteInput).toBeVisible()
|
||||
const inviteLink = await inviteInput.inputValue()
|
||||
if (!inviteLink.includes('inviteCode=')) {
|
||||
throw new Error(`Unexpected invite link: ${inviteLink}`)
|
||||
}
|
||||
return inviteLink
|
||||
}
|
||||
@@ -32,4 +32,7 @@ async function start() {
|
||||
await import('../src/index.ts')
|
||||
}
|
||||
|
||||
start().catch(console.error)
|
||||
start().catch((err) => {
|
||||
console.error('Failed to start E2E server:', err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { apiSignup, E2E_PASSWORD, uniqueEmail } from '../../helpers/auth'
|
||||
import { loginViaUi } from '../../helpers/ui'
|
||||
|
||||
test('should log in with existing credentials', async ({ page, request }) => {
|
||||
const email = uniqueEmail('login')
|
||||
const password = E2E_PASSWORD
|
||||
|
||||
// Seed an existing user through the API (setup, not the flow under test)
|
||||
await apiSignup(request, email, password)
|
||||
|
||||
// The default page context is a fresh, logged-out session
|
||||
await loginViaUi(page, email, password)
|
||||
|
||||
// The logged-in user lands on their team page
|
||||
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||
await expect(page.getByRole('heading', { name: 'Projects' })).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,63 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { apiSignup, E2E_PASSWORD, uniqueEmail } from '../../helpers/auth'
|
||||
import { loginViaUi } from '../../helpers/ui'
|
||||
|
||||
test('should show error when accessing reset-password page without token', async ({ page }) => {
|
||||
await page.goto('/reset-password')
|
||||
await expect(page.getByText('Invalid or missing reset token.')).toBeVisible()
|
||||
await expect(page.getByRole('button', { name: 'Go to Login' })).toBeVisible()
|
||||
})
|
||||
|
||||
test('should reset password with valid token and allow logging in with new password', async ({
|
||||
page,
|
||||
request,
|
||||
prisma,
|
||||
}) => {
|
||||
const email = uniqueEmail('reset-pw')
|
||||
const oldPassword = E2E_PASSWORD
|
||||
const newPassword = 'newSecretPassword123'
|
||||
|
||||
// 1. Seed user
|
||||
await apiSignup(request, email, oldPassword)
|
||||
|
||||
// 2. Request password reset via API
|
||||
const resetRes = await request.post('/api/auth/request-password-reset', {
|
||||
data: {
|
||||
email,
|
||||
redirectTo: '/reset-password',
|
||||
},
|
||||
})
|
||||
expect(resetRes.ok()).toBe(true)
|
||||
|
||||
// Retrieve the generated verification token from DB
|
||||
const verification = await prisma.verification.findFirst({
|
||||
where: {
|
||||
identifier: { startsWith: 'reset-password:' },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
})
|
||||
expect(verification).not.toBeNull()
|
||||
const token = verification!.identifier.replace('reset-password:', '')
|
||||
|
||||
// 3. Open reset password page with token
|
||||
await page.goto(`/reset-password?token=${token}`)
|
||||
|
||||
// 4. Fill in new password and confirmation
|
||||
await page.locator('input#password').fill(newPassword)
|
||||
await page.locator('input#confirmPassword').fill(newPassword)
|
||||
|
||||
// 5. Submit form
|
||||
await page.getByRole('button', { name: 'Reset Password' }).click()
|
||||
|
||||
// 6. Verify success state
|
||||
await expect(page.getByText('Password reset successfully!')).toBeVisible()
|
||||
|
||||
// 7. Click Go to Login
|
||||
await page.getByRole('button', { name: 'Go to Login' }).click()
|
||||
await expect(page).toHaveURL('/login')
|
||||
|
||||
// 8. Log in with the new password
|
||||
await loginViaUi(page, email, newPassword)
|
||||
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||
await expect(page.getByRole('heading', { name: 'Projects' })).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { E2E_PASSWORD, uniqueEmail } from '../../helpers/auth'
|
||||
import { signupViaUi } from '../../helpers/ui'
|
||||
|
||||
test('should sign up as the first user and become the team owner', async ({ page, prisma }) => {
|
||||
const email = uniqueEmail('signup')
|
||||
const password = E2E_PASSWORD
|
||||
|
||||
const teamId = await signupViaUi(page, email, password)
|
||||
|
||||
// The first user is redirected to their single team
|
||||
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||
await expect(page.getByRole('heading', { name: 'Projects' })).toBeVisible()
|
||||
|
||||
// The new user exists and is the owner of the team
|
||||
const user = await prisma.user.findUnique({ where: { email } })
|
||||
expect(user).not.toBeNull()
|
||||
|
||||
const membership = await prisma.teamMember.findUnique({
|
||||
where: { teamIdUserId: { teamId, userId: user!.id } },
|
||||
})
|
||||
expect(membership?.role).toBe('owner')
|
||||
expect(membership?.scope).toBe('team')
|
||||
})
|
||||
@@ -0,0 +1,68 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
|
||||
test.use({ fileOptions: { mediaType: 'audio' } })
|
||||
|
||||
test('upload an audio file, create a comment at a non-zero timestamp', async ({ file, prisma }) => {
|
||||
const { page, projectId, fileId } = file
|
||||
const commentText = `Audio timestamp comment ${Date.now()}`
|
||||
|
||||
// Wait for audio transcode completion
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const asset = await prisma.asset.findUnique({ where: { id: fileId } })
|
||||
return asset?.status
|
||||
},
|
||||
{ timeout: 30_000 },
|
||||
)
|
||||
.toBe('processed')
|
||||
|
||||
await page.goto(`/projects/${projectId}/files/${fileId}`)
|
||||
|
||||
// Wait for audio/video media element to be visible
|
||||
const mediaEl = page.locator('audio, video').first()
|
||||
await expect(mediaEl).toBeVisible({ timeout: 30_000 })
|
||||
|
||||
// Seek media element to non-zero timestamp (e.g. 1 second)
|
||||
await page.evaluate(() => {
|
||||
const el = document.querySelector('audio, video') as HTMLMediaElement | null
|
||||
if (el) el.currentTime = 1
|
||||
})
|
||||
await page.waitForTimeout(500)
|
||||
|
||||
// Type comment text and send
|
||||
const input = page.locator('[contenteditable="true"]').first()
|
||||
await input.fill(commentText)
|
||||
const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last()
|
||||
await sendBtn.click()
|
||||
|
||||
// Verify comment card appears in sidebar
|
||||
await expect(page.getByText(commentText)).toBeVisible()
|
||||
|
||||
// Ensure comment is persisted in DB before page reload
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return prisma.assetComment.findFirst({
|
||||
where: { assetId: fileId, message: commentText },
|
||||
})
|
||||
})
|
||||
.not.toBeNull()
|
||||
|
||||
// Reload page
|
||||
await page.reload()
|
||||
|
||||
// Click the comment in right sidebar
|
||||
const commentCard = page.getByText(commentText).first()
|
||||
await expect(commentCard).toBeVisible()
|
||||
await commentCard.click()
|
||||
|
||||
// Verify media element jumped to timestamp
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return page.evaluate(() => {
|
||||
const el = document.querySelector('audio, video') as HTMLMediaElement | null
|
||||
return el ? el.currentTime : 0
|
||||
})
|
||||
})
|
||||
.toBeGreaterThan(0)
|
||||
})
|
||||
@@ -0,0 +1,32 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
|
||||
test('create a comment on a binary file', async ({ file, prisma }) => {
|
||||
const { page, projectId, fileId } = file
|
||||
const commentText = `Binary comment ${Date.now()}`
|
||||
|
||||
await page.goto(`/projects/${projectId}/files/${fileId}`)
|
||||
|
||||
// Wait for file page & comments sidebar to load
|
||||
const input = page.locator('[contenteditable="true"]').first()
|
||||
await expect(input).toBeVisible()
|
||||
|
||||
// Type comment text and send
|
||||
await input.fill(commentText)
|
||||
const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last()
|
||||
await sendBtn.click()
|
||||
|
||||
// Verify comment card appears in sidebar
|
||||
await expect(page.getByText(commentText)).toBeVisible()
|
||||
|
||||
// Refresh page and click the comment
|
||||
await page.reload()
|
||||
const commentCard = page.getByText(commentText).first()
|
||||
await expect(commentCard).toBeVisible()
|
||||
await commentCard.click()
|
||||
|
||||
// DB verification
|
||||
const commentInDb = await prisma.assetComment.findFirst({
|
||||
where: { assetId: fileId, message: commentText },
|
||||
})
|
||||
expect(commentInDb).not.toBeNull()
|
||||
})
|
||||
@@ -0,0 +1,71 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
|
||||
test.use({ fileOptions: { mediaType: 'image' } })
|
||||
|
||||
test('upload an image file, create a comment with draw', async ({ file, prisma }) => {
|
||||
const { page, projectId, fileId } = file
|
||||
const commentText = `Image draw comment ${Date.now()}`
|
||||
|
||||
// Wait for transcode completion
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const asset = await prisma.asset.findUnique({ where: { id: fileId } })
|
||||
return asset?.status
|
||||
},
|
||||
{ timeout: 30_000 },
|
||||
)
|
||||
.toBe('processed')
|
||||
|
||||
await page.goto(`/projects/${projectId}/files/${fileId}`)
|
||||
|
||||
// Verify image is visible
|
||||
await expect(page.locator('img').first()).toBeVisible({ timeout: 30_000 })
|
||||
|
||||
// Toggle drawing mode
|
||||
const drawToggleBtn = page.getByTitle('Toggle Annotation')
|
||||
await expect(drawToggleBtn).toBeVisible()
|
||||
await drawToggleBtn.click()
|
||||
|
||||
// Perform drawing gesture on canvas overlay
|
||||
const canvas = page.locator('.konvajs-content canvas').first()
|
||||
await expect(canvas).toBeVisible()
|
||||
const box = await canvas.boundingBox()
|
||||
if (box) {
|
||||
const startX = box.x + box.width * 0.3
|
||||
const startY = box.y + box.height * 0.3
|
||||
const endX = box.x + box.width * 0.6
|
||||
const endY = box.y + box.height * 0.6
|
||||
await page.mouse.move(startX, startY)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(endX, endY, { steps: 5 })
|
||||
await page.mouse.up()
|
||||
}
|
||||
|
||||
// Type comment text and send
|
||||
const input = page.locator('[contenteditable="true"]').first()
|
||||
await input.fill(commentText)
|
||||
const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last()
|
||||
await sendBtn.click()
|
||||
|
||||
// Verify comment card appears in sidebar
|
||||
await expect(page.getByText(commentText)).toBeVisible()
|
||||
|
||||
// Ensure comment is persisted in DB before page reload
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return prisma.assetComment.findFirst({
|
||||
where: { assetId: fileId, message: commentText },
|
||||
})
|
||||
})
|
||||
.not.toBeNull()
|
||||
|
||||
// Reload page and click comment in right sidebar
|
||||
await page.reload()
|
||||
const commentCard = page.getByText(commentText).first()
|
||||
await expect(commentCard).toBeVisible()
|
||||
await commentCard.click()
|
||||
|
||||
// Verify draw annotation is rendered on canvas
|
||||
await expect(page.locator('.konvajs-content canvas').first()).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,82 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
|
||||
// Uploaded as a binary file so no real transcode task races with the simulated mid-transcode
|
||||
// state we set up directly in the database.
|
||||
test.use({ fileOptions: { mediaType: 'binary' } })
|
||||
|
||||
test('shows the poster preview and "Preparing..." while a video is still transcoding', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileId, fileName } = file
|
||||
|
||||
// Simulate a video that is mid-transcode: the poster/sprite preview already exists, but the
|
||||
// asset is still marked as processing.
|
||||
const assetDir = `files/e2e/${fileId}`
|
||||
await prisma.asset.update({
|
||||
where: { id: fileId },
|
||||
data: {
|
||||
status: 'processing',
|
||||
mediaType: 'video/mp4',
|
||||
media: {
|
||||
duration: 10,
|
||||
filesize: 0,
|
||||
frames: 300,
|
||||
proxyType: 'video',
|
||||
imageTranscodes: [],
|
||||
videoTranscodes: [],
|
||||
sprite: { key: `${assetDir}/sprite.webp`, frames: 100, tileX: 10, tileY: 10 },
|
||||
poster: { key: `${assetDir}/poster.webp` },
|
||||
finishedAt: new Date().toISOString(),
|
||||
metadata: {
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
hasAudio: false,
|
||||
duration: 10,
|
||||
bitRate: 0,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
format: {},
|
||||
},
|
||||
original: { key: `${assetDir}/original.mp4`, filesizeInBytes: 0, codec: '' },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
|
||||
const card = fileCard(page, fileName)
|
||||
await expect(card).toBeVisible()
|
||||
|
||||
// The preview (poster thumbnail used as the sprite scrubber base) is rendered instead of a
|
||||
// blank placeholder, and its opacity breathes while transcoding is in progress.
|
||||
await expect(card.locator('img[alt="Thumbnail"]')).toBeVisible()
|
||||
await expect(card.getByTestId('file-card-preview-media')).toHaveClass(/animate-pulse/)
|
||||
|
||||
// The creator row is replaced by a "Preparing..." label while transcoding.
|
||||
await expect(card.getByText(/Preparing|准备中/i)).toBeVisible()
|
||||
|
||||
// The duration badge is hidden until the asset is ready.
|
||||
await expect(card.getByText('00:10')).toHaveCount(0)
|
||||
})
|
||||
|
||||
test('shows a preparing circle before the poster is generated', async ({ file, prisma }) => {
|
||||
const { page, projectId, fileId, fileName } = file
|
||||
|
||||
// Simulate an asset whose upload finished but whose poster does not exist yet.
|
||||
await prisma.asset.update({
|
||||
where: { id: fileId },
|
||||
data: { status: 'processing', mediaType: 'video/mp4' },
|
||||
})
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
|
||||
const card = fileCard(page, fileName)
|
||||
await expect(card).toBeVisible()
|
||||
|
||||
// A size-breathing circle stands in until the poster is available, with a "Preparing..." label.
|
||||
await expect(card.getByTestId('file-card-preparing-circle')).toBeVisible()
|
||||
await expect(card.getByText(/Preparing|准备中/i)).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,75 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
|
||||
test.use({ fileOptions: { mediaType: 'text' } })
|
||||
|
||||
test('upload a txt file, create a comment with draw', async ({ file, prisma }) => {
|
||||
const { page, projectId, fileId } = file
|
||||
const commentText = `Txt draw comment ${Date.now()}`
|
||||
|
||||
// Wait for background transcode worker to complete (txt -> pdf proxy)
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const asset = await prisma.asset.findUnique({ where: { id: fileId } })
|
||||
return asset?.status
|
||||
},
|
||||
{ timeout: 60_000 },
|
||||
)
|
||||
.toBe('processed')
|
||||
|
||||
await page.goto(`/projects/${projectId}/files/${fileId}`)
|
||||
|
||||
// Verify PDF viewer container or page is loaded
|
||||
await expect(page.locator('.pdf-viewer, canvas, [data-testid="pdf-viewer"]').first()).toBeVisible(
|
||||
{
|
||||
timeout: 30_000,
|
||||
},
|
||||
)
|
||||
|
||||
// Toggle drawing mode
|
||||
const drawToggleBtn = page.getByTitle('Toggle Annotation')
|
||||
await expect(drawToggleBtn).toBeVisible()
|
||||
await drawToggleBtn.click()
|
||||
|
||||
// Perform drawing gesture on canvas overlay
|
||||
const canvas = page.locator('.konvajs-content canvas').first()
|
||||
await expect(canvas).toBeVisible()
|
||||
const box = await canvas.boundingBox()
|
||||
if (box) {
|
||||
const startX = box.x + box.width * 0.3
|
||||
const startY = box.y + box.height * 0.3
|
||||
const endX = box.x + box.width * 0.6
|
||||
const endY = box.y + box.height * 0.6
|
||||
await page.mouse.move(startX, startY)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(endX, endY, { steps: 5 })
|
||||
await page.mouse.up()
|
||||
}
|
||||
|
||||
// Type comment text and send
|
||||
const input = page.locator('[contenteditable="true"]').first()
|
||||
await input.fill(commentText)
|
||||
const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last()
|
||||
await sendBtn.click()
|
||||
|
||||
// Verify comment card appears in sidebar
|
||||
await expect(page.getByText(commentText)).toBeVisible()
|
||||
|
||||
// Ensure comment is persisted in DB before page reload
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return prisma.assetComment.findFirst({
|
||||
where: { assetId: fileId, message: commentText },
|
||||
})
|
||||
})
|
||||
.not.toBeNull()
|
||||
|
||||
// Reload page and click comment in right sidebar
|
||||
await page.reload()
|
||||
const commentCard = page.getByText(commentText).first()
|
||||
await expect(commentCard).toBeVisible()
|
||||
await commentCard.click()
|
||||
|
||||
// Verify draw annotation is rendered on canvas
|
||||
await expect(page.locator('.konvajs-content canvas').first()).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,93 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
|
||||
test.use({ fileOptions: { mediaType: 'video' } })
|
||||
|
||||
test('upload a video file, create a comment with draw at a non-zero timestamp', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileId } = file
|
||||
const commentText = `Video draw comment ${Date.now()}`
|
||||
|
||||
// Wait for video transcode completion
|
||||
await expect
|
||||
.poll(
|
||||
async () => {
|
||||
const asset = await prisma.asset.findUnique({ where: { id: fileId } })
|
||||
return asset?.status
|
||||
},
|
||||
{ timeout: 60_000 },
|
||||
)
|
||||
.toBe('processed')
|
||||
|
||||
await page.goto(`/projects/${projectId}/files/${fileId}`)
|
||||
|
||||
// Wait for video element to be visible
|
||||
const video = page.locator('video').first()
|
||||
await expect(video).toBeVisible({ timeout: 30_000 })
|
||||
|
||||
// Seek video to non-zero timestamp (e.g. 1 second)
|
||||
await page.evaluate(() => {
|
||||
const v = document.querySelector('video')
|
||||
if (v) v.currentTime = 1
|
||||
})
|
||||
await page.waitForTimeout(500)
|
||||
|
||||
// Toggle drawing mode
|
||||
const drawToggleBtn = page.getByTitle('Toggle Annotation')
|
||||
await expect(drawToggleBtn).toBeVisible()
|
||||
await drawToggleBtn.click()
|
||||
|
||||
// Perform drawing gesture on canvas overlay
|
||||
const canvas = page.locator('.konvajs-content canvas').first()
|
||||
await expect(canvas).toBeVisible()
|
||||
const box = await canvas.boundingBox()
|
||||
if (box) {
|
||||
const startX = box.x + box.width * 0.3
|
||||
const startY = box.y + box.height * 0.3
|
||||
const endX = box.x + box.width * 0.6
|
||||
const endY = box.y + box.height * 0.6
|
||||
await page.mouse.move(startX, startY)
|
||||
await page.mouse.down()
|
||||
await page.mouse.move(endX, endY, { steps: 5 })
|
||||
await page.mouse.up()
|
||||
}
|
||||
|
||||
// Type comment text and send
|
||||
const input = page.locator('[contenteditable="true"]').first()
|
||||
await input.fill(commentText)
|
||||
const sendBtn = page.locator('button:has(svg.lucide-arrow-up)').last()
|
||||
await sendBtn.click()
|
||||
|
||||
// Verify comment card appears in sidebar
|
||||
await expect(page.getByText(commentText)).toBeVisible()
|
||||
|
||||
// Ensure comment is persisted in DB before page reload
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return prisma.assetComment.findFirst({
|
||||
where: { assetId: fileId, message: commentText },
|
||||
})
|
||||
})
|
||||
.not.toBeNull()
|
||||
|
||||
// Reload page
|
||||
await page.reload()
|
||||
|
||||
// Click the comment in right sidebar
|
||||
const commentCard = page.getByText(commentText).first()
|
||||
await expect(commentCard).toBeVisible()
|
||||
await commentCard.click()
|
||||
|
||||
// Verify video jumped to timestamp and draw annotation is shown on canvas
|
||||
await expect
|
||||
.poll(async () => {
|
||||
return page.evaluate(() => {
|
||||
const v = document.querySelector('video')
|
||||
return v ? v.currentTime : 0
|
||||
})
|
||||
})
|
||||
.toBeGreaterThan(0)
|
||||
|
||||
await expect(page.locator('.konvajs-content canvas').first()).toBeVisible()
|
||||
})
|
||||
@@ -0,0 +1,64 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { openProjectMembersDialog } from '../../helpers/ui'
|
||||
import { seedProjectMember } from '../../helpers/team'
|
||||
|
||||
test('owner changes a project member role in the members dialog and permissions update', async ({
|
||||
project,
|
||||
browser,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, teamId, projectId, context } = project
|
||||
const member = await seedProjectMember(
|
||||
prisma,
|
||||
teamId,
|
||||
projectId,
|
||||
'reviewer',
|
||||
'project',
|
||||
browser,
|
||||
context,
|
||||
)
|
||||
|
||||
// Open the project detail page and open the project members dialog
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
const dialog = await openProjectMembersDialog(page)
|
||||
|
||||
const memberRow = dialog
|
||||
.locator('div.flex.items-center.justify-between')
|
||||
.filter({ hasText: member.email })
|
||||
await expect(memberRow).toBeVisible()
|
||||
|
||||
// Click role dropdown trigger for this member (currently Reviewer)
|
||||
await memberRow.getByRole('button', { name: /Reviewer/i }).click()
|
||||
|
||||
// Select "Editor" from the dropdown menu
|
||||
await page.getByRole('menuitemradio', { name: 'Editor' }).click()
|
||||
|
||||
// Verify UI displays updated role "Editor"
|
||||
await expect(memberRow.getByRole('button', { name: /Editor/i })).toBeVisible()
|
||||
|
||||
// DB verification: projectMember role is updated to editor
|
||||
const pm = await prisma.projectMember.findUnique({
|
||||
where: {
|
||||
projectIdTeamMemberId: {
|
||||
projectId,
|
||||
teamMemberId: member.teamMemberId,
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(pm?.role).toBe('editor')
|
||||
|
||||
// Functional verification: project member can now perform edit API operations on the project
|
||||
const memberContext = member.context!
|
||||
const memberPage = await memberContext.newPage()
|
||||
try {
|
||||
await memberPage.goto(`/teams/${teamId}`)
|
||||
|
||||
// Verify edit permission on project via API (PUT /api/projects/:projectId requires Edit permission)
|
||||
const res = await memberContext.request.put(`/api/projects/${projectId}`, {
|
||||
data: { enableNotification: true },
|
||||
})
|
||||
expect(res.status()).toBe(200)
|
||||
} finally {
|
||||
await memberContext.close()
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
|
||||
test('owner creates a collection from the sidebar and the collection shows project files', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileName } = file
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
|
||||
// Create a collection via the sidebar "+" button
|
||||
await page.getByTestId('create-collection').click()
|
||||
|
||||
await expect(page).toHaveURL(/\/collections\/[^/]+/)
|
||||
await expect(page.getByText('Collection created')).toBeVisible()
|
||||
|
||||
// The collection page is a recursive files-only view of the project
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
|
||||
const collection = await prisma.collection.findFirst({ where: { projectId } })
|
||||
expect(collection).not.toBeNull()
|
||||
expect(collection?.name).toBe('Untitled Collection')
|
||||
|
||||
const project = await prisma.project.findUnique({ where: { id: projectId } })
|
||||
expect(collection?.filter).toMatchObject({
|
||||
sourceFolderId: project?.rootFolderId,
|
||||
searchFilter: { conditions: [], recursively: true },
|
||||
})
|
||||
})
|
||||
+15
-38
@@ -1,4 +1,4 @@
|
||||
import { expect, test } from './fixtures'
|
||||
import { expect, test } from '../../fixtures'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
@@ -19,57 +19,34 @@ test.afterAll(async () => {
|
||||
}
|
||||
})
|
||||
|
||||
test('should sign up and create a project with a cover image', async ({ page }) => {
|
||||
const email = `test-${Date.now()}@shumai.local`
|
||||
const password = 'Password123!'
|
||||
|
||||
// 1. Sign Up Flow
|
||||
await page.goto('/signup')
|
||||
await expect(page).toHaveURL(/\/signup/)
|
||||
|
||||
// Fill credentials
|
||||
await page.fill('#email', email)
|
||||
await page.fill('#password', password)
|
||||
|
||||
// Submit sign up
|
||||
await page.click('button[type="submit"]')
|
||||
|
||||
// Wait for the automatic redirect to the team page (since only one team exists)
|
||||
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||
|
||||
// 2. Create Project Flow
|
||||
// Click the "Create Project" button on the dashboard
|
||||
await page.click('button:has-text("Create Project")')
|
||||
test('owner should create a project with a cover image', async ({ owner, prisma }) => {
|
||||
const { page, teamId } = owner
|
||||
const projectName = `My Project ${Date.now()}`
|
||||
|
||||
// Open the create project dialog
|
||||
await page.getByRole('button', { name: 'Create Project' }).click()
|
||||
const dialog = page.locator('[role="dialog"]')
|
||||
await expect(dialog).toBeVisible()
|
||||
|
||||
// Fill project name
|
||||
const projectName = `My Project ${Date.now()}`
|
||||
// Fill in project details and upload a cover image
|
||||
await dialog.locator('#name').fill(projectName)
|
||||
|
||||
// Set cover image
|
||||
await dialog.locator('input[type="file"]').setInputFiles(tempImgPath)
|
||||
|
||||
// Wait for image upload completion and preview
|
||||
await expect(dialog.locator('img[alt="Cover Preview"]')).toBeVisible({ timeout: 15_000 })
|
||||
|
||||
// Click submit in dialog
|
||||
// Submit and land on the project page
|
||||
await dialog.locator('button[type="submit"]').click()
|
||||
|
||||
// Wait for navigation to the project page
|
||||
await expect(page).toHaveURL(/\/projects\/[^/]+/)
|
||||
|
||||
// Verify project name appears in the project view
|
||||
await expect(page.locator(`text=${projectName}`).first()).toBeVisible()
|
||||
|
||||
// 3. Verification on Dashboard
|
||||
// Navigate back to the dashboard via sidebar
|
||||
await page.click('button[aria-label="Dashboard"]')
|
||||
|
||||
// Wait for dashboard URL
|
||||
// Back on the home page the new project card is visible with its cover
|
||||
await page.click('button[aria-label="Home"]')
|
||||
await expect(page).toHaveURL(/\/teams\/[^/]+/)
|
||||
|
||||
// Verify the project card is visible and displays the cover image with project name alt text
|
||||
await expect(page.locator(`img[alt="${projectName}"]`)).toBeVisible()
|
||||
|
||||
// The project was persisted for the owner's team
|
||||
const project = await prisma.project.findFirst({ where: { name: projectName } })
|
||||
expect(project).not.toBeNull()
|
||||
expect(project?.teamId).toBe(teamId)
|
||||
})
|
||||
@@ -0,0 +1,36 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
|
||||
test('owner creates a share link from a file context menu and lands on the share page', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileName, fileId } = file
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
|
||||
// Create a share link for the file through the context menu
|
||||
await fileCard(page, fileName).click({ button: 'right' })
|
||||
await page.getByRole('menuitem', { name: 'Create Share Link' }).click()
|
||||
|
||||
// The toast offers a "View" action that navigates to the share page
|
||||
const toast = page.locator('[data-sonner-toast]').filter({ hasText: 'Share link created' })
|
||||
await expect(toast).toBeVisible()
|
||||
await toast.getByRole('button', { name: 'View' }).click()
|
||||
|
||||
await expect(page).toHaveURL(/\/projects\/[^/]+\/shares\/[^/]+/)
|
||||
|
||||
// The shared file is listed in the share contents
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
|
||||
// DB: the share exists and the file is symlinked under the share root
|
||||
const share = await prisma.shareLink.findFirst({ where: { projectId } })
|
||||
expect(share).not.toBeNull()
|
||||
|
||||
const symlink = await prisma.asset.findFirst({
|
||||
where: { parentId: share?.rootFolderId, targetId: fileId },
|
||||
})
|
||||
expect(symlink).not.toBeNull()
|
||||
expect(symlink?.type).toBe('symlink')
|
||||
})
|
||||
@@ -0,0 +1,164 @@
|
||||
import { expect, test } from '../../fixtures'
|
||||
import { seedFile, seedFolder } from '../../helpers/assets'
|
||||
import { fileCard } from '../../helpers/files'
|
||||
|
||||
test('owner deletes a file, finds it in recently deleted, and restores it', async ({
|
||||
file,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, fileName, fileId } = file
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
|
||||
// Delete through the context menu + confirmation dialog
|
||||
await fileCard(page, fileName).click({ button: 'right' })
|
||||
await page.getByRole('menuitem', { name: 'Delete' }).click()
|
||||
|
||||
const deleteDialog = page.getByRole('alertdialog')
|
||||
await expect(deleteDialog.getByText('Delete Asset?')).toBeVisible()
|
||||
await deleteDialog.getByRole('button', { name: 'Delete' }).click()
|
||||
|
||||
await expect(fileCard(page, fileName)).not.toBeVisible()
|
||||
|
||||
let asset = await prisma.asset.findUnique({ where: { id: fileId } })
|
||||
expect(asset?.isDeleted).toBe(true)
|
||||
expect(asset?.deletedAt).not.toBeNull()
|
||||
|
||||
// Navigate to the Recently Deleted view
|
||||
await page.getByText('Recently Deleted').click()
|
||||
await expect(page).toHaveURL(/\/recently-deleted/)
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
|
||||
// Restore through the context menu
|
||||
await fileCard(page, fileName).click({ button: 'right' })
|
||||
await page.getByRole('menuitem', { name: 'Restore' }).click()
|
||||
|
||||
await expect(fileCard(page, fileName)).not.toBeVisible()
|
||||
|
||||
asset = await prisma.asset.findUnique({ where: { id: fileId } })
|
||||
expect(asset?.isDeleted).toBe(false)
|
||||
expect(asset?.deletedAt).toBeNull()
|
||||
|
||||
// Back at the project root the file is visible again
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, fileName)).toBeVisible()
|
||||
})
|
||||
|
||||
test('owner deletes a folder and still sees its contents preview and countdown in recently deleted', async ({
|
||||
project,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, rootFolderId } = project
|
||||
const folderName = `e2e-deleted-folder-${Date.now()}`
|
||||
|
||||
const folder = await seedFolder(prisma, projectId, rootFolderId, folderName)
|
||||
await seedFile(prisma, projectId, folder.id, 'inside-1.png')
|
||||
await seedFile(prisma, projectId, folder.id, 'inside-2.png')
|
||||
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, folderName)).toBeVisible()
|
||||
|
||||
// Delete the folder through the context menu + confirmation dialog
|
||||
await fileCard(page, folderName).click({ button: 'right' })
|
||||
await page.getByRole('menuitem', { name: 'Delete' }).click()
|
||||
|
||||
const deleteDialog = page.getByRole('alertdialog')
|
||||
await expect(deleteDialog.getByText('Delete Asset?')).toBeVisible()
|
||||
await deleteDialog.getByRole('button', { name: 'Delete' }).click()
|
||||
await expect(fileCard(page, folderName)).not.toBeVisible()
|
||||
|
||||
// Navigate to the Recently Deleted view
|
||||
await page.getByText('Recently Deleted').click()
|
||||
await expect(page).toHaveURL(/\/recently-deleted/)
|
||||
|
||||
const deletedFolderCard = fileCard(page, folderName)
|
||||
await expect(deletedFolderCard).toBeVisible()
|
||||
// The folder still shows previews of the files that were deleted with it
|
||||
await expect(deletedFolderCard.getByTestId('folder-preview-grid')).toBeVisible()
|
||||
// And each item shows how many days are left before permanent deletion
|
||||
await expect(deletedFolderCard.getByTestId('folder-card-days-left')).toHaveText(/30\s*(d|天)/)
|
||||
})
|
||||
|
||||
test('owner deletes a version stack and restores it from recently deleted', async ({
|
||||
project,
|
||||
prisma,
|
||||
}) => {
|
||||
const { page, projectId, rootFolderId } = project
|
||||
const latestVersionName = `e2e-stack-latest-${Date.now()}.png`
|
||||
const olderVersionName = `e2e-stack-older-${Date.now()}.png`
|
||||
|
||||
const stack = await prisma.asset.create({
|
||||
data: {
|
||||
name: `e2e-stack-${Date.now()}`,
|
||||
type: 'version_stack',
|
||||
status: 'processed',
|
||||
projectId,
|
||||
parentId: rootFolderId,
|
||||
fileCount: 2,
|
||||
sizeByte: 20,
|
||||
},
|
||||
})
|
||||
await prisma.asset.create({
|
||||
data: {
|
||||
name: latestVersionName,
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
sizeByte: 10,
|
||||
sortIndex: 'a0',
|
||||
projectId,
|
||||
parentId: stack.id,
|
||||
},
|
||||
})
|
||||
await prisma.asset.create({
|
||||
data: {
|
||||
name: olderVersionName,
|
||||
type: 'file',
|
||||
status: 'processed',
|
||||
sizeByte: 10,
|
||||
sortIndex: 'a1',
|
||||
projectId,
|
||||
parentId: stack.id,
|
||||
},
|
||||
})
|
||||
|
||||
// The stack card is labelled with its latest version's name
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, latestVersionName)).toBeVisible()
|
||||
|
||||
await fileCard(page, latestVersionName).click({ button: 'right' })
|
||||
await page.getByRole('menuitem', { name: 'Delete' }).click()
|
||||
|
||||
const deleteDialog = page.getByRole('alertdialog')
|
||||
await expect(deleteDialog.getByText('Delete Asset?')).toBeVisible()
|
||||
await deleteDialog.getByRole('button', { name: 'Delete' }).click()
|
||||
await expect(fileCard(page, latestVersionName)).not.toBeVisible()
|
||||
|
||||
// The whole stack is soft-deleted, including its versions
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const row = await prisma.asset.findUnique({ where: { id: stack.id } })
|
||||
return row?.isDeleted
|
||||
})
|
||||
.toBe(true)
|
||||
|
||||
// Restore it from the Recently Deleted view
|
||||
await page.getByText('Recently Deleted').click()
|
||||
await expect(page).toHaveURL(/\/recently-deleted/)
|
||||
await expect(fileCard(page, latestVersionName)).toBeVisible()
|
||||
|
||||
await fileCard(page, latestVersionName).click({ button: 'right' })
|
||||
await page.getByRole('menuitem', { name: 'Restore' }).click()
|
||||
await expect(fileCard(page, latestVersionName)).not.toBeVisible()
|
||||
|
||||
await expect
|
||||
.poll(async () => {
|
||||
const row = await prisma.asset.findUnique({ where: { id: stack.id } })
|
||||
return row?.isDeleted
|
||||
})
|
||||
.toBe(false)
|
||||
|
||||
// Back at the project root the stack is visible again
|
||||
await page.goto(`/projects/${projectId}`)
|
||||
await expect(fileCard(page, latestVersionName)).toBeVisible()
|
||||
})
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user