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
11export const VIDEO_FILE_EXTENSIONS = Object.freeze([...VIDEO_MIME_TYPE_BY_EXTENSION.keys()]);
12
13/** Recognizes videos even when the file picker omitted their MIME type. */
14export function videoMimeType(attachment: {
15 readonly name: string;
16 readonly mimeType: string;
17}): string | null {
18 const mimeType = attachment.mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
19 if (mimeType.startsWith("video/")) return mimeType;
20 const dotIndex = attachment.name.lastIndexOf(".");
21 return dotIndex < 0
22 ? null
23 : (VIDEO_MIME_TYPE_BY_EXTENSION.get(attachment.name.slice(dotIndex + 1).toLowerCase()) ?? null);
24}