Files
shumai/packages/dtos/src/asset.ts
T
Yiling-J 5a1655e4ef feat(comments): add printable comments page with frame thumbnails and markup overlays (#550)
* feat(comments): add printable comments page with frame thumbnails and markup overlays

* fix(comments): guarantee frame-accurate ffmpeg seeking for printable comment thumbnails

* fix(comments): address printable comments review findings
2026-11-25 19:53:39 +08:00

503 lines
16 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>
const spriteLayoutSchema = z.object({
columns: z.number().int().positive(),
rows: z.number().int().positive(),
frameCount: z.number().int().positive(),
})
export type SpriteLayout = z.infer<typeof spriteLayoutSchema>
const matchedSpriteSchema = spriteLayoutSchema.extend({ url: z.string() })
export type MatchedSprite = z.infer<typeof matchedSpriteSchema>
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(),
matchedSprite: matchedSpriteSchema.optional(),
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(),
status: 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 batchGetFilesRequestSchema = z.object({
ids: z.array(z.string()).max(100),
})
export type BatchGetFilesRequest = z.infer<typeof batchGetFilesRequestSchema>
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),
skippedArchivedCount: z.number().optional(),
})
export type GetDownloadLinksResponse = z.infer<typeof getDownloadLinksResponseSchema>
export const getStoragePathsRequestSchema = z.object({
ids: z.array(z.string()).max(100),
})
export type GetStoragePathsRequest = z.infer<typeof getStoragePathsRequestSchema>
export const storagePathItemSchema = z.object({
id: z.string(),
name: z.string(),
path: z.string(),
backend: z.enum(['s3', 'local']),
isArchived: z.boolean(),
})
export type StoragePathItem = z.infer<typeof storagePathItemSchema>
export const getStoragePathsResponseSchema = z.object({
paths: z.array(storagePathItemSchema),
})
export type GetStoragePathsResponse = z.infer<typeof getStoragePathsResponseSchema>
export const archiveAssetsRequestSchema = z.object({
ids: z.array(z.string().min(1)).min(1),
})
export type ArchiveAssetsRequest = z.infer<typeof archiveAssetsRequestSchema>
export const archiveAssetsResponseSchema = z.object({
archivedAssetIds: z.array(z.string()),
taskIds: z.array(z.string()),
skippedCount: z.number(),
})
export type ArchiveAssetsResponse = z.infer<typeof archiveAssetsResponseSchema>
export const restoreArchivedAssetsRequestSchema = z.object({
ids: z.array(z.string().min(1)).min(1),
})
export type RestoreArchivedAssetsRequest = z.infer<typeof restoreArchivedAssetsRequestSchema>
export const restoreArchivedAssetsResponseSchema = z.object({
restoredAssetIds: z.array(z.string()),
taskIds: z.array(z.string()),
skippedCount: z.number(),
})
export type RestoreArchivedAssetsResponse = z.infer<typeof restoreArchivedAssetsResponseSchema>
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
export const commentFrameQuerySchema = z.object({
second: z.coerce.number().refine((val) => Number.isFinite(val) && val >= 0, {
message: 'second must be a non-negative finite number',
}),
width: z.coerce.number().int().min(64).max(1280).optional().default(400),
})
export type CommentFrameQuery = z.infer<typeof commentFrameQuerySchema>
export const printCommentsResponseSchema = z.object({
asset: assetInfoSchema,
breadcrumbs: z.array(z.string()),
comments: z.array(commentInfoSchema),
})
export type PrintCommentsResponse = z.infer<typeof printCommentsResponseSchema>