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 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 const spriteLayoutSchema = z.object({ columns: z.number().int().positive(), rows: z.number().int().positive(), frameCount: z.number().int().positive(), }) export type SpriteLayout = z.infer const matchedSpriteSchema = spriteLayoutSchema.extend({ url: z.string() }) export type MatchedSprite = z.infer export const childPreviewSchema = z.object({ type: z.string().nullable(), preview: previewInfoSchema.nullable(), }) export type ChildPreview = z.infer export const assetUserInfoSchema = z.object({ id: z.string(), name: z.string(), image: z.string().optional(), }) export type AssetUserInfo = z.infer export const assetAgentInfoSchema = z.object({ id: z.string(), name: z.string(), }) export type AssetAgentInfo = z.infer export const fieldValueInfoSchema = z.object({ fieldId: z.string(), value: z.any(), }) export type FieldValueInfo = z.infer export const ancestorFolderSchema = z.object({ id: z.string(), name: z.string(), }) export type AncestorFolder = z.infer 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 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 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 export const getAssetRequestSchema = z.object({ assetId: z.string(), }) export type GetAssetRequest = z.infer export const updateAssetNameRequestSchema = z.object({ id: z.string(), name: z.string(), }) export type UpdateAssetNameRequest = z.infer export const assetTypeFilterSchema = z.enum(['file', 'folder', 'all']) export type AssetTypeFilter = z.infer 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 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 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 export const commentReactionCountSchema = z.object({ code: z.string(), count: z.number(), requestingUserReacted: z.boolean(), creatorNames: z.array(z.string()), }) export type CommentReactionCount = z.infer export const addCommentReactionRequestSchema = z.object({ code: z.string().min(1), }) export type AddCommentReactionRequest = z.infer export const removeCommentReactionRequestSchema = z.object({ code: z.string().min(1), }) export type RemoveCommentReactionRequest = z.infer 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 = 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 export const reparentAssetsRequestSchema = z.object({ newParentId: z.string(), assetIds: z.array(z.string()), creatorId: z.string().optional(), }) export type ReparentAssetsRequest = z.infer 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 export const updateFileRequestSchema = z.object({ name: z.string(), }) export type UpdateFileRequest = z.infer export const updateAssetOrderRequestSchema = z.object({ beforeIndex: z.string().optional(), afterIndex: z.string().optional(), }) export type UpdateAssetOrderRequest = z.infer export const deleteFilesRequestSchema = z.object({ ids: z.array(z.string()), }) export type DeleteFilesRequest = z.infer export const batchGetFilesRequestSchema = z.object({ ids: z.array(z.string()).max(100), }) export type BatchGetFilesRequest = z.infer export const restoreFilesRequestSchema = z.object({ ids: z.array(z.string()), }) export type RestoreFilesRequest = z.infer export const uploadFileRequestSchema = z.object({ file: z.instanceof(File), }) export type UploadFileRequest = z.infer export const uploadTeamFileResponseSchema = z.object({ key: z.string(), }) export type UploadTeamFileResponse = z.infer 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 export const postAttachmentResponseSchema = z.object({ id: z.string(), uploadUrl: z.string(), }) export type PostAttachmentResponse = z.infer export const getDownloadLinksRequestSchema = z.object({ ids: z.array(z.string()), }) export type GetDownloadLinksRequest = z.infer export const downloadLinkItemSchema = z.object({ id: z.string(), name: z.string(), url: z.string(), }) export type DownloadLinkItem = z.infer export const getDownloadLinksResponseSchema = z.object({ files: z.array(downloadLinkItemSchema), skippedArchivedCount: z.number().optional(), }) export type GetDownloadLinksResponse = z.infer export const getStoragePathsRequestSchema = z.object({ ids: z.array(z.string()).max(100), }) export type GetStoragePathsRequest = z.infer 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 export const getStoragePathsResponseSchema = z.object({ paths: z.array(storagePathItemSchema), }) export type GetStoragePathsResponse = z.infer export const archiveAssetsRequestSchema = z.object({ ids: z.array(z.string().min(1)).min(1), }) export type ArchiveAssetsRequest = z.infer export const archiveAssetsResponseSchema = z.object({ archivedAssetIds: z.array(z.string()), taskIds: z.array(z.string()), skippedCount: z.number(), }) export type ArchiveAssetsResponse = z.infer export const restoreArchivedAssetsRequestSchema = z.object({ ids: z.array(z.string().min(1)).min(1), }) export type RestoreArchivedAssetsRequest = z.infer export const restoreArchivedAssetsResponseSchema = z.object({ restoredAssetIds: z.array(z.string()), taskIds: z.array(z.string()), skippedCount: z.number(), }) export type RestoreArchivedAssetsResponse = z.infer export const commentExportFormatSchema = z.enum([ 'fcp-fiojson', 'media-composer-xml', 'premiere-xml', 'resolve-edl', ]) export type CommentExportFormat = z.infer 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 /** @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 export const printCommentsResponseSchema = z.object({ asset: assetInfoSchema, breadcrumbs: z.array(z.string()), comments: z.array(commentInfoSchema), }) export type PrintCommentsResponse = z.infer