From 403d260b91c8ddb559a9e63095dbedbe3cc0d41e Mon Sep 17 00:00:00 2001 From: sinsong Date: Fri, 30 Jun 2023 23:21:54 +0800 Subject: [PATCH] use constant --- frontend/src/utils/sizing.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/utils/sizing.js b/frontend/src/utils/sizing.js index ff19996..0185434 100644 --- a/frontend/src/utils/sizing.js +++ b/frontend/src/utils/sizing.js @@ -1,14 +1,16 @@ +const DATA_UNIT_FACTOR = 1024 + export function calculateSize(size) { function wellSized(num) { - return num > 1 && num < 1024 + return num > 1 && num < DATA_UNIT_FACTOR } if (size === undefined) { return } if (wellSized(size)) { return `${size.toFixed(1)} B` } - size /= 1024 + size /= DATA_UNIT_FACTOR if (wellSized(size)) { return `${size.toFixed(1)} KB` } - size /= 1024 + size /= DATA_UNIT_FACTOR if (wellSized(size)) { return `${size.toFixed(1)} MB` } - size /= 1024 + size /= DATA_UNIT_FACTOR if (wellSized(size)) { return `${size.toFixed(1)} GB` } console.error('size too big') }