25 lines
858 B
TypeScript
25 lines
858 B
TypeScript
const VIDEO_MIME_TYPE_BY_EXTENSION = new Map([
|
|
["avi", "video/x-msvideo"],
|
|
["m4v", "video/mp4"],
|
|
["mkv", "video/x-matroska"],
|
|
["mov", "video/quicktime"],
|
|
["mp4", "video/mp4"],
|
|
["ogv", "video/ogg"],
|
|
["webm", "video/webm"],
|
|
]);
|
|
|
|
export const VIDEO_FILE_EXTENSIONS = Object.freeze([...VIDEO_MIME_TYPE_BY_EXTENSION.keys()]);
|
|
|
|
/** Recognizes videos even when the file picker omitted their MIME type. */
|
|
export function videoMimeType(attachment: {
|
|
readonly name: string;
|
|
readonly mimeType: string;
|
|
}): string | null {
|
|
const mimeType = attachment.mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
if (mimeType.startsWith("video/")) return mimeType;
|
|
const dotIndex = attachment.name.lastIndexOf(".");
|
|
return dotIndex < 0
|
|
? null
|
|
: (VIDEO_MIME_TYPE_BY_EXTENSION.get(attachment.name.slice(dotIndex + 1).toLowerCase()) ?? null);
|
|
}
|