diff --git a/src/extensions/zenodo/ui.tsx b/src/extensions/zenodo/ui.tsx index 6745329ae49099ee8961c58f462ff85041891d03..11954681d803b12857e6633d200ffc1dda959e21 100644 --- a/src/extensions/zenodo/ui.tsx +++ b/src/extensions/zenodo/ui.tsx @@ -14,6 +14,7 @@ import { Button } from '../../mol-plugin-ui/controls/common'; import { OpenInBrowserSvg } from '../../mol-plugin-ui/controls/icons'; import { ParameterControls } from '../../mol-plugin-ui/controls/parameters'; import { PluginContext } from '../../mol-plugin/context'; +import { formatBytes } from '../../mol-util'; import { ParamDefinition as PD } from '../../mol-util/param-definition'; type ZenodoFile = { @@ -75,19 +76,20 @@ function createImportParams(files: ZenodoFile[], plugin: PluginContext) { } for (const file of files) { + const label = `${file.key} (${formatBytes(file.size)})`; if (structureExts.has(file.type)) { const { format, isBinary } = structureExts.get(file.type)!; - modelOpts.push([`${file.links.self}|${format}|${isBinary}`, file.key]); - topologyOpts.push([`${file.links.self}|${format}|${isBinary}`, file.key]); + modelOpts.push([`${file.links.self}|${format}|${isBinary}`, label]); + topologyOpts.push([`${file.links.self}|${format}|${isBinary}`, label]); } else if (volumeExts.has(file.type)) { const { format, isBinary } = volumeExts.get(file.type)!; - volumeOpts.push([`${file.links.self}|${format}|${isBinary}`, file.key]); + volumeOpts.push([`${file.links.self}|${format}|${isBinary}`, label]); } else if (file.type === 'psf') { - topologyOpts.push([`${file.links.self}|${file.type}|false`, file.key]); + topologyOpts.push([`${file.links.self}|${file.type}|false`, label]); } else if (file.type === 'xtc' || file.type === 'dcd') { - coordinatesOpts.push([`${file.links.self}|${file.type}|true`, file.key]); + coordinatesOpts.push([`${file.links.self}|${file.type}|true`, label]); } else if (file.type === 'zip') { - compressedOpts.push([`${file.links.self}|${file.type}|true`, file.key]); + compressedOpts.push([`${file.links.self}|${file.type}|true`, label]); } } diff --git a/src/mol-util/index.ts b/src/mol-util/index.ts index 1cbd8ede585bc66eefde4ca85612ebf94020c59a..4db05201cd2b0631b5534f3be008456b440a42bf 100644 --- a/src/mol-util/index.ts +++ b/src/mol-util/index.ts @@ -202,4 +202,10 @@ export function formatProgress(p: Progress) { if (tp.isIndeterminate) return tp.message; const x = (100 * tp.current / tp.max).toFixed(2); return `${tp.message} ${x}%`; +} + +export function formatBytes(count: number) { + const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + const i = Math.floor(Math.log(count) / Math.log(1024)); + return `${(count / Math.pow(1024, i)).toFixed(2)} ${units[i]}`; } \ No newline at end of file