From 20c2679dc8a51d90e75f994e26e1eddfeb48d84c Mon Sep 17 00:00:00 2001 From: Martin Filser Date: Fri, 29 Apr 2022 12:02:51 +0200 Subject: [PATCH] Attachment size, changed calculation to npm filesize (Version Info) --- .../components/settings/informationBody.jade | 28 +++++++++---------- client/components/settings/informationBody.js | 11 +++----- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/client/components/settings/informationBody.jade b/client/components/settings/informationBody.jade index e98fe1e68..52916c7d4 100644 --- a/client/components/settings/informationBody.jade +++ b/client/components/settings/informationBody.jade @@ -58,38 +58,38 @@ template(name='statistics') td {{numFormat statistics.os.loadavg.[0]}}, {{numFormat statistics.os.loadavg.[1]}}, {{numFormat statistics.os.loadavg.[2]}} tr th {{_ 'OS_Totalmem'}} - td {{bytesToSize statistics.os.totalmem}} + td {{fileSize statistics.os.totalmem}} tr th {{_ 'OS_Freemem'}} - td {{bytesToSize statistics.os.freemem}} + td {{fileSize statistics.os.freemem}} tr th {{_ 'OS_Cpus'}} td {{statistics.os.cpus.length}} unless isSandstorm tr th {{_ 'Node_heap_total_heap_size'}} - td {{bytesToSize statistics.nodeHeapStats.totalHeapSize}} + td {{fileSize statistics.nodeHeapStats.totalHeapSize}} tr th {{_ 'Node_heap_total_heap_size_executable'}} - td {{bytesToSize statistics.nodeHeapStats.totalHeapSizeExecutable}} + td {{fileSize statistics.nodeHeapStats.totalHeapSizeExecutable}} tr th {{_ 'Node_heap_total_physical_size'}} - td {{bytesToSize statistics.nodeHeapStats.totalPhysicalSize}} + td {{fileSize statistics.nodeHeapStats.totalPhysicalSize}} tr th {{_ 'Node_heap_total_available_size'}} - td {{bytesToSize statistics.nodeHeapStats.totalAvailableSize}} + td {{fileSize statistics.nodeHeapStats.totalAvailableSize}} tr th {{_ 'Node_heap_used_heap_size'}} - td {{bytesToSize statistics.nodeHeapStats.usedHeapSize}} + td {{fileSize statistics.nodeHeapStats.usedHeapSize}} tr th {{_ 'Node_heap_heap_size_limit'}} - td {{bytesToSize statistics.nodeHeapStats.heapSizeLimit}} + td {{fileSize statistics.nodeHeapStats.heapSizeLimit}} tr th {{_ 'Node_heap_malloced_memory'}} - td {{bytesToSize statistics.nodeHeapStats.mallocedMemory}} + td {{fileSize statistics.nodeHeapStats.mallocedMemory}} tr th {{_ 'Node_heap_peak_malloced_memory'}} - td {{bytesToSize statistics.nodeHeapStats.peakMallocedMemory}} + td {{fileSize statistics.nodeHeapStats.peakMallocedMemory}} tr th {{_ 'Node_heap_does_zap_garbage'}} td {{statistics.nodeHeapStats.doesZapGarbage}} @@ -101,13 +101,13 @@ template(name='statistics') td {{statistics.nodeHeapStats.numberOfDetachedContexts}} tr th {{_ 'Node_memory_usage_rss'}} - td {{bytesToSize statistics.nodeMemoryUsage.rss}} + td {{fileSize statistics.nodeMemoryUsage.rss}} tr th {{_ 'Node_memory_usage_heap_total'}} - td {{bytesToSize statistics.nodeMemoryUsage.heapTotal}} + td {{fileSize statistics.nodeMemoryUsage.heapTotal}} tr th {{_ 'Node_memory_usage_heap_used'}} - td {{bytesToSize statistics.nodeMemoryUsage.heapUsed}} + td {{fileSize statistics.nodeMemoryUsage.heapUsed}} tr th {{_ 'Node_memory_usage_external'}} - td {{bytesToSize statistics.nodeMemoryUsage.external}} + td {{fileSize statistics.nodeMemoryUsage.external}} diff --git a/client/components/settings/informationBody.js b/client/components/settings/informationBody.js index 6bab8b3ac..c397c0fd0 100644 --- a/client/components/settings/informationBody.js +++ b/client/components/settings/informationBody.js @@ -1,4 +1,5 @@ import { TAPi18n } from '/imports/i18n'; +const filesize = require('filesize'); BlazeComponent.extendComponent({ onCreated() { @@ -39,12 +40,8 @@ BlazeComponent.extendComponent({ return parseFloat(number).toFixed(2); }, - bytesToSize(bytes) { - const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB']; - if (bytes === 0) { - return '0 Byte'; - } - const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)), 10); - return `${Math.round(bytes / Math.pow(1024, i), 2)} ${sizes[i]}`; + fileSize(size) { + const ret = filesize(size); + return ret; }, }).register('statistics');