feat(api): remove mediaType and mimeType from DTO responses and DB MediaInfo interface

This commit is contained in:
yiling
2026-07-20 14:37:17 +08:00
parent 5d4020dc2d
commit 3afe0fc3c3
19 changed files with 37 additions and 48 deletions
+3 -3
View File
@@ -79,7 +79,7 @@ describe('file api', () => {
fileCount: 1,
type: 'file',
status: 'active',
mediaType: 'image/jpeg',
proxyType: 'image',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@@ -107,7 +107,7 @@ describe('file api', () => {
fileCount: 1,
type: 'file',
status: 'active',
mediaType: 'image/jpeg',
proxyType: 'image',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@@ -500,7 +500,7 @@ describe('file api', () => {
fileCount: 1,
type: 'file',
status: 'active',
mediaType: 'image/jpeg',
proxyType: 'image',
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
-6
View File
@@ -53,7 +53,6 @@ describe('folder api', () => {
fileCount: 1,
type: 'folder',
status: 'active',
mediaType: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@@ -81,7 +80,6 @@ describe('folder api', () => {
fileCount: 1,
type: 'folder',
status: 'active',
mediaType: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@@ -113,7 +111,6 @@ describe('folder api', () => {
fileCount: 0,
type: 'folder',
status: 'active',
mediaType: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
@@ -147,7 +144,6 @@ describe('folder api', () => {
fileCount: 0,
type: 'folder',
status: 'active',
mediaType: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
@@ -223,7 +219,6 @@ describe('folder api', () => {
fileCount: 0,
type: 'folder',
status: 'active',
mediaType: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
},
@@ -261,7 +256,6 @@ describe('folder api', () => {
fileCount: 1,
type: 'folder',
status: 'active',
mediaType: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
})
+5 -2
View File
@@ -1475,6 +1475,7 @@ describe('AssetService', () => {
mediaType: 'video/mp4',
status: 'processed',
media: {
proxyType: 'video',
poster: { key: 'poster-key' },
metadata: { duration: 262 },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1485,7 +1486,7 @@ describe('AssetService', () => {
const info = await assetService.getAsset({ assetId: video.id })
expect(info.preview).toBeDefined()
expect(info.preview?.mediaType).toBe('video/mp4')
expect(info.preview?.proxyType).toBe('video')
expect(info.preview?.duration).toBe(262)
})
@@ -1502,6 +1503,7 @@ describe('AssetService', () => {
mediaType: 'image/png',
status: 'processed',
media: {
proxyType: 'image',
thumbnail: { key: 'thumb-key' },
metadata: { originalWidth: 100, originalHeight: 80 },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1530,6 +1532,7 @@ describe('AssetService', () => {
mediaType: 'image/png',
status: 'processed',
media: {
proxyType: 'image',
thumbnail: { key: 'thumb-key' },
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
@@ -1554,7 +1557,7 @@ describe('AssetService', () => {
expect(info.type).toBe(AssetType.symlink)
// Resolved from target
expect(info.sizeByte).toBe(5000)
expect(info.mediaType).toBe('image/png')
expect(info.proxyType).toBe('image')
expect(info.media).toBeDefined()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((info.media as any).thumbnail?.key).toBe('thumb-key')
-3
View File
@@ -1735,7 +1735,6 @@ export class AssetService {
type: a.type,
targetType: a.type === AssetType.symlink ? a.target?.type : null,
status: latestVersion.status,
mediaType: latestVersion.mediaType,
proxyType,
latestChildren,
preview,
@@ -2027,7 +2026,6 @@ export class AssetService {
}
return {
mediaType: asset.mediaType,
proxyType,
thumbnailUrl,
originalHeight: asset.media.metadata?.originalHeight,
@@ -2067,7 +2065,6 @@ export class AssetService {
id: a.id,
assetId: a.asset.id,
url,
mediaType: a.asset.mediaType,
proxyType: attachmentProxyType,
})
}
@@ -401,7 +401,6 @@ export class NotificationService {
info.asset = {
id: a.id,
name: a.name,
mediaType: a.mediaType || undefined,
proxyType: (a.media as PrismaJson.MediaInfo | null)?.proxyType || undefined,
preview: previewUrl || undefined,
thumbnailUrl: thumbnailUrl || undefined,
-1
View File
@@ -143,7 +143,6 @@ declare global {
thumbnail?: ImageTranscode
finishedAt: string
metadata: Metadata | null
mimeType: string
original: OriginalInfo | null
}
-4
View File
@@ -8,7 +8,6 @@ export const assetInfoPaginatedListSchema = z.object({
export type AssetInfoPaginatedList = z.infer<typeof assetInfoPaginatedListSchema>
export const previewInfoSchema = z.object({
mediaType: z.string().nullable(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
thumbnailUrl: z.string().optional(),
originalHeight: z.number().optional(),
@@ -63,7 +62,6 @@ export const assetInfoSchema = z.object({
type: z.string(),
targetType: z.string().optional().nullable(),
status: z.string(),
mediaType: z.string().nullable(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
latestChildren: z.array(childPreviewSchema).optional(),
preview: previewInfoSchema.nullable().optional(),
@@ -108,7 +106,6 @@ export const assetInfoSchema = z.object({
.optional(),
videoPreview: z.object({ url: z.string(), key: z.string().optional() }).optional(),
pdfTranscode: z.object({ url: z.string(), key: z.string().optional() }).optional(),
mimeType: z.string().optional(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
metadata: mediaMetadataSchema.optional(),
})
@@ -191,7 +188,6 @@ export const attachmentInfoSchema = z.object({
id: z.string(),
assetId: z.string(),
url: z.string(),
mediaType: z.string().nullable(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
})
export type AttachmentInfo = z.infer<typeof attachmentInfoSchema>
-1
View File
@@ -18,7 +18,6 @@ export type EntityInfo = z.infer<typeof entityInfoSchema>
export const assetPreviewSchema = z.object({
id: z.string().optional(),
mediaType: z.string().optional(),
proxyType: z.enum(['image', 'video', 'audio', 'pdf']).nullable().optional(),
name: z.string().optional(),
preview: z.string().optional(),
+8 -8
View File
@@ -128,14 +128,14 @@ describe.each(['local', 'temporal'] as const)(
// Verify media info contains videoTranscodes, poster, sprite, and duration details
const mediaInfo = updatedAsset?.media as unknown as {
mimeType: string
proxyType: string
duration: number
videoTranscodes: { key: string }[]
poster: unknown
sprite: unknown
}
expect(mediaInfo).toBeDefined()
expect(mediaInfo.mimeType).toBe('video/mp4')
expect(mediaInfo.proxyType).toBe('video')
expect(mediaInfo.duration).toBeCloseTo(1.0, 1)
expect(mediaInfo.videoTranscodes).toBeDefined()
expect(mediaInfo.videoTranscodes.length).toBeGreaterThan(0)
@@ -213,12 +213,12 @@ describe.each(['local', 'temporal'] as const)(
expect(updatedAsset?.status).toBe(AssetStatus.processed)
const mediaInfo = updatedAsset?.media as unknown as {
mimeType: string
proxyType: string
imageTranscodes: unknown[]
thumbnail: unknown
}
expect(mediaInfo).toBeDefined()
expect(mediaInfo.mimeType).toBe('image/png')
expect(mediaInfo.proxyType).toBe('image')
expect(mediaInfo.imageTranscodes).toBeDefined()
expect(mediaInfo.imageTranscodes.length).toBeGreaterThan(0)
expect(mediaInfo.thumbnail).toBeDefined()
@@ -292,11 +292,11 @@ describe.each(['local', 'temporal'] as const)(
expect(updatedAsset?.status).toBe(AssetStatus.processed)
const mediaInfo = updatedAsset?.media as unknown as {
mimeType: string
proxyType: string
videoTranscodes: { key: string }[]
}
expect(mediaInfo).toBeDefined()
expect(mediaInfo.mimeType).toBe('audio/wav')
expect(mediaInfo.proxyType).toBe('audio')
expect(mediaInfo.videoTranscodes).toBeDefined()
expect(mediaInfo.videoTranscodes.length).toBeGreaterThan(0)
// Audio proxy key should end with -audio-proxy.mp4
@@ -529,7 +529,7 @@ describe.each(['local', 'temporal'] as const)(
// Verify media info contains pdf details, poster, sprite, and pageCount
const mediaInfo = updatedAsset?.media as unknown as {
mimeType: string
proxyType: string
poster: { key: string }
sprite: { key: string }
frames?: number
@@ -537,7 +537,7 @@ describe.each(['local', 'temporal'] as const)(
metadata?: { totalFrames?: number; pageCount?: number }
}
expect(mediaInfo).toBeDefined()
expect(mediaInfo.mimeType).toBe('application/pdf')
expect(mediaInfo.proxyType).toBe('pdf')
expect(mediaInfo.poster).toBeDefined()
expect(mediaInfo.poster.key).toContain('poster.webp')
expect(mediaInfo.sprite).toBeDefined()
@@ -73,7 +73,6 @@ export async function getMediaInfoActivity(params: {
videoPreview: { width: 0, height: 0 },
finishedAt: new Date().toISOString(),
metadata: null,
mimeType: params.mediaType || '',
original: {
key: '', // Will be filled by caller or updated later
downloadUrl: '',
@@ -428,7 +427,7 @@ export async function generateSpriteActivity(params: GenerateSpriteActivityParam
const posterFile = path.join(tmpDir, 'poster.webp')
try {
if (params.mediaInfo.proxyType === 'pdf' || params.mediaInfo.mimeType === 'application/pdf') {
if (params.mediaInfo.proxyType === 'pdf') {
const pdfRes = await transcodeService.generatePdfSprite(
params.filePath,
spriteFile,
@@ -54,12 +54,10 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
codec: '',
}
const mimeType = mediaInfo.mimeType
const metadata = mediaInfo.metadata
const isImage = mimeType.startsWith('image/')
const isPsd = isMimePsd(mimeType)
if ((isImage || isPsd) && metadata) {
const isImage = mediaInfo.proxyType === 'image'
if (isImage && metadata) {
const imageSpec: PrismaJson.ImageTranscode = {
width: metadata.originalWidth,
height: metadata.originalHeight,
@@ -58,10 +58,9 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
codec: '',
}
const mimeType = mediaInfo.mimeType
const metadata = mediaInfo.metadata
if (mimeType.startsWith('video/') && metadata) {
if (mediaInfo.proxyType === 'video' && metadata) {
const videoResolutions = getTargetVideoResolutions(
spec.videoStrategy || 'best_match',
metadata.originalWidth,
@@ -103,7 +102,7 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
})
}
const isAudio = mimeType.startsWith('audio/')
const isAudio = mediaInfo.proxyType === 'audio'
if (isAudio && metadata) {
const audioTranscode = await executeActivity(workerQueue, transcodeAudioActivity, {
assetKey: key,
@@ -50,7 +50,6 @@ interface BreadcrumbNavProps {
name?: string
type: 'file' | 'folder'
version?: number
mediaType?: string | null
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | null
}
isRootFolder: boolean
@@ -513,10 +513,20 @@ export function FileBrowser({
fileCount: 0,
type: 'file',
status: hasUrl ? 'uploading' : 'error',
mediaType:
proxyType:
f.file.name.toLowerCase().endsWith('.wma') && f.file.type?.startsWith('video/')
? f.file.type.replace(/^video\//, 'audio/')
: f.file.type || null,
? 'audio'
: f.file.type?.startsWith('image/')
? 'image'
: f.file.type?.startsWith('video/')
? 'video'
: f.file.type?.startsWith('audio/')
? 'audio'
: f.file.name.endsWith('.pdf') ||
f.file.name.endsWith('.txt') ||
f.file.name.endsWith('.csv')
? 'pdf'
: null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
}
@@ -487,7 +487,6 @@ export function FolderTree({
sizeByte: 0,
fileCount: 0,
status: 'processed',
mediaType: null,
createdAt: '',
updatedAt: '',
}}
@@ -412,7 +412,7 @@ export function PublicShareManager({
? (stackFileData.versionStack.versions.find((v) => v.id === activeFileId)?.version ??
stackFileData.versionStack.versions.length)
: undefined,
mediaType: viewingFileData?.mediaType || null,
proxyType: viewingFileData?.proxyType || null,
},
isRootFolder: currentFolderId === shareInfo.rootFolderId && !viewingFileId,
isPublic: true,
-2
View File
@@ -31,7 +31,6 @@ export const sampleVideoAsset: AssetInfo = {
fileCount: 1,
type: 'file',
status: 'ready',
mediaType: 'video',
proxyType: 'video',
createdAt: '2024-01-01T00:00:00.000Z',
updatedAt: '2024-01-01T00:00:00.000Z',
@@ -151,7 +150,6 @@ export const sampleAudioAsset: AssetInfo = {
...sampleVideoAsset,
id: 'e2e-sample-audio-asset',
name: 'sample-audio.mp4',
mediaType: 'audio/mp4',
proxyType: 'audio',
media: {
proxyType: 'audio',
@@ -161,7 +161,7 @@ function FileViewPage() {
? (versionsDataList.find((v: { id: string }) => v.id === activeFileId)?.version ??
versionsDataList.length)
: undefined,
mediaType: fileData.mediaType,
proxyType: fileData.proxyType,
},
isRootFolder: false,
fileId,
+1 -1
View File
@@ -10,7 +10,7 @@ export interface TopNavProjectState {
name?: string
type: 'file' | 'folder'
version?: number
mediaType?: string | null
proxyType?: 'image' | 'video' | 'audio' | 'pdf' | null
}
isRootFolder: boolean
fileId?: string