Signal-Desktop/ts/types/MIME.ts

38 lines
1.7 KiB
TypeScript
Raw Normal View History

// Copyright 2018-2021 Signal Messenger, LLC
2020-10-30 20:34:04 +00:00
// SPDX-License-Identifier: AGPL-3.0-only
export type MIMEType = string & { _mimeTypeBrand: never };
2018-04-09 23:24:24 +00:00
2018-05-07 15:24:40 +00:00
export const APPLICATION_OCTET_STREAM = 'application/octet-stream' as MIMEType;
2018-05-07 19:49:06 +00:00
export const APPLICATION_JSON = 'application/json' as MIMEType;
2018-05-07 16:40:59 +00:00
export const AUDIO_AAC = 'audio/aac' as MIMEType;
export const AUDIO_MP3 = 'audio/mp3' as MIMEType;
2018-05-07 15:24:40 +00:00
export const IMAGE_GIF = 'image/gif' as MIMEType;
export const IMAGE_JPEG = 'image/jpeg' as MIMEType;
2020-08-26 18:06:48 +00:00
export const IMAGE_PNG = 'image/png' as MIMEType;
export const IMAGE_WEBP = 'image/webp' as MIMEType;
2020-09-28 18:40:26 +00:00
export const IMAGE_ICO = 'image/x-icon' as MIMEType;
export const IMAGE_BMP = 'image/bmp' as MIMEType;
2018-05-07 19:49:06 +00:00
export const VIDEO_MP4 = 'video/mp4' as MIMEType;
2018-05-07 15:24:40 +00:00
export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType;
export const LONG_MESSAGE = 'text/x-signal-plain' as MIMEType;
2018-05-07 15:24:40 +00:00
export const isGif = (value: string): value is MIMEType =>
value === 'image/gif';
export const isJPEG = (value: string): value is MIMEType =>
value === 'image/jpeg';
export const isImage = (value: string): value is MIMEType =>
Boolean(value) && value.startsWith('image/');
export const isVideo = (value: string): value is MIMEType =>
Boolean(value) && value.startsWith('video/');
2020-04-16 19:19:37 +00:00
// As of 2020-04-16 aif files do not play in Electron nor Chrome. We should only
// recognize them as file attachments.
export const isAudio = (value: string): value is MIMEType =>
Boolean(value) && value.startsWith('audio/') && !value.endsWith('aiff');
export const isLongMessage = (value: unknown): value is MIMEType =>
value === LONG_MESSAGE;
2021-07-14 23:39:52 +00:00
export const fromString = (value: string): MIMEType => {
return value as MIMEType;
};