Open History to see the last commit
1const VIDEO_MIME_TYPE_BY_EXTENSION = new Map([
2 ["avi", "video/x-msvideo"],
3 ["m4v", "video/mp4"],
4 ["mkv", "video/x-matroska"],
5 ["mov", "video/quicktime"],
6 ["mp4", "video/mp4"],
7 ["ogv", "video/ogg"],
8 ["webm", "video/webm"],
9]);
10
11/** Recognizes videos even when the file picker omitted their MIME type. */
12export function videoMimeType(attachment: {
13 readonly name: string;
14 readonly mimeType: string;
15}): string | null {
16 const mimeType = attachment.mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
17 if (mimeType.startsWith("video/")) return mimeType;
18 const dotIndex = attachment.name.lastIndexOf(".");
19 return dotIndex < 0
20 ? null
21 : (VIDEO_MIME_TYPE_BY_EXTENSION.get(attachment.name.slice(dotIndex + 1).toLowerCase()) ?? null);
22}