fix(webui): render sprite image scrubber for video upload notifications

This commit is contained in:
yiling
2026-06-19 13:25:00 +08:00
parent 6cb3ca6874
commit 5e92660d1c
3 changed files with 35 additions and 1 deletions
@@ -371,6 +371,9 @@ export class NotificationService {
if (n.asset) {
const a = n.asset
let previewUrl = ''
let thumbnailUrl = ''
let originalWidth = 0
let originalHeight = 0
const media = a.media as PrismaJson.MediaInfo | null
@@ -379,8 +382,16 @@ export class NotificationService {
try {
if (media.sprite) {
previewUrl = await s3Service.presign(bucket, media.sprite.key, 'GET')
if (media.thumbnail) {
thumbnailUrl = await s3Service.presign(bucket, media.thumbnail.key || '', 'GET')
}
if (media.metadata) {
originalWidth = media.metadata.originalWidth
originalHeight = media.metadata.originalHeight
}
} else if (media.thumbnail) {
previewUrl = await s3Service.presign(bucket, media.thumbnail.key || '', 'GET')
thumbnailUrl = previewUrl
}
} catch (e) {
console.error('Failed to generate presigned url for notification asset preview:', e)
@@ -392,6 +403,9 @@ export class NotificationService {
name: a.name,
mediaType: a.mediaType || undefined,
preview: previewUrl || undefined,
thumbnailUrl: thumbnailUrl || undefined,
originalWidth: originalWidth || undefined,
originalHeight: originalHeight || undefined,
}
}
+3
View File
@@ -21,6 +21,9 @@ export const assetPreviewSchema = z.object({
mediaType: z.string().optional(),
name: z.string().optional(),
preview: z.string().optional(),
thumbnailUrl: z.string().optional(),
originalWidth: z.number().optional(),
originalHeight: z.number().optional(),
})
export type AssetPreview = z.infer<typeof assetPreviewSchema>
@@ -1,6 +1,7 @@
import type { NotificationInfo } from '@shumai/dtos'
import { formatTimeAgo } from '@/ui/lib/time'
import { cn } from '@/ui/lib/utils'
import { SpriteScrubber } from './sprite-scrubber'
interface NotificationCardProps {
notification: NotificationInfo
@@ -76,6 +77,13 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
}
})()
const isVideoWithSprite =
asset?.mediaType?.startsWith('video/') &&
asset.preview &&
asset.thumbnailUrl &&
asset.originalWidth &&
asset.originalHeight
const hasPreview =
asset?.preview && (asset.mediaType?.startsWith('image') || asset.mediaType?.startsWith('video'))
@@ -98,7 +106,16 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
{hasPreview && (
<div className="w-18 h-18 ml-2 rounded-md overflow-hidden flex-shrink-0 bg-muted border border-border flex items-center justify-center mt-0.5">
<img src={asset!.preview} alt={asset!.name} className="w-full h-full object-cover" />
{isVideoWithSprite ? (
<SpriteScrubber
spriteUrl={asset.preview!}
thumbnailUrl={asset.thumbnailUrl!}
videoWidth={asset.originalWidth!}
videoHeight={asset.originalHeight!}
/>
) : (
<img src={asset!.preview} alt={asset!.name} className="w-full h-full object-cover" />
)}
</div>
)}
</div>