feat(core): export comments to FCP, Premiere, Media Composer, and Resolve (#400)

* feat(core): export comments to FCP, Premiere, Media Composer, and Resolve

Add backend support to export video comments matching Frame.io export capabilities:
- DaVinci Resolve (.edl): CMX 3600 EDL with ResolveColorPurple markers and reply threading
- Avid Media Composer (.xml): OMFI StreamItems XML with TC1 / V1 track allocation and sequential frame positioning
- Adobe Premiere Pro (.xml): FCP7 XML sequence with dual marker placement on sequence and generatoritem
- Final Cut Pro 10.4.0+ (.fiojson): Flattened JSON schema with frame, timestamp, and annotation serialization

Includes DTO schema validation, AssetService export method, API route (GET /files/:fileId/comments/export), SMPTE drop-frame timecode calculations, unit tests, golden master tests, service integration tests, and API endpoint tests.

* test(core): move comments export test fixtures to test directory

* fix(core): escape asset name in Premiere XML, align Resolve FCM, and support CJK

- Escape XML special characters in <name> tag for Premiere Pro XML sequence
- Harmonize Resolve EDL FCM header and emitted timecodes using getEffectiveDropFrame
- Use RFC 5987 / RFC 6266 buildContentDisposition for CJK filenames in download headers
- Add test coverage for CJK filenames, comments, and author names across all 4 NLE formats

* fix(core): implement timezone-aware comment exports and sanitize resolve edl
This commit is contained in:
Yiling-J
2026-09-13 14:48:41 +08:00
committed by GitHub
parent 70b81355c2
commit 3420d848cb
20 changed files with 3855 additions and 1 deletions
+80
View File
@@ -70,6 +70,7 @@ describe('file api', () => {
assetId: 'file1',
} as unknown as Awaited<ReturnType<typeof assetService.getComment>>)
vi.spyOn(assetService, 'listComments').mockImplementation(vi.fn())
vi.spyOn(assetService, 'exportComments').mockImplementation(vi.fn())
vi.spyOn(assetService, 'restoreAssets').mockImplementation(vi.fn())
vi.spyOn(metadataService, 'updateAssetMetadata').mockImplementation(vi.fn())
vi.spyOn(notificationService, 'create').mockImplementation(vi.fn())
@@ -350,6 +351,85 @@ describe('file api', () => {
})
})
it('GET /files/:fileId/comments/export - success', async () => {
vi.mocked(assetService.exportComments).mockResolvedValue({
content: 'TITLE: test\n001 ...',
filename: 'test-video_comments.edl',
mimeType: 'application/edl',
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/test-id/comments/export?format=resolve-edl')
expect(res.status).toBe(200)
expect(res.headers.get('Content-Disposition')).toBe(
'attachment; filename="test-video_comments.edl"; filename*=UTF-8\'\'test-video_comments.edl',
)
expect(res.headers.get('Content-Type')).toBe('application/edl')
const body = await res.text()
expect(body).toBe('TITLE: test\n001 ...')
expect(authzService.hasPermission).toHaveBeenCalledWith({
user: { id: 'user1', name: 'Test User' },
permission: Permission.Read,
type: ResourceType.Asset,
id: 'test-id',
})
expect(assetService.exportComments).toHaveBeenCalledWith('test-id', 'resolve-edl', {
timeZone: undefined,
})
})
it('GET /files/:fileId/comments/export - handles CJK filename in Content-Disposition', async () => {
vi.mocked(assetService.exportComments).mockResolvedValue({
content: 'TITLE: 中文视频\n001 ...',
filename: '宣传片_2026_resolve.edl',
mimeType: 'text/plain; charset=utf-8',
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request('/files/test-id/comments/export?format=resolve-edl')
expect(res.status).toBe(200)
expect(res.headers.get('Content-Disposition')).toBe(
`attachment; filename*=UTF-8''${encodeURIComponent('宣传片_2026_resolve.edl')}`,
)
})
it('GET /files/:fileId/comments/export - with timezone query', async () => {
vi.mocked(assetService.exportComments).mockResolvedValue({
content: '{}',
filename: 'test.fiojson',
mimeType: 'application/json',
})
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const res = await app.request(
'/files/test-id/comments/export?format=fcp-fiojson&timeZone=America%2FNew_York',
)
expect(res.status).toBe(200)
expect(assetService.exportComments).toHaveBeenCalledWith('test-id', 'fcp-fiojson', {
timeZone: 'America/New_York',
})
})
it('GET /files/:fileId/comments/export - 400 on missing or invalid format', async () => {
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
const resMissing = await app.request('/files/test-id/comments/export')
expect(resMissing.status).toBe(400)
const resInvalid = await app.request('/files/test-id/comments/export?format=invalid-format')
expect(resInvalid.status).toBe(400)
const resInvalidTz = await app.request(
'/files/test-id/comments/export?format=resolve-edl&timeZone=Invalid/Fake_Zone',
)
expect(resInvalidTz.status).toBe(400)
})
it('POST /comments/:commentId/complete', async () => {
vi.mocked(assetService.completeComment).mockResolvedValue({
id: 'comment-id',
+24 -1
View File
@@ -17,9 +17,10 @@ import {
uploadFileRequestSchema,
getDownloadLinksRequestSchema,
completeCommentRequestSchema,
exportCommentsQuerySchema,
AuditAction,
} from '@shumai/dtos'
import { transcodeService } from '@shumai/core'
import { transcodeService, buildContentDisposition } from '@shumai/core'
import fs from 'fs'
import { Hono } from 'hono'
import os from 'os'
@@ -227,6 +228,28 @@ const route = new Hono<{ Variables: { user: User } }>()
const comments = await assetService.listComments(fileId, req)
return c.json(comments)
})
.get(
'/files/:fileId/comments/export',
zValidator('query', exportCommentsQuerySchema),
async (c) => {
const fileId = c.req.param('fileId')
const user = c.get('user')
const { format, timeZone } = c.req.valid('query')
await authzService.hasPermission({
user,
permission: Permission.Read,
type: ResourceType.Asset,
id: fileId,
})
const result = await assetService.exportComments(fileId, format, { timeZone })
c.header('Content-Type', result.mimeType)
c.header('Content-Disposition', buildContentDisposition(result.filename))
return c.body(result.content)
},
)
.post(
'/comments/:commentId/complete',
zValidator('json', completeCommentRequestSchema),