2018-03-26 23:32:43 +02:00
|
|
|
// @flow
|
2018-11-07 23:44:38 +01:00
|
|
|
import React, { Fragment, PureComponent } from 'react';
|
2018-06-10 23:57:46 +02:00
|
|
|
import MarkdownPreview from 'component/common/markdown-preview';
|
2018-03-26 23:32:43 +02:00
|
|
|
import Button from 'component/button';
|
2018-11-07 23:44:38 +01:00
|
|
|
import Expandable from 'component/expandable';
|
2019-03-05 05:46:57 +01:00
|
|
|
import path from 'path';
|
2017-09-17 22:33:52 +02:00
|
|
|
|
2018-03-26 23:32:43 +02:00
|
|
|
type Props = {
|
2019-04-24 16:02:08 +02:00
|
|
|
claim: StreamClaim,
|
|
|
|
fileInfo: FileListItem,
|
|
|
|
metadata: StreamMetadata,
|
2018-03-26 23:32:43 +02:00
|
|
|
openFolder: string => void,
|
|
|
|
contentType: string,
|
2018-11-07 23:44:38 +01:00
|
|
|
user: ?any,
|
2018-03-26 23:32:43 +02:00
|
|
|
};
|
2017-09-20 14:47:08 +02:00
|
|
|
|
2018-11-07 23:44:38 +01:00
|
|
|
class FileDetails extends PureComponent<Props> {
|
|
|
|
render() {
|
2019-05-17 20:21:07 +02:00
|
|
|
const { claim, contentType, fileInfo, metadata, openFolder } = this.props;
|
2018-04-25 21:31:58 +02:00
|
|
|
|
2018-11-07 23:44:38 +01:00
|
|
|
if (!claim || !metadata) {
|
2019-07-21 23:31:22 +02:00
|
|
|
return <span className="empty">{__('Empty claim or metadata info.')}</span>;
|
2018-11-07 23:44:38 +01:00
|
|
|
}
|
|
|
|
|
2019-04-24 16:02:08 +02:00
|
|
|
const { description, languages, license } = metadata;
|
2017-09-17 22:33:52 +02:00
|
|
|
|
2018-11-07 23:44:38 +01:00
|
|
|
const mediaType = contentType || 'unknown';
|
2019-07-24 07:23:35 +02:00
|
|
|
const fileSize = metadata.source.size
|
|
|
|
? formatBytes(metadata.source.size)
|
|
|
|
: fileInfo && fileInfo.download_path && formatBytes(fileInfo.written_bytes);
|
2019-05-07 23:38:29 +02:00
|
|
|
let downloadPath = fileInfo && fileInfo.download_path ? path.normalize(fileInfo.download_path) : null;
|
2019-02-12 18:26:50 +01:00
|
|
|
let downloadNote;
|
|
|
|
// If the path is blank, file is not avialable. Create path from name so the folder opens on click.
|
|
|
|
if (fileInfo && fileInfo.download_path === null) {
|
|
|
|
downloadPath = `${fileInfo.download_directory}/${fileInfo.file_name}`;
|
|
|
|
downloadNote = 'This file may have been moved or deleted';
|
|
|
|
}
|
2018-11-07 23:44:38 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Fragment>
|
|
|
|
<Expandable>
|
|
|
|
{description && (
|
|
|
|
<Fragment>
|
2018-12-19 06:44:53 +01:00
|
|
|
<div className="media__info-text">
|
2018-11-07 23:44:38 +01:00
|
|
|
<MarkdownPreview content={description} promptLinks />
|
|
|
|
</div>
|
|
|
|
</Fragment>
|
|
|
|
)}
|
2018-12-19 06:44:53 +01:00
|
|
|
<div className="media__info-title">Info</div>
|
|
|
|
<div className="media__info-text">
|
2018-11-07 23:44:38 +01:00
|
|
|
<div>
|
|
|
|
{__('Content-Type')}
|
|
|
|
{': '}
|
|
|
|
{mediaType}
|
|
|
|
</div>
|
2019-07-24 07:23:35 +02:00
|
|
|
{fileSize && (
|
|
|
|
<div>
|
|
|
|
{__('File Size')}
|
|
|
|
{': '}
|
|
|
|
{fileSize}
|
|
|
|
</div>
|
|
|
|
)}
|
2018-11-07 23:44:38 +01:00
|
|
|
<div>
|
2019-04-24 16:02:08 +02:00
|
|
|
{__('Languages')}
|
2018-11-07 23:44:38 +01:00
|
|
|
{': '}
|
2019-04-24 16:02:08 +02:00
|
|
|
{languages ? languages.join(' ') : null}
|
2018-11-07 23:44:38 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
{__('License')}
|
|
|
|
{': '}
|
|
|
|
{license}
|
|
|
|
</div>
|
|
|
|
{downloadPath && (
|
|
|
|
<div>
|
|
|
|
{__('Downloaded to')}
|
|
|
|
{': '}
|
|
|
|
<Button
|
|
|
|
button="link"
|
2019-04-24 16:02:08 +02:00
|
|
|
onClick={() => {
|
|
|
|
if (downloadPath) {
|
|
|
|
openFolder(downloadPath);
|
|
|
|
}
|
|
|
|
}}
|
2019-02-12 18:26:50 +01:00
|
|
|
label={downloadNote || downloadPath}
|
2018-11-07 23:44:38 +01:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2018-03-26 23:32:43 +02:00
|
|
|
</div>
|
2018-11-07 23:44:38 +01:00
|
|
|
</Expandable>
|
|
|
|
</Fragment>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 07:23:35 +02:00
|
|
|
// move this with other helper functions when we re-use it
|
|
|
|
function formatBytes(bytes, decimals = 2) {
|
|
|
|
if (bytes === 0) return '0 Bytes';
|
|
|
|
|
|
|
|
const k = 1024;
|
|
|
|
const dm = decimals < 0 ? 0 : decimals;
|
|
|
|
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
|
|
|
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
|
|
}
|
2017-09-17 22:33:52 +02:00
|
|
|
|
|
|
|
export default FileDetails;
|