mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 22:49:30 +00:00
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.
This commit is contained in:
@@ -75,7 +75,6 @@ export async function getMediaInfoActivity(params: {
|
||||
metadata: null,
|
||||
original: {
|
||||
key: '', // Will be filled by caller or updated later
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
},
|
||||
|
||||
@@ -213,7 +213,6 @@ describe('Watermark Activities', () => {
|
||||
},
|
||||
original: {
|
||||
key,
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
},
|
||||
@@ -295,66 +294,6 @@ describe('Watermark Activities', () => {
|
||||
fs.rmSync(outFilePath, { force: true })
|
||||
})
|
||||
|
||||
it('skips the raw (isRaw) video transcode when generating watermark proxies', async () => {
|
||||
const assetKey = 'files/e2e-wm/raw-video.mp4'
|
||||
const asset = await seedAsset('raw-video.mp4', 'video/mp4', assetKey, 'video')
|
||||
const config = await seedConfig()
|
||||
|
||||
// Simulate the media state produced by transcodeVideoWorkflow: a
|
||||
// transcoded proxy plus a raw marker entry pointing at the original file.
|
||||
await prisma.asset.update({
|
||||
where: { id: asset.id },
|
||||
data: {
|
||||
media: {
|
||||
...(asset.media as PrismaJson.MediaInfo),
|
||||
videoTranscodes: [
|
||||
{ key: assetKey, width: 100, height: 100, resolution: '100p' },
|
||||
{ key: assetKey, width: 1920, height: 1080, isRaw: true },
|
||||
],
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
vi.mocked(transcodeService.getVideoInfo).mockResolvedValue({
|
||||
originalWidth: 1920,
|
||||
originalHeight: 1080,
|
||||
duration: 10,
|
||||
bitRate: 1000,
|
||||
frameRate: 30,
|
||||
totalFrames: 300,
|
||||
startTimecode: '00:00:00:00',
|
||||
hasAudio: true,
|
||||
mimeType: 'video/mp4',
|
||||
})
|
||||
vi.mocked(s3Service.putObject).mockResolvedValue(undefined as never)
|
||||
|
||||
// The ffmpeg execFile call is mocked, but the activity stats the output
|
||||
// file afterwards, so pre-create both expected output paths.
|
||||
const stem = 'raw-video'
|
||||
const configId = config.id
|
||||
const proxyOutFilePath = path.join('/tmp', `${stem}-watermark-${configId}-100p.mp4`)
|
||||
const rawOutFilePath = path.join('/tmp', `${stem}-watermark-${configId}-1080p.mp4`)
|
||||
fs.writeFileSync(proxyOutFilePath, Buffer.from('fake mp4'))
|
||||
fs.writeFileSync(rawOutFilePath, Buffer.from('fake mp4'))
|
||||
|
||||
try {
|
||||
const media = await transcodeWatermarkMediaActivity({
|
||||
assetId: asset.id,
|
||||
watermarkConfigId: config.id,
|
||||
})
|
||||
|
||||
expect(media.proxyType).toBe('video')
|
||||
// Only the transcoded proxy should be watermarked, never the raw original.
|
||||
expect(transcodeService.transcodeVideo).toHaveBeenCalledTimes(1)
|
||||
expect(media.videoTranscodes).toHaveLength(1)
|
||||
expect(media.videoTranscodes?.[0].resolution).toBe('100p')
|
||||
expect(media.videoTranscodes?.[0].key).toContain('watermark-')
|
||||
} finally {
|
||||
fs.rmSync(proxyOutFilePath, { force: true })
|
||||
fs.rmSync(rawOutFilePath, { force: true })
|
||||
}
|
||||
})
|
||||
|
||||
it('produces a watermarked mp4 proxy for a video asset (ffmpeg path)', async () => {
|
||||
const assetKey = 'files/e2e-wm/video.mp4'
|
||||
const asset = await seedAsset('video.mp4', 'video/mp4', assetKey, 'video')
|
||||
@@ -435,7 +374,6 @@ describe('Watermark Activities', () => {
|
||||
},
|
||||
original: {
|
||||
key: 'files/x/original.png',
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
},
|
||||
|
||||
@@ -246,7 +246,6 @@ export async function transcodeWatermarkMediaActivity(
|
||||
},
|
||||
original: {
|
||||
key: assetKey,
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
},
|
||||
@@ -302,10 +301,6 @@ export async function transcodeWatermarkMediaActivity(
|
||||
|
||||
for (let i = 0; i < originalTranscodes.length; i++) {
|
||||
const vt = originalTranscodes[i]
|
||||
// Skip the raw marker entry (points at the original file) — it is not a
|
||||
// transcoded proxy, so there is nothing to watermark (and transcoding
|
||||
// the original at full resolution would be needlessly expensive).
|
||||
if (vt.isRaw) continue
|
||||
const targetWidth = vt.width || originalWidth
|
||||
const targetHeight = vt.height || originalHeight
|
||||
const resolution = vt.resolution || `${targetHeight}p`
|
||||
|
||||
@@ -49,7 +49,6 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise<void>
|
||||
|
||||
mediaInfo.original = {
|
||||
key,
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
}
|
||||
|
||||
@@ -60,7 +60,6 @@ export async function transcodePdfWorkflow(task: WorkflowTask): Promise<void> {
|
||||
|
||||
mediaInfo.original = {
|
||||
key,
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
}
|
||||
|
||||
@@ -210,7 +210,6 @@ describe('transcodeVideoWorkflow', () => {
|
||||
},
|
||||
original: {
|
||||
key: 'audio.wav',
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
},
|
||||
|
||||
@@ -54,7 +54,6 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
|
||||
mediaInfo.original = {
|
||||
key,
|
||||
downloadUrl: '',
|
||||
filesizeInBytes: 0,
|
||||
codec: '',
|
||||
}
|
||||
@@ -94,13 +93,6 @@ export async function transcodeVideoWorkflow(task: WorkflowTask): Promise<void>
|
||||
mediaInfo.videoTranscodes.push(videoTranscode)
|
||||
}
|
||||
}
|
||||
|
||||
mediaInfo.videoTranscodes.push({
|
||||
key: mediaInfo.original?.key,
|
||||
width: metadata.originalWidth,
|
||||
height: metadata.originalHeight,
|
||||
isRaw: true,
|
||||
})
|
||||
}
|
||||
|
||||
const isAudio = mediaInfo.proxyType === 'audio'
|
||||
|
||||
Reference in New Issue
Block a user