mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +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:
@@ -71,7 +71,6 @@ interface BreadcrumbNavProps {
|
||||
key: string
|
||||
width: number
|
||||
height: number
|
||||
isRaw?: boolean
|
||||
}>
|
||||
}
|
||||
versions?: Array<{
|
||||
@@ -159,10 +158,7 @@ export function BreadcrumbNav({
|
||||
}
|
||||
|
||||
const isAudio = currentAsset.proxyType === 'audio'
|
||||
const hasVideoTranscodes =
|
||||
!isAudio &&
|
||||
downloadInfo?.videoTranscodes &&
|
||||
downloadInfo.videoTranscodes.filter((t) => !t.isRaw).length > 0
|
||||
const hasVideoTranscodes = !isAudio && (downloadInfo?.videoTranscodes?.length ?? 0) > 0
|
||||
|
||||
const breadcrumbs: { name: string; path?: string; id?: string; isMuted?: boolean }[] = isPublic
|
||||
? [
|
||||
@@ -244,28 +240,26 @@ export function BreadcrumbNav({
|
||||
<DropdownMenuPortal>
|
||||
<DropdownMenuSubContent className="w-48">
|
||||
<DropdownMenuLabel>{m.download()}</DropdownMenuLabel>
|
||||
{downloadInfo?.videoTranscodes
|
||||
?.filter((t) => !t.isRaw)
|
||||
.map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
else if (longSide >= 1920) resolution = '1080p'
|
||||
else if (longSide >= 1280) resolution = '720p'
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={resolution}
|
||||
onClick={() => handleDownload(t.key)}
|
||||
className="flex items-center justify-between"
|
||||
>
|
||||
<span>{resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
{downloadInfo?.videoTranscodes?.map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
else if (longSide >= 1920) resolution = '1080p'
|
||||
else if (longSide >= 1280) resolution = '720p'
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
key={resolution}
|
||||
onClick={() => handleDownload(t.key)}
|
||||
className="flex items-center justify-between"
|
||||
>
|
||||
<span>{resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
)
|
||||
})}
|
||||
{downloadInfo?.originalKey && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
@@ -425,7 +425,6 @@ export function PublicShareManager({
|
||||
key: t.key,
|
||||
width: t.width,
|
||||
height: t.height,
|
||||
isRaw: t.isRaw,
|
||||
})),
|
||||
}
|
||||
: undefined,
|
||||
|
||||
@@ -111,11 +111,7 @@ export const CompareImagePane = forwardRef<ComparePaneHandle, CompareImagePanePr
|
||||
})
|
||||
}, [baseScale, conW, conH, imgW, imgH])
|
||||
|
||||
let bestUrl = file.media?.original?.downloadUrl
|
||||
const bestTranscode = getBestTranscode(file.media?.imageTranscodes, screenWidth)
|
||||
if (bestTranscode?.url) {
|
||||
bestUrl = bestTranscode.url
|
||||
}
|
||||
const bestUrl = getBestTranscode(file.media?.imageTranscodes, screenWidth)?.url ?? ''
|
||||
|
||||
const handleDownload = useCallback(async () => {
|
||||
const key = file.media?.original?.key
|
||||
|
||||
@@ -96,12 +96,7 @@ export const ImageViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
setPan({ x, y })
|
||||
}
|
||||
|
||||
let bestUrl = file.media?.original?.downloadUrl
|
||||
|
||||
const bestTranscode = getBestTranscode(file.media?.imageTranscodes, screenWidth)
|
||||
if (bestTranscode?.url) {
|
||||
bestUrl = bestTranscode.url
|
||||
}
|
||||
const bestUrl = getBestTranscode(file.media?.imageTranscodes, screenWidth)?.url ?? ''
|
||||
|
||||
const handleDownload = async () => {
|
||||
const key = file.media?.original?.key
|
||||
@@ -184,24 +179,30 @@ export const ImageViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
<div className="flex-1 flex flex-col-reverse md:flex-row min-h-0 relative">
|
||||
{children}
|
||||
<div ref={containerRef} className="flex-1 relative overflow-hidden">
|
||||
<DrawingCanvas
|
||||
width={conW}
|
||||
height={conH}
|
||||
mediaDimensions={{
|
||||
width: imgW,
|
||||
height: imgH,
|
||||
}}
|
||||
imageUrl={bestUrl}
|
||||
annotations={displayAnnotations}
|
||||
scale={zoom}
|
||||
offset={pan}
|
||||
onPan={setPan}
|
||||
className="absolute inset-0 z-0"
|
||||
isDrawing={isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={addAnnotation}
|
||||
/>
|
||||
{bestUrl ? (
|
||||
<DrawingCanvas
|
||||
width={conW}
|
||||
height={conH}
|
||||
mediaDimensions={{
|
||||
width: imgW,
|
||||
height: imgH,
|
||||
}}
|
||||
imageUrl={bestUrl}
|
||||
annotations={displayAnnotations}
|
||||
scale={zoom}
|
||||
offset={pan}
|
||||
onPan={setPan}
|
||||
className="absolute inset-0 z-0"
|
||||
isDrawing={isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={addAnnotation}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-full w-full items-center justify-center">
|
||||
<p className="text-muted-foreground">Preview unavailable</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<ImageControlBar
|
||||
|
||||
@@ -132,7 +132,7 @@ export const PdfViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
}
|
||||
}, [])
|
||||
|
||||
const fileUrl = file.media?.pdfTranscode?.url || file.media?.original?.downloadUrl
|
||||
const fileUrl = file.media?.pdfTranscode?.url
|
||||
|
||||
// Load PDF Document
|
||||
useEffect(() => {
|
||||
|
||||
@@ -30,20 +30,9 @@ interface CompareVideoPaneProps {
|
||||
}
|
||||
|
||||
function computeResolutions(file: AssetInfo): DisplayTranscode[] {
|
||||
const original: DisplayTranscode | null = file.media?.original?.downloadUrl
|
||||
? {
|
||||
id: 'original',
|
||||
url: file.media.original.downloadUrl,
|
||||
key: file.media.original.key ?? '',
|
||||
width: file.media?.metadata?.originalWidth ?? 0,
|
||||
height: file.media?.metadata?.originalHeight ?? 0,
|
||||
size: 0,
|
||||
isRaw: true,
|
||||
resolution: 'Original',
|
||||
}
|
||||
: null
|
||||
|
||||
const transcodes: DisplayTranscode[] = (file.media?.videoTranscodes ?? []).map((t) => {
|
||||
// Only transcoded proxy versions are ever displayed; the raw original file
|
||||
// is never used as a playback source.
|
||||
return (file.media?.videoTranscodes ?? []).map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
@@ -52,14 +41,8 @@ function computeResolutions(file: AssetInfo): DisplayTranscode[] {
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
return { ...t, resolution: t.isRaw ? 'Original' : resolution }
|
||||
return { ...t, resolution }
|
||||
})
|
||||
|
||||
const hasOriginalTranscode = transcodes.some((t) => t.isRaw)
|
||||
if (!hasOriginalTranscode && original) {
|
||||
return [...transcodes, original]
|
||||
}
|
||||
return transcodes
|
||||
}
|
||||
|
||||
export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPaneProps>(
|
||||
@@ -113,9 +96,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
const totalFrames = resolveTotalFrames({ dbTotalFrames, containerDuration, frameRate })
|
||||
|
||||
const resolutions = computeResolutions(file)
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
const initialRes = previewResolutions[0] ?? resolutions[0]
|
||||
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? 'Original')
|
||||
const initialRes = resolutions[0]
|
||||
const [currentResolution, setCurrentResolution] = useState(initialRes?.resolution ?? '')
|
||||
const currentSrcRef = useRef(initialRes?.url)
|
||||
|
||||
const isAudio = file.proxyType === 'audio'
|
||||
@@ -155,7 +137,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
// if the parent renders this pane without a per-asset `key`. Runs before the
|
||||
// video.js init effect below (declaration order) so the ref is fresh.
|
||||
useEffect(() => {
|
||||
setCurrentResolution(initialRes?.resolution ?? 'Original')
|
||||
setCurrentResolution(initialRes?.resolution ?? '')
|
||||
currentSrcRef.current = initialRes?.url
|
||||
}, [file.id])
|
||||
|
||||
@@ -421,7 +403,7 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
onRequestTogglePlay?.()
|
||||
}, [isActive, onActivate, onRequestTogglePlay])
|
||||
|
||||
if (!file.media?.original?.downloadUrl || !metadata) {
|
||||
if (!file.media?.metadata || resolutions.length === 0) {
|
||||
return (
|
||||
<div className="flex h-full w-full items-center justify-center bg-black">
|
||||
<p className="text-muted-foreground">Media is not available.</p>
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '../../ui/dropdown-menu'
|
||||
import { Slider } from '../../ui/slider'
|
||||
@@ -115,7 +116,6 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
const overlay = state.isFullScreen && floatOverlayInFullScreen
|
||||
|
||||
const isAudio = data.proxyType === 'audio'
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
const startTimecode = data.media?.metadata?.startTimecode
|
||||
const displayTotalFrames = Math.max(0, totalFrames - 1)
|
||||
@@ -311,7 +311,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Settings / Resolution */}
|
||||
{!isAudio && previewResolutions.length > 0 && (
|
||||
{!isAudio && resolutions.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
@@ -326,7 +326,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>{m.quality()}</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
@@ -372,12 +372,24 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution === 'Original' ? m.original() : res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
|
||||
</span>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">MP4</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
{data.media?.original?.key && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleDownload(data.media?.original?.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{m.original()}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{data.name?.split('.').pop()?.toUpperCase() || 'RAW'}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
|
||||
@@ -18,9 +18,67 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
) => {
|
||||
const localPlayerRef = useRef<Player | null>(null)
|
||||
const playerRef = localPlayerRef
|
||||
const hasMedia = !!data.media?.original?.downloadUrl && !!data.media?.metadata
|
||||
const resolutions: DisplayTranscode[] = (data.media?.videoTranscodes ?? []).map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
else if (longSide >= 1920) resolution = '1080p'
|
||||
else if (longSide >= 1280) resolution = '720p'
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
|
||||
return {
|
||||
...t,
|
||||
resolution,
|
||||
}
|
||||
})
|
||||
// Only transcoded proxy versions are ever displayed; the raw original file
|
||||
// is never used as a playback source.
|
||||
const hasMedia = resolutions.length > 0 && !!data.media?.metadata
|
||||
// We use a container ref to manually append the video element
|
||||
const videoContainerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// Logic to select best resolution based on screen size
|
||||
const getInitialResolution = (): DisplayTranscode | null => {
|
||||
if (resolutions.length === 0) return null
|
||||
|
||||
if (typeof window === 'undefined') return resolutions[0]
|
||||
|
||||
// Use device pixel ratio for high DPI screens
|
||||
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
|
||||
|
||||
// 1. Sort by width ascending
|
||||
const sortedResolutions = [...resolutions].sort((a, b) => {
|
||||
const wA = a.width ?? 0
|
||||
const wB = b.width ?? 0
|
||||
return wA - wB
|
||||
})
|
||||
|
||||
// 2. Find first one >= screenWidth
|
||||
const bestFit = sortedResolutions.find((r) => (r.width ?? 0) >= screenWidth)
|
||||
|
||||
// 3. If found, return it. If not (all are smaller), return the last one (largest).
|
||||
return bestFit || sortedResolutions[sortedResolutions.length - 1]
|
||||
}
|
||||
|
||||
const initialRes = getInitialResolution()
|
||||
|
||||
// State
|
||||
const [state, setState] = useState<PlayerState>({
|
||||
isPlaying: false,
|
||||
progress: 0,
|
||||
currentTime: 0,
|
||||
duration: data.media?.metadata?.duration || 0,
|
||||
volume: 1,
|
||||
isMuted: false,
|
||||
isLooping: false,
|
||||
playbackRate: 1,
|
||||
isFullScreen: false,
|
||||
showFrames: false,
|
||||
currentResolution: initialRes?.resolution ?? '',
|
||||
currentSrc: initialRes?.url ?? '',
|
||||
})
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
const rootRef = useRef<HTMLDivElement>(null)
|
||||
const controlsTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
@@ -113,76 +171,6 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
}, [])
|
||||
|
||||
// Initial resolution setup
|
||||
const originalRes: DisplayTranscode = {
|
||||
id: 'original',
|
||||
url: data.media?.original?.downloadUrl || '',
|
||||
key: data.media?.original?.key ?? '',
|
||||
width: data.media?.metadata?.originalWidth ?? 0,
|
||||
height: data.media?.metadata?.originalHeight ?? 0,
|
||||
size: 0,
|
||||
isRaw: true,
|
||||
resolution: 'Original',
|
||||
}
|
||||
|
||||
const resolutions: DisplayTranscode[] = (data.media?.videoTranscodes ?? []).map((t) => {
|
||||
const longSide = Math.max(t.width, t.height)
|
||||
let resolution = `${t.height}p`
|
||||
if (longSide >= 3840) resolution = '2160p'
|
||||
else if (longSide >= 1920) resolution = '1080p'
|
||||
else if (longSide >= 1280) resolution = '720p'
|
||||
else if (longSide >= 960) resolution = '540p'
|
||||
else if (longSide >= 640) resolution = '360p'
|
||||
else if (longSide >= 320) resolution = '180p'
|
||||
|
||||
return {
|
||||
...t,
|
||||
resolution: t.isRaw ? 'Original' : resolution,
|
||||
}
|
||||
})
|
||||
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
// Logic to select best resolution based on screen size
|
||||
const getInitialResolution = (): DisplayTranscode => {
|
||||
if (previewResolutions.length === 0) return originalRes
|
||||
|
||||
if (typeof window === 'undefined') return previewResolutions[0]
|
||||
|
||||
// Use device pixel ratio for high DPI screens
|
||||
const screenWidth = window.innerWidth * (window.devicePixelRatio || 1)
|
||||
|
||||
// 1. Sort by width ascending
|
||||
const sortedResolutions = [...previewResolutions].sort((a, b) => {
|
||||
const wA = a.width ?? 0
|
||||
const wB = b.width ?? 0
|
||||
return wA - wB
|
||||
})
|
||||
|
||||
// 2. Find first one >= screenWidth
|
||||
const bestFit = sortedResolutions.find((r) => (r.width ?? 0) >= screenWidth)
|
||||
|
||||
// 3. If found, return it. If not (all are smaller), return the last one (largest).
|
||||
return bestFit || sortedResolutions[sortedResolutions.length - 1]
|
||||
}
|
||||
|
||||
const initialRes = getInitialResolution()
|
||||
|
||||
// State
|
||||
const [state, setState] = useState<PlayerState>({
|
||||
isPlaying: false,
|
||||
progress: 0,
|
||||
currentTime: 0,
|
||||
duration: data.media?.metadata?.duration || 0,
|
||||
volume: 1,
|
||||
isMuted: false,
|
||||
isLooping: false,
|
||||
playbackRate: 1,
|
||||
isFullScreen: false,
|
||||
showFrames: false,
|
||||
currentResolution: initialRes?.resolution || 'Original',
|
||||
currentSrc: initialRes?.url || '',
|
||||
})
|
||||
|
||||
const [buffered, setBuffered] = useState(0)
|
||||
const [isControlsVisible, setIsControlsVisible] = useState(true)
|
||||
const [isPlayerReady, setIsPlayerReady] = useState(false)
|
||||
|
||||
Reference in New Issue
Block a user