mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 05:14:25 +00:00
feat(webui): add NLE comments export and migrate export API to POST (#401)
This commit is contained in:
@@ -351,7 +351,7 @@ describe('file api', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('GET /files/:fileId/comments/export - success', async () => {
|
it('POST /files/:fileId/comments/export - success', async () => {
|
||||||
vi.mocked(assetService.exportComments).mockResolvedValue({
|
vi.mocked(assetService.exportComments).mockResolvedValue({
|
||||||
content: 'TITLE: test\n001 ...',
|
content: 'TITLE: test\n001 ...',
|
||||||
filename: 'test-video_comments.edl',
|
filename: 'test-video_comments.edl',
|
||||||
@@ -359,7 +359,11 @@ describe('file api', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||||
const res = await app.request('/files/test-id/comments/export?format=resolve-edl')
|
const res = await app.request('/files/test-id/comments/export', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ format: 'resolve-edl' }),
|
||||||
|
})
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.headers.get('Content-Disposition')).toBe(
|
expect(res.headers.get('Content-Disposition')).toBe(
|
||||||
@@ -381,7 +385,7 @@ describe('file api', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('GET /files/:fileId/comments/export - handles CJK filename in Content-Disposition', async () => {
|
it('POST /files/:fileId/comments/export - handles CJK filename in Content-Disposition', async () => {
|
||||||
vi.mocked(assetService.exportComments).mockResolvedValue({
|
vi.mocked(assetService.exportComments).mockResolvedValue({
|
||||||
content: 'TITLE: 中文视频\n001 ...',
|
content: 'TITLE: 中文视频\n001 ...',
|
||||||
filename: '宣传片_2026_resolve.edl',
|
filename: '宣传片_2026_resolve.edl',
|
||||||
@@ -389,7 +393,11 @@ describe('file api', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||||
const res = await app.request('/files/test-id/comments/export?format=resolve-edl')
|
const res = await app.request('/files/test-id/comments/export', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ format: 'resolve-edl' }),
|
||||||
|
})
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(res.headers.get('Content-Disposition')).toBe(
|
expect(res.headers.get('Content-Disposition')).toBe(
|
||||||
@@ -397,7 +405,7 @@ describe('file api', () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('GET /files/:fileId/comments/export - with timezone query', async () => {
|
it('POST /files/:fileId/comments/export - with timezone in body', async () => {
|
||||||
vi.mocked(assetService.exportComments).mockResolvedValue({
|
vi.mocked(assetService.exportComments).mockResolvedValue({
|
||||||
content: '{}',
|
content: '{}',
|
||||||
filename: 'test.fiojson',
|
filename: 'test.fiojson',
|
||||||
@@ -405,9 +413,14 @@ describe('file api', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||||
const res = await app.request(
|
const res = await app.request('/files/test-id/comments/export', {
|
||||||
'/files/test-id/comments/export?format=fcp-fiojson&timeZone=America%2FNew_York',
|
method: 'POST',
|
||||||
)
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
format: 'fcp-fiojson',
|
||||||
|
timeZone: 'America/New_York',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
expect(res.status).toBe(200)
|
expect(res.status).toBe(200)
|
||||||
expect(assetService.exportComments).toHaveBeenCalledWith('test-id', 'fcp-fiojson', {
|
expect(assetService.exportComments).toHaveBeenCalledWith('test-id', 'fcp-fiojson', {
|
||||||
@@ -415,18 +428,31 @@ describe('file api', () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it('GET /files/:fileId/comments/export - 400 on missing or invalid format', async () => {
|
it('POST /files/:fileId/comments/export - 400 on missing or invalid format', async () => {
|
||||||
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
const app = new Hono().use('*', authMiddleware).route('/', fileRoute)
|
||||||
|
|
||||||
const resMissing = await app.request('/files/test-id/comments/export')
|
const resMissing = await app.request('/files/test-id/comments/export', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
})
|
||||||
expect(resMissing.status).toBe(400)
|
expect(resMissing.status).toBe(400)
|
||||||
|
|
||||||
const resInvalid = await app.request('/files/test-id/comments/export?format=invalid-format')
|
const resInvalid = await app.request('/files/test-id/comments/export', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ format: 'invalid-format' }),
|
||||||
|
})
|
||||||
expect(resInvalid.status).toBe(400)
|
expect(resInvalid.status).toBe(400)
|
||||||
|
|
||||||
const resInvalidTz = await app.request(
|
const resInvalidTz = await app.request('/files/test-id/comments/export', {
|
||||||
'/files/test-id/comments/export?format=resolve-edl&timeZone=Invalid/Fake_Zone',
|
method: 'POST',
|
||||||
)
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
format: 'resolve-edl',
|
||||||
|
timeZone: 'Invalid/Fake_Zone',
|
||||||
|
}),
|
||||||
|
})
|
||||||
expect(resInvalidTz.status).toBe(400)
|
expect(resInvalidTz.status).toBe(400)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import {
|
|||||||
uploadFileRequestSchema,
|
uploadFileRequestSchema,
|
||||||
getDownloadLinksRequestSchema,
|
getDownloadLinksRequestSchema,
|
||||||
completeCommentRequestSchema,
|
completeCommentRequestSchema,
|
||||||
exportCommentsQuerySchema,
|
exportCommentsRequestSchema,
|
||||||
AuditAction,
|
AuditAction,
|
||||||
} from '@shumai/dtos'
|
} from '@shumai/dtos'
|
||||||
import { transcodeService, buildContentDisposition } from '@shumai/core'
|
import { transcodeService, buildContentDisposition } from '@shumai/core'
|
||||||
@@ -228,13 +228,13 @@ const route = new Hono<{ Variables: { user: User } }>()
|
|||||||
const comments = await assetService.listComments(fileId, req)
|
const comments = await assetService.listComments(fileId, req)
|
||||||
return c.json(comments)
|
return c.json(comments)
|
||||||
})
|
})
|
||||||
.get(
|
.post(
|
||||||
'/files/:fileId/comments/export',
|
'/files/:fileId/comments/export',
|
||||||
zValidator('query', exportCommentsQuerySchema),
|
zValidator('json', exportCommentsRequestSchema),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
const fileId = c.req.param('fileId')
|
const fileId = c.req.param('fileId')
|
||||||
const user = c.get('user')
|
const user = c.get('user')
|
||||||
const { format, timeZone } = c.req.valid('query')
|
const { format, timeZone } = c.req.valid('json')
|
||||||
|
|
||||||
await authzService.hasPermission({
|
await authzService.hasPermission({
|
||||||
user,
|
user,
|
||||||
|
|||||||
@@ -348,7 +348,7 @@ export const commentExportFormatSchema = z.enum([
|
|||||||
])
|
])
|
||||||
export type CommentExportFormat = z.infer<typeof commentExportFormatSchema>
|
export type CommentExportFormat = z.infer<typeof commentExportFormatSchema>
|
||||||
|
|
||||||
export const exportCommentsQuerySchema = z.object({
|
export const exportCommentsRequestSchema = z.object({
|
||||||
format: commentExportFormatSchema,
|
format: commentExportFormatSchema,
|
||||||
timeZone: z
|
timeZone: z
|
||||||
.string()
|
.string()
|
||||||
@@ -365,4 +365,9 @@ export const exportCommentsQuerySchema = z.object({
|
|||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
})
|
})
|
||||||
export type ExportCommentsQuery = z.infer<typeof exportCommentsQuerySchema>
|
export type ExportCommentsRequest = z.infer<typeof exportCommentsRequestSchema>
|
||||||
|
|
||||||
|
/** @deprecated Use exportCommentsRequestSchema */
|
||||||
|
export const exportCommentsQuerySchema = exportCommentsRequestSchema
|
||||||
|
/** @deprecated Use ExportCommentsRequest */
|
||||||
|
export type ExportCommentsQuery = ExportCommentsRequest
|
||||||
|
|||||||
@@ -0,0 +1,305 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
||||||
|
import React from 'react'
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||||
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||||
|
import { FileViewerRightSidebar } from './file-viewer-right-sidebar'
|
||||||
|
import type { AssetInfo } from '@shumai/dtos'
|
||||||
|
import { toast } from 'sonner'
|
||||||
|
|
||||||
|
vi.mock('react-intersection-observer', () => ({
|
||||||
|
useInView: () => ({
|
||||||
|
ref: vi.fn(),
|
||||||
|
inView: false,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('@/ui/hooks/use-permissions', () => ({
|
||||||
|
usePermissions: () => ({
|
||||||
|
canEdit: true,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('sonner', () => ({
|
||||||
|
toast: {
|
||||||
|
error: vi.fn(),
|
||||||
|
success: vi.fn(),
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
const mockExportPost = vi.fn()
|
||||||
|
|
||||||
|
vi.mock('@/ui/api/client', () => ({
|
||||||
|
client: {
|
||||||
|
api: {
|
||||||
|
projects: {
|
||||||
|
':projectId': {
|
||||||
|
fields: {
|
||||||
|
$get: vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => [],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
team: {
|
||||||
|
$get: vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ id: 'team-1' }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
files: {
|
||||||
|
':fileId': {
|
||||||
|
comments: {
|
||||||
|
$get: vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({
|
||||||
|
data: [
|
||||||
|
{
|
||||||
|
id: 'comment-1',
|
||||||
|
message: 'Great shot!',
|
||||||
|
userId: 'user-1',
|
||||||
|
createdAt: new Date().toISOString(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
pageInfo: {},
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
$post: vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ id: 'new-comment-id' }),
|
||||||
|
}),
|
||||||
|
export: {
|
||||||
|
$post: (...args: unknown[]) => mockExportPost(...args),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
shares: {
|
||||||
|
':shareId': {
|
||||||
|
files: {
|
||||||
|
':fileId': {
|
||||||
|
comments: {
|
||||||
|
$get: vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ data: [], pageInfo: {} }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
me: {
|
||||||
|
$get: vi.fn().mockResolvedValue({
|
||||||
|
ok: true,
|
||||||
|
json: async () => ({ id: 'user-1', name: 'Test User' }),
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('FileViewerRightSidebar - Comments Export', () => {
|
||||||
|
let queryClient: QueryClient
|
||||||
|
let createObjectUrlMock: ReturnType<typeof vi.spyOn>
|
||||||
|
let revokeObjectUrlMock: ReturnType<typeof vi.spyOn>
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: { retry: false },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
vi.clearAllMocks()
|
||||||
|
|
||||||
|
createObjectUrlMock = vi.spyOn(window.URL, 'createObjectURL').mockReturnValue('blob:mock-url')
|
||||||
|
revokeObjectUrlMock = vi.spyOn(window.URL, 'revokeObjectURL').mockImplementation(() => {})
|
||||||
|
window.HTMLElement.prototype.hasPointerCapture = vi.fn().mockReturnValue(false)
|
||||||
|
window.HTMLElement.prototype.setPointerCapture = vi.fn()
|
||||||
|
window.HTMLElement.prototype.releasePointerCapture = vi.fn()
|
||||||
|
window.HTMLElement.prototype.scrollIntoView = vi.fn()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup()
|
||||||
|
})
|
||||||
|
|
||||||
|
const mockFile: AssetInfo = {
|
||||||
|
id: 'file-123',
|
||||||
|
name: 'sample_cut.mp4',
|
||||||
|
proxyType: 'video',
|
||||||
|
media: {
|
||||||
|
metadata: {
|
||||||
|
duration: 120,
|
||||||
|
frameRate: 24,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as AssetInfo
|
||||||
|
|
||||||
|
it('renders "All comments" and the three-dot button in authenticated sidebar', async () => {
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<FileViewerRightSidebar
|
||||||
|
teamId="team-1"
|
||||||
|
projectId="proj-1"
|
||||||
|
file={mockFile}
|
||||||
|
onSaveField={vi.fn()}
|
||||||
|
members={[{ id: 'user-1', name: 'User One', role: 'owner' }]}
|
||||||
|
isPublic={false}
|
||||||
|
/>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(screen.getByText('All comments')).toBeDefined()
|
||||||
|
expect(screen.getByRole('button', { name: 'More options' })).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('does NOT render "All comments" header row in public share view', async () => {
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<FileViewerRightSidebar
|
||||||
|
teamId="team-1"
|
||||||
|
projectId="proj-1"
|
||||||
|
file={mockFile}
|
||||||
|
onSaveField={vi.fn()}
|
||||||
|
members={[]}
|
||||||
|
isPublic={true}
|
||||||
|
shareId="share-123"
|
||||||
|
/>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(screen.queryByText('All comments')).toBeNull()
|
||||||
|
expect(screen.queryByRole('button', { name: 'More options' })).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('opens dropdown menu with Export Comments and the 4 NLE options', async () => {
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<FileViewerRightSidebar
|
||||||
|
teamId="team-1"
|
||||||
|
projectId="proj-1"
|
||||||
|
file={mockFile}
|
||||||
|
onSaveField={vi.fn()}
|
||||||
|
members={[{ id: 'user-1', name: 'User One', role: 'owner' }]}
|
||||||
|
isPublic={false}
|
||||||
|
/>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const moreButton = screen.getByRole('button', { name: 'More options' })
|
||||||
|
fireEvent.pointerDown(moreButton, { button: 0, ctrlKey: false })
|
||||||
|
|
||||||
|
// Submenu trigger should be visible
|
||||||
|
const exportText = await screen.findByText('Export Comments')
|
||||||
|
const subTrigger = exportText.closest('[data-slot="dropdown-menu-sub-trigger"]') || exportText
|
||||||
|
expect(subTrigger).toBeDefined()
|
||||||
|
|
||||||
|
// Open submenu via ArrowRight or click
|
||||||
|
fireEvent.keyDown(subTrigger, { key: 'ArrowRight', code: 'ArrowRight' })
|
||||||
|
|
||||||
|
// All 4 formats should be rendered
|
||||||
|
expect(await screen.findByText('FCP 10.4.0+')).toBeDefined()
|
||||||
|
expect(screen.getByText('FIOJSON')).toBeDefined()
|
||||||
|
|
||||||
|
expect(screen.getByText('Media Composer')).toBeDefined()
|
||||||
|
|
||||||
|
expect(screen.getByText('Premiere Pro')).toBeDefined()
|
||||||
|
expect(screen.getAllByText('XML').length).toBe(2) // Media Composer + Premiere Pro
|
||||||
|
|
||||||
|
expect(screen.getByText('Resolve')).toBeDefined()
|
||||||
|
expect(screen.getByText('EDL')).toBeDefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('calls export API and triggers download when selecting an NLE format', async () => {
|
||||||
|
const mockBlob = new Blob(['TITLE: sample\n001 ...'], { type: 'application/edl' })
|
||||||
|
mockExportPost.mockResolvedValueOnce({
|
||||||
|
ok: true,
|
||||||
|
blob: async () => mockBlob,
|
||||||
|
headers: new Headers({
|
||||||
|
'content-disposition': 'attachment; filename="sample_cut_comments.edl"',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
|
||||||
|
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||||||
|
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<FileViewerRightSidebar
|
||||||
|
teamId="team-1"
|
||||||
|
projectId="proj-1"
|
||||||
|
file={mockFile}
|
||||||
|
onSaveField={vi.fn()}
|
||||||
|
members={[{ id: 'user-1', name: 'User One', role: 'owner' }]}
|
||||||
|
isPublic={false}
|
||||||
|
/>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const moreButton = screen.getByRole('button', { name: 'More options' })
|
||||||
|
fireEvent.pointerDown(moreButton, { button: 0, ctrlKey: false })
|
||||||
|
|
||||||
|
const exportText = await screen.findByText('Export Comments')
|
||||||
|
const subTrigger = exportText.closest('[data-slot="dropdown-menu-sub-trigger"]') || exportText
|
||||||
|
fireEvent.keyDown(subTrigger, { key: 'ArrowRight', code: 'ArrowRight' })
|
||||||
|
|
||||||
|
const resolveOption = await screen.findByText('Resolve')
|
||||||
|
fireEvent.click(resolveOption.closest('[data-slot="dropdown-menu-item"]') || resolveOption)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockExportPost).toHaveBeenCalledWith({
|
||||||
|
param: { fileId: 'file-123' },
|
||||||
|
json: {
|
||||||
|
format: 'resolve-edl',
|
||||||
|
timeZone: expect.any(String),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(createObjectUrlMock).toHaveBeenCalledWith(mockBlob)
|
||||||
|
expect(clickSpy).toHaveBeenCalled()
|
||||||
|
expect(revokeObjectUrlMock).toHaveBeenCalledWith('blob:mock-url')
|
||||||
|
clickSpy.mockRestore()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('shows error toast when export fails', async () => {
|
||||||
|
mockExportPost.mockResolvedValueOnce({
|
||||||
|
ok: false,
|
||||||
|
status: 500,
|
||||||
|
})
|
||||||
|
|
||||||
|
render(
|
||||||
|
<QueryClientProvider client={queryClient}>
|
||||||
|
<FileViewerRightSidebar
|
||||||
|
teamId="team-1"
|
||||||
|
projectId="proj-1"
|
||||||
|
file={mockFile}
|
||||||
|
onSaveField={vi.fn()}
|
||||||
|
members={[{ id: 'user-1', name: 'User One', role: 'owner' }]}
|
||||||
|
isPublic={false}
|
||||||
|
/>
|
||||||
|
</QueryClientProvider>,
|
||||||
|
)
|
||||||
|
|
||||||
|
const moreButton = screen.getByRole('button', { name: 'More options' })
|
||||||
|
fireEvent.pointerDown(moreButton, { button: 0, ctrlKey: false })
|
||||||
|
|
||||||
|
const exportText = await screen.findByText('Export Comments')
|
||||||
|
const subTrigger = exportText.closest('[data-slot="dropdown-menu-sub-trigger"]') || exportText
|
||||||
|
fireEvent.keyDown(subTrigger, { key: 'ArrowRight', code: 'ArrowRight' })
|
||||||
|
|
||||||
|
const premiereOption = await screen.findByText('Premiere Pro')
|
||||||
|
fireEvent.click(premiereOption.closest('[data-slot="dropdown-menu-item"]') || premiereOption)
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(mockExportPost).toHaveBeenCalledWith({
|
||||||
|
param: { fileId: 'file-123' },
|
||||||
|
json: {
|
||||||
|
format: 'premiere-xml',
|
||||||
|
timeZone: expect.any(String),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
expect(toast.error).toHaveBeenCalledWith('Failed to export comments')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { AssetInfo, CommentInfo, FieldValueInfo } from '@shumai/dtos'
|
import type { AssetInfo, CommentExportFormat, CommentInfo, FieldValueInfo } from '@shumai/dtos'
|
||||||
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
|
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
|
||||||
import type { MemberInfo } from '@/ui/stores/members'
|
import type { MemberInfo } from '@/ui/stores/members'
|
||||||
import { client } from '@/ui/api/client'
|
import { client } from '@/ui/api/client'
|
||||||
@@ -14,6 +14,18 @@ import { ChatInput } from './chat/message-input'
|
|||||||
import FieldRenderer from './field-renderer'
|
import FieldRenderer from './field-renderer'
|
||||||
import { GuestIdentityPopup } from './guest-identity-popup'
|
import { GuestIdentityPopup } from './guest-identity-popup'
|
||||||
import { ScrollArea } from './ui/scroll-area'
|
import { ScrollArea } from './ui/scroll-area'
|
||||||
|
import { Button } from './ui/button'
|
||||||
|
import {
|
||||||
|
DropdownMenu,
|
||||||
|
DropdownMenuContent,
|
||||||
|
DropdownMenuItem,
|
||||||
|
DropdownMenuSub,
|
||||||
|
DropdownMenuSubContent,
|
||||||
|
DropdownMenuSubTrigger,
|
||||||
|
DropdownMenuTrigger,
|
||||||
|
} from './ui/dropdown-menu'
|
||||||
|
import { MoreHorizontal } from 'lucide-react'
|
||||||
|
import { toast } from 'sonner'
|
||||||
import { m } from '@/ui/paraglide/messages.js'
|
import { m } from '@/ui/paraglide/messages.js'
|
||||||
import { getViewerForFile } from '@/ui/components/viewers/registry'
|
import { getViewerForFile } from '@/ui/components/viewers/registry'
|
||||||
|
|
||||||
@@ -34,6 +46,17 @@ interface FileViewerRightSidebarProps {
|
|||||||
selectedCommentId?: string | null
|
selectedCommentId?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const COMMENT_EXPORT_OPTIONS: {
|
||||||
|
format: CommentExportFormat
|
||||||
|
label: string
|
||||||
|
ext: string
|
||||||
|
}[] = [
|
||||||
|
{ format: 'fcp-fiojson', label: 'FCP 10.4.0+', ext: 'FIOJSON' },
|
||||||
|
{ format: 'media-composer-xml', label: 'Media Composer', ext: 'XML' },
|
||||||
|
{ format: 'premiere-xml', label: 'Premiere Pro', ext: 'XML' },
|
||||||
|
{ format: 'resolve-edl', label: 'Resolve', ext: 'EDL' },
|
||||||
|
]
|
||||||
|
|
||||||
export function FileViewerRightSidebar({
|
export function FileViewerRightSidebar({
|
||||||
teamId,
|
teamId,
|
||||||
projectId,
|
projectId,
|
||||||
@@ -56,6 +79,7 @@ export function FileViewerRightSidebar({
|
|||||||
const { ref, inView } = useInView()
|
const { ref, inView } = useInView()
|
||||||
const [replyingTo, setReplyingTo] = useState<CommentInfo | null>(null)
|
const [replyingTo, setReplyingTo] = useState<CommentInfo | null>(null)
|
||||||
const [isGuestPopupOpen, setIsGuestPopupOpen] = useState(false)
|
const [isGuestPopupOpen, setIsGuestPopupOpen] = useState(false)
|
||||||
|
const [isExporting, setIsExporting] = useState(false)
|
||||||
const [pendingComment, setPendingComment] = useState<{
|
const [pendingComment, setPendingComment] = useState<{
|
||||||
text: string
|
text: string
|
||||||
attachmentIds: string[]
|
attachmentIds: string[]
|
||||||
@@ -64,6 +88,49 @@ export function FileViewerRightSidebar({
|
|||||||
second?: number | null
|
second?: number | null
|
||||||
} | null>(null)
|
} | null>(null)
|
||||||
|
|
||||||
|
const handleExportComments = async (format: CommentExportFormat) => {
|
||||||
|
if (!file?.id || isExporting) return
|
||||||
|
try {
|
||||||
|
setIsExporting(true)
|
||||||
|
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
|
const res = await client.api.files[':fileId'].comments.export.$post({
|
||||||
|
param: { fileId: file.id },
|
||||||
|
json: { format, timeZone },
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Failed to export comments')
|
||||||
|
}
|
||||||
|
|
||||||
|
const disposition = res.headers.get('content-disposition')
|
||||||
|
let filename = `${file.name || 'comments'}_comments`
|
||||||
|
if (disposition) {
|
||||||
|
const utf8Match = /filename\*=UTF-8''([^;]+)/i.exec(disposition)
|
||||||
|
const basicMatch = /filename="?([^";]+)"?/i.exec(disposition)
|
||||||
|
if (utf8Match?.[1]) {
|
||||||
|
filename = decodeURIComponent(utf8Match[1])
|
||||||
|
} else if (basicMatch?.[1]) {
|
||||||
|
filename = basicMatch[1]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const blob = await res.blob()
|
||||||
|
const downloadUrl = window.URL.createObjectURL(blob)
|
||||||
|
const link = document.createElement('a')
|
||||||
|
link.href = downloadUrl
|
||||||
|
link.download = filename
|
||||||
|
document.body.appendChild(link)
|
||||||
|
link.click()
|
||||||
|
document.body.removeChild(link)
|
||||||
|
window.URL.revokeObjectURL(downloadUrl)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to export comments:', error)
|
||||||
|
toast.error(m.failed_to_export_comments())
|
||||||
|
} finally {
|
||||||
|
setIsExporting(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const { data: apiFields } = useQuery({
|
const { data: apiFields } = useQuery({
|
||||||
queryKey: ['fields', projectId],
|
queryKey: ['fields', projectId],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
@@ -298,8 +365,47 @@ export function FileViewerRightSidebar({
|
|||||||
</TabsTrigger>
|
</TabsTrigger>
|
||||||
</TabsList>
|
</TabsList>
|
||||||
<TabsContent value="comments" className="flex-1 flex flex-col overflow-hidden min-h-0 mt-0">
|
<TabsContent value="comments" className="flex-1 flex flex-col overflow-hidden min-h-0 mt-0">
|
||||||
|
{!isPublic && (
|
||||||
|
<div className="flex items-center justify-between px-1 py-1.5 shrink-0 border-b border-border/50">
|
||||||
|
<span className="text-xs font-semibold text-foreground">{m.all_comments()}</span>
|
||||||
|
<DropdownMenu modal={false}>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
className="h-6 w-6 text-muted-foreground hover:text-foreground cursor-pointer"
|
||||||
|
aria-label={m.more_options()}
|
||||||
|
>
|
||||||
|
<MoreHorizontal className="size-4" />
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="end" className="w-48">
|
||||||
|
<DropdownMenuSub>
|
||||||
|
<DropdownMenuSubTrigger className="cursor-pointer">
|
||||||
|
<span>{m.export_comments()}</span>
|
||||||
|
</DropdownMenuSubTrigger>
|
||||||
|
<DropdownMenuSubContent className="w-56">
|
||||||
|
{COMMENT_EXPORT_OPTIONS.map((opt) => (
|
||||||
|
<DropdownMenuItem
|
||||||
|
key={opt.format}
|
||||||
|
className="flex items-center justify-between cursor-pointer"
|
||||||
|
disabled={isExporting}
|
||||||
|
onClick={() => handleExportComments(opt.format)}
|
||||||
|
>
|
||||||
|
<span>{opt.label}</span>
|
||||||
|
<span className="text-xs text-muted-foreground ml-auto pl-4">
|
||||||
|
{opt.ext}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
))}
|
||||||
|
</DropdownMenuSubContent>
|
||||||
|
</DropdownMenuSub>
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<ScrollArea className="flex-1 min-h-0 [&>div>div]:block!">
|
<ScrollArea className="flex-1 min-h-0 [&>div>div]:block!">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4 pt-2">
|
||||||
{comments.map((comment) => (
|
{comments.map((comment) => (
|
||||||
<div key={comment.id}>
|
<div key={comment.id}>
|
||||||
<MessageCard
|
<MessageCard
|
||||||
|
|||||||
@@ -1354,6 +1354,8 @@
|
|||||||
"linked_tasks_count": "{count} tasks",
|
"linked_tasks_count": "{count} tasks",
|
||||||
"current_project_label": "Current Project",
|
"current_project_label": "Current Project",
|
||||||
"all_comments": "All comments",
|
"all_comments": "All comments",
|
||||||
|
"export_comments": "Export Comments",
|
||||||
|
"failed_to_export_comments": "Failed to export comments",
|
||||||
"previous_file": "Previous file",
|
"previous_file": "Previous file",
|
||||||
"next_file": "Next file",
|
"next_file": "Next file",
|
||||||
"switch_version": "Switch version",
|
"switch_version": "Switch version",
|
||||||
|
|||||||
@@ -1354,6 +1354,8 @@
|
|||||||
"linked_tasks_count": "{count} 个任务",
|
"linked_tasks_count": "{count} 个任务",
|
||||||
"current_project_label": "当前项目",
|
"current_project_label": "当前项目",
|
||||||
"all_comments": "所有评论",
|
"all_comments": "所有评论",
|
||||||
|
"export_comments": "导出评论",
|
||||||
|
"failed_to_export_comments": "导出评论失败",
|
||||||
"previous_file": "上一个文件",
|
"previous_file": "上一个文件",
|
||||||
"next_file": "下一个文件",
|
"next_file": "下一个文件",
|
||||||
"switch_version": "切换版本",
|
"switch_version": "切换版本",
|
||||||
|
|||||||
Reference in New Issue
Block a user