Create MessageMedia.tsx

This commit is contained in:
RogerHsu7 2026-01-30 10:41:33 +08:00 committed by GitHub
parent c259dfebef
commit f0a94d07d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -0,0 +1,25 @@
import React from 'react'
type Media = { path: string, mime?: string, name?: string }
function isImage(m?: string, path?: string) {
return (m && m.startsWith('image/')) || (path && path.match(/\.(png|jpe?g|webp|gif)$/i))
}
export function MessageMedia({ media }: { media: Media[] }) {
if (!media?.length) return null
return (
<div className="message-media">
{media.map((m, i) => (
<div key={i} className="media-item">
{isImage(m.mime, m.path) ? (
// MEDIA:/absolute/path should be proxied/served by the gateway; adjust URL transformation accordingly
<img src={m.path.replace(/^MEDIA:/, '/media/')} alt={m.name || 'image'} />
) : (
<a href={m.path.replace(/^MEDIA:/, '/media/')} target="_blank" rel="noreferrer">{m.name || 'file'}</a>
)}
</div>
))}
</div>
)
}