This commit is contained in:
RandyJC
2025-12-08 20:56:17 +01:00
parent 5499a83a9f
commit e60818f93e
2 changed files with 25 additions and 11 deletions

View File

@@ -33,6 +33,7 @@ const QuestionMedia = ({ media, alt, onPlayChange }: Props) => {
<div className={clsx(containerClass, "px-4")}> <div className={clsx(containerClass, "px-4")}>
<audio <audio
controls controls
crossOrigin="anonymous"
src={media.url} src={media.url}
className="mt-4 w-full rounded-md bg-black/40 p-2 shadow-lg" className="mt-4 w-full rounded-md bg-black/40 p-2 shadow-lg"
preload="none" preload="none"
@@ -48,6 +49,8 @@ const QuestionMedia = ({ media, alt, onPlayChange }: Props) => {
<div className={containerClass}> <div className={containerClass}>
<video <video
controls controls
crossOrigin="anonymous"
playsInline
src={media.url} src={media.url}
className="m-4 w-full max-w-3xl rounded-md shadow-lg" className="m-4 w-full max-w-3xl rounded-md shadow-lg"
preload="metadata" preload="metadata"

View File

@@ -34,19 +34,30 @@ const ensureMediaFolder = () => {
const inferMimeFromName = (fileName: string) => { const inferMimeFromName = (fileName: string) => {
const ext = path.extname(fileName).toLowerCase() const ext = path.extname(fileName).toLowerCase()
if ([".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp", ".svg"].includes(ext)) { const map: Record<string, string> = {
return `image/${ext.replace(".", "") || "jpeg"}` ".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".gif": "image/gif",
".webp": "image/webp",
".bmp": "image/bmp",
".svg": "image/svg+xml",
".mp3": "audio/mpeg",
".m4a": "audio/mp4",
".aac": "audio/aac",
".wav": "audio/wav",
".ogg": "audio/ogg",
".oga": "audio/ogg",
".flac": "audio/flac",
".mp4": "video/mp4",
".m4v": "video/mp4",
".mov": "video/quicktime",
".webm": "video/webm",
".ogv": "video/ogg",
".mkv": "video/x-matroska",
} }
if ([".mp3", ".wav", ".ogg", ".aac", ".m4a", ".flac"].includes(ext)) { return map[ext] || "application/octet-stream"
return `audio/${ext.replace(".", "") || "mpeg"}`
}
if ([".mp4", ".webm", ".mov", ".ogv", ".mkv"].includes(ext)) {
return `video/${ext.replace(".", "") || "mp4"}`
}
return "application/octet-stream"
} }
const inferMediaType = (mime: string): QuestionMedia["type"] | null => { const inferMediaType = (mime: string): QuestionMedia["type"] | null => {