2017-06-08_509bba0/509bba0_unpacked_with_node_modules/discord_app/components/Attachment.js
2022-07-26 10:06:20 -07:00

72 lines
1.9 KiB
JavaScript
Executable file

import React from 'react';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import Image from './common/Image';
import * as FileUtils from '../utils/FileUtils';
import humanize from 'humanize';
const IMAGE_RE = /\.(png|jpe?g|webp|gif)$/i;
const MAX_IMAGE_FILE_SIZE = 1024 * 1024 * 10;
const Attachment = React.createClass({
mixins: [PureRenderMixin],
propTypes: {
inlineMedia: React.PropTypes.bool,
attachment: React.PropTypes.object.isRequired,
},
getDefaultProps() {
return {
inlineMedia: true,
};
},
isImage() {
return IMAGE_RE.test(this.props.attachment.filename);
},
render() {
const attachment = this.props.attachment;
const fileType = FileUtils.classifyFileName(attachment.filename);
if (
this.props.inlineMedia &&
this.isImage() &&
attachment.width > 0 &&
attachment.height > 0 &&
attachment.size <= MAX_IMAGE_FILE_SIZE
) {
return (
<div className="attachment-image">
<a href={attachment.url} onClick={this.props.onClick} target="_blank" rel="noreferrer">
<Image
src={attachment['proxy_url']}
href={attachment.url}
width={attachment.width}
height={attachment.height}
resize={true}
onContextMenu={this.props.onContextMenu}
/>
</a>
</div>
);
} else {
return (
<div className="attachment">
<div className={`icon icon-file ${fileType}`} />
<div className="attachment-inner">
<a href={attachment.url} target="_blank" rel="noreferrer">{attachment.filename}</a>
<div className="metadata">{humanize.filesize(attachment.size)}</div>
</div>
</div>
);
}
},
});
export default Attachment;
// WEBPACK FOOTER //
// ./discord_app/components/Attachment.js