Port MIME
module to TypeScript
This commit is contained in:
parent
6a63e427c8
commit
df2e6e7864
7 changed files with 25 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
const is = require('@sindresorhus/is');
|
const is = require('@sindresorhus/is');
|
||||||
|
|
||||||
const MIME = require('./mime');
|
const MIME = require('../../../ts/types/MIME');
|
||||||
const { arrayBufferToBlob, blobToArrayBuffer, dataURLToBlob } = require('blob-util');
|
const { arrayBufferToBlob, blobToArrayBuffer, dataURLToBlob } = require('blob-util');
|
||||||
const { autoOrientImage } = require('../auto_orient_image');
|
const { autoOrientImage } = require('../auto_orient_image');
|
||||||
const { migrateDataToFileSystem } = require('./attachment/migrate_data_to_file_system');
|
const { migrateDataToFileSystem } = require('./attachment/migrate_data_to_file_system');
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
exports.isJPEG = mimeType =>
|
|
||||||
mimeType === 'image/jpeg';
|
|
||||||
|
|
||||||
exports.isVideo = mimeType =>
|
|
||||||
mimeType.startsWith('video/') && mimeType !== 'video/wmv';
|
|
||||||
|
|
||||||
exports.isImage = mimeType =>
|
|
||||||
mimeType.startsWith('image/') && mimeType !== 'image/tiff';
|
|
||||||
|
|
||||||
exports.isAudio = mimeType => mimeType.startsWith('audio/');
|
|
|
@ -191,7 +191,7 @@ window.Signal.Types.Conversation = require('./ts/types/Conversation');
|
||||||
window.Signal.Types.Errors = require('./js/modules/types/errors');
|
window.Signal.Types.Errors = require('./js/modules/types/errors');
|
||||||
|
|
||||||
window.Signal.Types.Message = Message;
|
window.Signal.Types.Message = Message;
|
||||||
window.Signal.Types.MIME = require('./js/modules/types/mime');
|
window.Signal.Types.MIME = require('./ts/types/MIME');
|
||||||
window.Signal.Types.Settings = require('./js/modules/types/settings');
|
window.Signal.Types.Settings = require('./js/modules/types/settings');
|
||||||
|
|
||||||
window.Signal.Views = {};
|
window.Signal.Views = {};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const { assert } = require('chai');
|
const { assert } = require('chai');
|
||||||
|
|
||||||
const MIME = require('../../../js/modules/types/mime');
|
const MIME = require('../../../ts/types/MIME');
|
||||||
|
|
||||||
|
|
||||||
describe('MIME', () => {
|
describe('MIME', () => {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
|
|
||||||
// @ts-ignore
|
import * as MIME from '../../../ts/types/MIME';
|
||||||
import Mime from '../../../js/modules/types/mime';
|
|
||||||
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
@ -92,17 +91,17 @@ export class Quote extends React.Component<Props, {}> {
|
||||||
const { contentType, thumbnail } = first;
|
const { contentType, thumbnail } = first;
|
||||||
const objectUrl = getObjectUrl(thumbnail);
|
const objectUrl = getObjectUrl(thumbnail);
|
||||||
|
|
||||||
if (Mime.isVideo(contentType)) {
|
if (MIME.isVideo(contentType)) {
|
||||||
return objectUrl
|
return objectUrl
|
||||||
? this.renderImage(objectUrl, 'play')
|
? this.renderImage(objectUrl, 'play')
|
||||||
: this.renderIcon('movie');
|
: this.renderIcon('movie');
|
||||||
}
|
}
|
||||||
if (Mime.isImage(contentType)) {
|
if (MIME.isImage(contentType)) {
|
||||||
return objectUrl
|
return objectUrl
|
||||||
? this.renderImage(objectUrl)
|
? this.renderImage(objectUrl)
|
||||||
: this.renderIcon('image');
|
: this.renderIcon('image');
|
||||||
}
|
}
|
||||||
if (Mime.isAudio(contentType)) {
|
if (MIME.isAudio(contentType)) {
|
||||||
return this.renderIcon('microphone');
|
return this.renderIcon('microphone');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,16 +122,16 @@ export class Quote extends React.Component<Props, {}> {
|
||||||
const first = attachments[0];
|
const first = attachments[0];
|
||||||
const { contentType, fileName, isVoiceMessage } = first;
|
const { contentType, fileName, isVoiceMessage } = first;
|
||||||
|
|
||||||
if (Mime.isVideo(contentType)) {
|
if (MIME.isVideo(contentType)) {
|
||||||
return <div className="type-label">{i18n('video')}</div>;
|
return <div className="type-label">{i18n('video')}</div>;
|
||||||
}
|
}
|
||||||
if (Mime.isImage(contentType)) {
|
if (MIME.isImage(contentType)) {
|
||||||
return <div className="type-label">{i18n('photo')}</div>;
|
return <div className="type-label">{i18n('photo')}</div>;
|
||||||
}
|
}
|
||||||
if (Mime.isAudio(contentType) && isVoiceMessage) {
|
if (MIME.isAudio(contentType) && isVoiceMessage) {
|
||||||
return <div className="type-label">{i18n('voiceMessage')}</div>;
|
return <div className="type-label">{i18n('voiceMessage')}</div>;
|
||||||
}
|
}
|
||||||
if (Mime.isAudio(contentType)) {
|
if (MIME.isAudio(contentType)) {
|
||||||
return <div className="type-label">{i18n('audio')}</div>;
|
return <div className="type-label">{i18n('audio')}</div>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,7 @@ export { BackboneWrapper } from '../components/utility/BackboneWrapper';
|
||||||
import { Quote } from '../components/conversation/Quote';
|
import { Quote } from '../components/conversation/Quote';
|
||||||
import * as HTML from '../html';
|
import * as HTML from '../html';
|
||||||
|
|
||||||
// @ts-ignore
|
import * as MIME from '../../ts/types/MIME';
|
||||||
import MIME from '../../js/modules/types/mime';
|
|
||||||
|
|
||||||
// TypeScript wants two things when you import:
|
// TypeScript wants two things when you import:
|
||||||
// 1) a normal typescript file
|
// 1) a normal typescript file
|
||||||
|
|
|
@ -1 +1,14 @@
|
||||||
export type MIMEType = string & { _mimeTypeBrand: any };
|
export type MIMEType = string & { _mimeTypeBrand: any };
|
||||||
|
|
||||||
|
|
||||||
|
export const isVideo = (value: MIMEType): boolean =>
|
||||||
|
value.startsWith('video/') && value !== 'video/wmv';
|
||||||
|
|
||||||
|
export const isImage = (value: MIMEType): boolean =>
|
||||||
|
value.startsWith('image/') && value !== 'image/tiff';
|
||||||
|
|
||||||
|
export const isAudio = (value: MIMEType): boolean =>
|
||||||
|
value.startsWith('audio/');
|
||||||
|
|
||||||
|
export const isJPEG = (value: MIMEType): boolean =>
|
||||||
|
value === 'image/jpeg';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue