mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-04 23:24:21 +00:00
fix(webui): render sprite image scrubber for video upload notifications
This commit is contained in:
@@ -371,6 +371,9 @@ export class NotificationService {
|
|||||||
if (n.asset) {
|
if (n.asset) {
|
||||||
const a = n.asset
|
const a = n.asset
|
||||||
let previewUrl = ''
|
let previewUrl = ''
|
||||||
|
let thumbnailUrl = ''
|
||||||
|
let originalWidth = 0
|
||||||
|
let originalHeight = 0
|
||||||
|
|
||||||
const media = a.media as PrismaJson.MediaInfo | null
|
const media = a.media as PrismaJson.MediaInfo | null
|
||||||
|
|
||||||
@@ -379,8 +382,16 @@ export class NotificationService {
|
|||||||
try {
|
try {
|
||||||
if (media.sprite) {
|
if (media.sprite) {
|
||||||
previewUrl = await s3Service.presign(bucket, media.sprite.key, 'GET')
|
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) {
|
} else if (media.thumbnail) {
|
||||||
previewUrl = await s3Service.presign(bucket, media.thumbnail.key || '', 'GET')
|
previewUrl = await s3Service.presign(bucket, media.thumbnail.key || '', 'GET')
|
||||||
|
thumbnailUrl = previewUrl
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to generate presigned url for notification asset preview:', e)
|
console.error('Failed to generate presigned url for notification asset preview:', e)
|
||||||
@@ -392,6 +403,9 @@ export class NotificationService {
|
|||||||
name: a.name,
|
name: a.name,
|
||||||
mediaType: a.mediaType || undefined,
|
mediaType: a.mediaType || undefined,
|
||||||
preview: previewUrl || undefined,
|
preview: previewUrl || undefined,
|
||||||
|
thumbnailUrl: thumbnailUrl || undefined,
|
||||||
|
originalWidth: originalWidth || undefined,
|
||||||
|
originalHeight: originalHeight || undefined,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export const assetPreviewSchema = z.object({
|
|||||||
mediaType: z.string().optional(),
|
mediaType: z.string().optional(),
|
||||||
name: z.string().optional(),
|
name: z.string().optional(),
|
||||||
preview: 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>
|
export type AssetPreview = z.infer<typeof assetPreviewSchema>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { NotificationInfo } from '@shumai/dtos'
|
import type { NotificationInfo } from '@shumai/dtos'
|
||||||
import { formatTimeAgo } from '@/ui/lib/time'
|
import { formatTimeAgo } from '@/ui/lib/time'
|
||||||
import { cn } from '@/ui/lib/utils'
|
import { cn } from '@/ui/lib/utils'
|
||||||
|
import { SpriteScrubber } from './sprite-scrubber'
|
||||||
|
|
||||||
interface NotificationCardProps {
|
interface NotificationCardProps {
|
||||||
notification: NotificationInfo
|
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 =
|
const hasPreview =
|
||||||
asset?.preview && (asset.mediaType?.startsWith('image') || asset.mediaType?.startsWith('video'))
|
asset?.preview && (asset.mediaType?.startsWith('image') || asset.mediaType?.startsWith('video'))
|
||||||
|
|
||||||
@@ -98,7 +106,16 @@ export const NotificationCard = ({ notification }: NotificationCardProps) => {
|
|||||||
|
|
||||||
{hasPreview && (
|
{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">
|
<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>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user