Files
shumai/packages/dtos/src/asset.ts
T
Yiling-J 43a2eced75 feat(transcode): add 3D asset support and turntable viewer (#454)
* feat(transcode): add 3D asset support and turntable viewer

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

* fix(viewer): download original 3D model file instead of rendered turntable MP4
2026-10-11 21:32:28 +08:00

427 lines
13 KiB
TypeScript

import { z } from 'zod'
import { paginationPageInfoSchema, paginationParamsSchema } from './pagination'
/**
* Number of days a soft-deleted asset is kept before it is permanently purged.
* Shared between the backend retention logic and the WebUI countdown labels.
*/
export const TRASH_RETENTION_DAYS = 30
export const assetInfoPaginatedListSchema = z.object({
data: z.array(z.lazy(() => assetInfoSchema)),
pageInfo: paginationPageInfoSchema,
})
export type AssetInfoPaginatedList = z.infer<typeof assetInfoPaginatedListSchema>
export const previewInfoSchema = z.object({
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
thumbnailUrl: z.string().optional(),
originalHeight: z.number().optional(),
originalWidth: z.number().optional(),
rotation: z.number().optional(),
spriteUrl: z.string().optional(),
duration: z.number().optional(),
pageCount: z.number().optional(),
})
export type PreviewInfo = z.infer<typeof previewInfoSchema>
export const childPreviewSchema = z.object({
type: z.string().nullable(),
preview: previewInfoSchema.nullable(),
})
export type ChildPreview = z.infer<typeof childPreviewSchema>
export const assetUserInfoSchema = z.object({
id: z.string(),
name: z.string(),
image: z.string().optional(),
})
export type AssetUserInfo = z.infer<typeof assetUserInfoSchema>
export const assetAgentInfoSchema = z.object({
id: z.string(),
name: z.string(),
})
export type AssetAgentInfo = z.infer<typeof assetAgentInfoSchema>
export const fieldValueInfoSchema = z.object({
fieldId: z.string(),
value: z.any(),
})
export type FieldValueInfo = z.infer<typeof fieldValueInfoSchema>
export const ancestorFolderSchema = z.object({
id: z.string(),
name: z.string(),
})
export type AncestorFolder = z.infer<typeof ancestorFolderSchema>
export const mediaMetadataSchema = z.object({
duration: z.number().optional(),
originalWidth: z.number().optional(),
originalHeight: z.number().optional(),
rotation: z.number().optional(),
frameRate: z.number().optional(),
totalFrames: z.number().optional(),
startTimecode: z.string().optional(),
})
export type MediaMetadata = z.infer<typeof mediaMetadataSchema>
export const assetInfoSchema = z.object({
id: z.string(),
name: z.string(),
sizeByte: z.number(),
fileCount: z.number(),
type: z.string(),
targetType: z.string().optional().nullable(),
status: z.string(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
latestChildren: z.array(childPreviewSchema).optional(),
preview: previewInfoSchema.nullable().optional(),
createdAt: z.string(),
updatedAt: z.string(),
deletedAt: z.string().nullable().optional(),
projectId: z.string().optional().nullable(),
creator: assetUserInfoSchema.nullable().optional(),
agentId: z.string().optional().nullable(),
agent: assetAgentInfoSchema.optional().nullable(),
fieldValues: z.array(fieldValueInfoSchema).optional(),
sortIndex: z.string().optional().nullable(),
startTime: z.number().optional().nullable(),
endTime: z.number().optional().nullable(),
hasAgentsMd: z.boolean().optional(),
commentsCount: z.number().optional(),
media: z
.object({
original: z.object({ key: z.string().optional() }).optional(),
videoTranscodes: z
.array(
z.object({
id: z.string(),
url: z.string(),
key: z.string(),
width: z.number(),
height: z.number(),
size: z.number(),
resolution: z.string().optional(),
hdr: z.boolean().optional(),
}),
)
.optional(),
imageTranscodes: z
.array(
z.object({
id: z.string(),
url: z.string(),
key: z.string(),
width: z.number(),
height: z.number(),
size: z.number(),
}),
)
.optional(),
videoPreview: z.object({ url: z.string(), key: z.string().optional() }).optional(),
pdfTranscode: z.object({ url: z.string(), key: z.string().optional() }).optional(),
isHls: z.boolean().optional(),
hls: z
.object({
key: z.string(),
url: z.string().optional(),
resolutions: z
.array(
z.object({
width: z.number(),
height: z.number(),
resolution: z.string().optional(),
hdr: z.boolean().optional(),
key: z.string().optional(),
url: z.string().optional(),
}),
)
.optional(),
})
.optional(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
metadata: mediaMetadataSchema.optional(),
error: z.string().optional(),
})
.optional(),
ancestorFolders: z.array(ancestorFolderSchema).optional(),
versionStack: z
.object({
id: z.string(),
versions: z.array(
z.object({
version: z.number(),
current: z.boolean(),
id: z.string(),
name: z.string().optional().nullable(),
previewUrl: z.string().optional().nullable(),
createdAt: z.string().optional().nullable(),
creator: z
.object({
id: z.string(),
name: z.string().nullable(),
image: z.string().optional().nullable(),
})
.nullable()
.optional(),
agent: assetAgentInfoSchema.optional().nullable(),
}),
),
})
.optional()
.nullable(),
})
export type AssetInfo = z.infer<typeof assetInfoSchema>
export const createAssetRequestSchema = z.object({
name: z.string(),
type: z.string(),
projectId: z.string().optional(),
parentId: z.string().optional(),
key: z.string().optional(),
sizeByte: z.number().optional(),
contentType: z.string().optional(),
creatorId: z.string().optional(),
agentId: z.string().optional(),
})
export type CreateAssetRequest = z.infer<typeof createAssetRequestSchema>
export const getAssetRequestSchema = z.object({
assetId: z.string(),
})
export type GetAssetRequest = z.infer<typeof getAssetRequestSchema>
export const updateAssetNameRequestSchema = z.object({
id: z.string(),
name: z.string(),
})
export type UpdateAssetNameRequest = z.infer<typeof updateAssetNameRequestSchema>
export const assetTypeFilterSchema = z.enum(['file', 'folder', 'all'])
export type AssetTypeFilter = z.infer<typeof assetTypeFilterSchema>
export const listChildrenRequestSchema = z.object({
assetId: z.string().optional(),
assetType: assetTypeFilterSchema.optional().default('all'),
projectId: z.string().optional(),
showDeleted: z.boolean().optional(),
prefix: z.string().optional(),
sort: z.string().optional(),
order: z.string().optional(),
// pagination props mixed in via merge
...paginationParamsSchema.shape,
})
export type ListChildrenRequest = z.infer<typeof listChildrenRequestSchema>
export const createCommentRequestSchema = z.object({
assetId: z.string(),
userId: z.string(),
replyToId: z.string().optional(),
message: z.string(),
annotations: z.any().optional(),
second: z.number().optional(),
attachmentIds: z.array(z.string()),
})
export type CreateCommentRequest = z.infer<typeof createCommentRequestSchema>
export const attachmentInfoSchema = z.object({
id: z.string(),
assetId: z.string(),
url: z.string(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf', '3d']).nullable().optional(),
})
export type AttachmentInfo = z.infer<typeof attachmentInfoSchema>
export const commentReactionCountSchema = z.object({
code: z.string(),
count: z.number(),
requestingUserReacted: z.boolean(),
creatorNames: z.array(z.string()),
})
export type CommentReactionCount = z.infer<typeof commentReactionCountSchema>
export const addCommentReactionRequestSchema = z.object({
code: z.string().min(1),
})
export type AddCommentReactionRequest = z.infer<typeof addCommentReactionRequestSchema>
export const removeCommentReactionRequestSchema = z.object({
code: z.string().min(1),
})
export type RemoveCommentReactionRequest = z.infer<typeof removeCommentReactionRequestSchema>
export type CommentInfo = {
id: string
assetId: string
message: string | null
// eslint-disable-next-line @typescript-eslint/no-explicit-any
annotations: any
second: number | null
creator: AssetUserInfo
replies: CommentInfo[]
attachments: AttachmentInfo[]
mentions: AssetUserInfo[]
createdAt: string
updatedAt: string
sessionId: string | null
isCompleted: boolean
completionLastChangedBy: AssetUserInfo | null
reactionCounts: CommentReactionCount[]
}
export const commentInfoSchema: z.ZodType<CommentInfo> = z.object({
id: z.string(),
assetId: z.string(),
message: z.string().nullable(),
annotations: z.any(),
second: z.number().nullable(),
creator: assetUserInfoSchema,
replies: z.array(z.lazy(() => commentInfoSchema)),
attachments: z.array(attachmentInfoSchema),
mentions: z.array(assetUserInfoSchema),
createdAt: z.string(),
updatedAt: z.string(),
sessionId: z.string().nullable(),
isCompleted: z.boolean(),
completionLastChangedBy: assetUserInfoSchema.nullable(),
reactionCounts: z.array(commentReactionCountSchema),
})
export const completeCommentRequestSchema = z.object({
isCompleted: z.boolean(),
})
export type CompleteCommentRequest = z.infer<typeof completeCommentRequestSchema>
export const reparentAssetsRequestSchema = z.object({
newParentId: z.string(),
assetIds: z.array(z.string()),
creatorId: z.string().optional(),
})
export type ReparentAssetsRequest = z.infer<typeof reparentAssetsRequestSchema>
export const copyAssetsRequestSchema = z.object({
newParentId: z.string(),
assetIds: z.array(z.string()),
withComments: z.boolean().default(false),
creatorId: z.string().optional(),
})
export type CopyAssetsRequest = z.infer<typeof copyAssetsRequestSchema>
export const updateFileRequestSchema = z.object({
name: z.string(),
})
export type UpdateFileRequest = z.infer<typeof updateFileRequestSchema>
export const updateAssetOrderRequestSchema = z.object({
beforeIndex: z.string().optional(),
afterIndex: z.string().optional(),
})
export type UpdateAssetOrderRequest = z.infer<typeof updateAssetOrderRequestSchema>
export const deleteFilesRequestSchema = z.object({
ids: z.array(z.string()),
})
export type DeleteFilesRequest = z.infer<typeof deleteFilesRequestSchema>
export const restoreFilesRequestSchema = z.object({
ids: z.array(z.string()),
})
export type RestoreFilesRequest = z.infer<typeof restoreFilesRequestSchema>
export const uploadFileRequestSchema = z.object({
file: z.instanceof(File),
})
export type UploadFileRequest = z.infer<typeof uploadFileRequestSchema>
export const uploadTeamFileResponseSchema = z.object({
key: z.string(),
})
export type UploadTeamFileResponse = z.infer<typeof uploadTeamFileResponseSchema>
export interface ImageTranscode {
id: string
url: string
width: number
height: number
size: number
}
export interface VideoTranscode {
id: string
url: string
key: string
width: number
height: number
size: number
resolution?: string
hdr?: boolean
}
export const postAttachmentRequestSchema = z.object({
fileName: z.string(),
contentType: z.string(),
size: z.number(),
})
export type PostAttachmentRequest = z.infer<typeof postAttachmentRequestSchema>
export const postAttachmentResponseSchema = z.object({
id: z.string(),
uploadUrl: z.string(),
})
export type PostAttachmentResponse = z.infer<typeof postAttachmentResponseSchema>
export const getDownloadLinksRequestSchema = z.object({
ids: z.array(z.string()),
})
export type GetDownloadLinksRequest = z.infer<typeof getDownloadLinksRequestSchema>
export const downloadLinkItemSchema = z.object({
id: z.string(),
name: z.string(),
url: z.string(),
})
export type DownloadLinkItem = z.infer<typeof downloadLinkItemSchema>
export const getDownloadLinksResponseSchema = z.object({
files: z.array(downloadLinkItemSchema),
})
export type GetDownloadLinksResponse = z.infer<typeof getDownloadLinksResponseSchema>
export const commentExportFormatSchema = z.enum([
'fcp-fiojson',
'media-composer-xml',
'premiere-xml',
'resolve-edl',
])
export type CommentExportFormat = z.infer<typeof commentExportFormatSchema>
export const exportCommentsRequestSchema = z.object({
format: commentExportFormatSchema,
timeZone: z
.string()
.refine(
(tz) => {
try {
Intl.DateTimeFormat(undefined, { timeZone: tz })
return true
} catch {
return false
}
},
{ message: 'Invalid IANA time zone identifier' },
)
.optional(),
})
export type ExportCommentsRequest = z.infer<typeof exportCommentsRequestSchema>
/** @deprecated Use exportCommentsRequestSchema */
export const exportCommentsQuerySchema = exportCommentsRequestSchema
/** @deprecated Use ExportCommentsRequest */
export type ExportCommentsQuery = ExportCommentsRequest