Files
shumai/packages/dtos/src/asset.ts
T
Yiling-J 624a3a6a54 feat(webui): remove original-file display fallbacks, use proxies only (#273)
* feat(webui): remove original-file display fallbacks, use proxies only

WebUI now never uses the raw original file for display. All viewers
(image, video, compare, pdf) render exclusively from transcoded proxies;
when no proxy exists the viewer shows an unavailable placeholder instead
of falling back to media.original.

- getBestTranscode: drop the isRaw fallback candidates
- video-viewer / compare-video-pane: remove the synthetic 'Original'
  resolution entry and the original.downloadUrl hasMedia gate
- image-viewer / compare-image-pane: remove original.downloadUrl default
- pdf-viewer: require pdfTranscode.url (no original fallback)
- download menus (video-control-bar, breadcrumb-nav): use
  media.original.key for the 'Original' download option instead of the
  isRaw transcode marker entry

Backend:
- transcode-video workflow no longer pushes the isRaw:true marker entry
  into videoTranscodes (it pointed at the original file key)
- remove media.original.downloadUrl from the DTO, asset service mapping,
  MediaInfo DB type, and transcode workflows/activities (it was only
  consumed by the removed display fallbacks; downloads already use key
  via the download-url endpoints)

Tests/fixtures updated; docs updated to state the proxy-only display
policy.

* refactor: remove isRaw field via data migration, clean legacy media JSON

Add a Prisma data migration that cleans legacy media JSONB on both
assets and watermark_files:
- drop the raw-original marker entries (isRaw: true) from
  videoTranscodes / imageTranscodes — they pointed at the original file
  key and were only used by the removed display fallbacks / download
  menus, which now use media.original.key directly
- strip the isRaw field from remaining transcode entries
- drop original.downloadUrl (removed from the AssetInfo DTO)

The migration is generated via prisma migrate dev --create-only and
applied automatically by migrate deploy in production. It is guarded by
a test (packages/db/src/clean-media-migration.test.ts) that seeds legacy
media JSON, runs the migration SQL, and asserts the transform on both
tables.

With the data cleaned, remove the isRaw field entirely from the codebase:
- DTO schemas + ImageTranscode/VideoTranscode interfaces
- PrismaJson MediaInfo transcode types
- watermark activity isRaw skip (and its test), watermark proxy mapping,
  agent-embedding transcode selection, webui transcode filters, and all
  test fixtures

AGENTS.md: clarify that the no-manual-migration rule applies to DDL;
data migrations (pure SQL transforms, no schema change) are allowed
inside a --create-only generated migration and must be tested.
2026-08-07 22:40:06 +08:00

326 lines
9.6 KiB
TypeScript

import { z } from 'zod'
import { paginationPageInfoSchema, paginationParamsSchema } from './pagination'
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']).nullable().optional(),
thumbnailUrl: z.string().optional(),
originalHeight: z.number().optional(),
originalWidth: 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 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(),
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']).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(),
fieldValues: z.array(fieldValueInfoSchema).optional(),
sortIndex: z.string().optional().nullable(),
startTime: z.number().optional().nullable(),
endTime: z.number().optional().nullable(),
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(),
}),
)
.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(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
metadata: mediaMetadataSchema.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(),
creator: z
.object({
id: z.string(),
name: z.string().nullable(),
})
.nullable()
.optional(),
}),
),
})
.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(),
})
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 listChildrenRequestSchema = z.object({
assetId: z.string().optional(),
assetType: z.string(),
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']).nullable().optional(),
})
export type AttachmentInfo = z.infer<typeof attachmentInfoSchema>
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
}
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(),
})
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
}
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>