Extract common MIME types
This commit is contained in:
parent
8a4f062120
commit
fa4c3fda2b
3 changed files with 13 additions and 9 deletions
|
@ -5,7 +5,7 @@ import 'mocha';
|
|||
import { assert } from 'chai';
|
||||
|
||||
import * as Attachment from '../../types/Attachment';
|
||||
import { MIMEType } from '../../types/MIME';
|
||||
import * as MIME from '../../types/MIME';
|
||||
// @ts-ignore
|
||||
import { stringToArrayBuffer } from '../../../js/modules/string_to_array_buffer';
|
||||
|
||||
|
@ -14,7 +14,7 @@ describe('Attachment', () => {
|
|||
it('should return file extension from content type', () => {
|
||||
const input: Attachment.Attachment = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
contentType: 'image/gif' as MIMEType,
|
||||
contentType: MIME.IMAGE_GIF,
|
||||
};
|
||||
assert.strictEqual(Attachment.getFileExtension(input), 'gif');
|
||||
});
|
||||
|
@ -22,7 +22,7 @@ describe('Attachment', () => {
|
|||
it('should return file extension for QuickTime videos', () => {
|
||||
const input: Attachment.Attachment = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
contentType: 'video/quicktime' as MIMEType,
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
assert.strictEqual(Attachment.getFileExtension(input), 'mov');
|
||||
});
|
||||
|
@ -34,7 +34,7 @@ describe('Attachment', () => {
|
|||
const attachment: Attachment.Attachment = {
|
||||
fileName: 'funny-cat.mov',
|
||||
data: stringToArrayBuffer('foo'),
|
||||
contentType: 'video/quicktime' as MIMEType,
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
const actual = Attachment.getSuggestedFilename({ attachment });
|
||||
const expected = 'funny-cat.mov';
|
||||
|
@ -45,7 +45,7 @@ describe('Attachment', () => {
|
|||
it('should generate a filename based on timestamp', () => {
|
||||
const attachment: Attachment.Attachment = {
|
||||
data: stringToArrayBuffer('foo'),
|
||||
contentType: 'video/quicktime' as MIMEType,
|
||||
contentType: MIME.VIDEO_QUICKTIME,
|
||||
};
|
||||
const timestamp = new Date(new Date(0).getTimezoneOffset() * 60 * 1000);
|
||||
const actual = Attachment.getSuggestedFilename({
|
||||
|
|
|
@ -3,7 +3,7 @@ import { assert } from 'chai';
|
|||
|
||||
import * as Message from '../../../../ts/types/message/initializeAttachmentMetadata';
|
||||
import { IncomingMessage } from '../../../../ts/types/Message';
|
||||
import { MIMEType } from '../../../../ts/types/MIME';
|
||||
import * as MIME from '../../../../ts/types/MIME';
|
||||
// @ts-ignore
|
||||
import { stringToArrayBuffer } from '../../../../js/modules/string_to_array_buffer';
|
||||
|
||||
|
@ -19,7 +19,7 @@ describe('Message', () => {
|
|||
sent_at: 1523317140800,
|
||||
attachments: [
|
||||
{
|
||||
contentType: 'image/jpeg' as MIMEType,
|
||||
contentType: MIME.IMAGE_JPEG,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
fileName: 'foo.jpg',
|
||||
size: 1111,
|
||||
|
@ -35,7 +35,7 @@ describe('Message', () => {
|
|||
sent_at: 1523317140800,
|
||||
attachments: [
|
||||
{
|
||||
contentType: 'image/jpeg' as MIMEType,
|
||||
contentType: MIME.IMAGE_JPEG,
|
||||
data: stringToArrayBuffer('foo'),
|
||||
fileName: 'foo.jpg',
|
||||
size: 1111,
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
export type MIMEType = string & { _mimeTypeBrand: any };
|
||||
|
||||
export const APPLICATION_OCTET_STREAM = 'application/octet-stream' as MIMEType;
|
||||
export const IMAGE_GIF = 'image/gif' as MIMEType;
|
||||
export const IMAGE_JPEG = 'image/jpeg' as MIMEType;
|
||||
export const VIDEO_QUICKTIME = 'video/quicktime' as MIMEType;
|
||||
|
||||
export const isJPEG = (value: MIMEType): boolean => value === 'image/jpeg';
|
||||
export const isImage = (value: MIMEType): boolean => value.startsWith('image/');
|
||||
export const isVideo = (value: MIMEType): boolean => value.startsWith('video/');
|
||||
export const isAudio = (value: MIMEType): boolean => value.startsWith('audio/');
|
||||
|
||||
export const APPLICATION_OCTET_STREAM = 'application/octet-stream' as MIMEType;
|
||||
|
|
Loading…
Add table
Reference in a new issue