refactor(media): centralize voice compatibility policy

This commit is contained in:
Peter Steinberger
2026-02-14 03:17:02 +01:00
parent 03fee3c605
commit 6ebf503fa8
6 changed files with 62 additions and 40 deletions

View File

@@ -52,7 +52,7 @@ const AUDIO_FILE_EXTENSIONS = new Set([
".wav",
]);
function normalizeHeaderMime(mime?: string | null): string | undefined {
export function normalizeMimeType(mime?: string | null): string | undefined {
if (!mime) {
return undefined;
}
@@ -120,7 +120,7 @@ async function detectMimeImpl(opts: {
const ext = getFileExtension(opts.filePath);
const extMime = ext ? MIME_BY_EXT[ext] : undefined;
const headerMime = normalizeHeaderMime(opts.headerMime);
const headerMime = normalizeMimeType(opts.headerMime);
const sniffed = await sniffMime(opts.buffer);
// Prefer sniffed types, but don't let generic container types override a more
@@ -145,10 +145,11 @@ async function detectMimeImpl(opts: {
}
export function extensionForMime(mime?: string | null): string | undefined {
if (!mime) {
const normalized = normalizeMimeType(mime);
if (!normalized) {
return undefined;
}
return EXT_BY_MIME[mime.toLowerCase()];
return EXT_BY_MIME[normalized];
}
export function isGifMedia(opts: {