From effc3ef7b450eddaeae2e181ec53b1b53ab6f801 Mon Sep 17 00:00:00 2001 From: Martin Brennan Date: Wed, 22 Sep 2021 10:27:18 +1000 Subject: [PATCH] DEV: Use i18n.toHumanSize instead of formatBytes (#14415) Follow up to dba6a5eabfba9e2ad98f62075eea5b9128e5f594. I introduced a new formatBytes function there unnecessarily instead of using the existing toHumanSize. --- .../javascripts/discourse/app/lib/uploads.js | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/assets/javascripts/discourse/app/lib/uploads.js b/app/assets/javascripts/discourse/app/lib/uploads.js index f84f7370a51..dc1f9605a52 100644 --- a/app/assets/javascripts/discourse/app/lib/uploads.js +++ b/app/assets/javascripts/discourse/app/lib/uploads.js @@ -330,7 +330,7 @@ function displayErrorByResponseStatus(status, body, fileName, siteSettings) { const max_size_kb = siteSettings[`max_${type}_size_kb`]; bootbox.alert( I18n.t("post.errors.file_too_large_humanized", { - max_size: formatBytes(max_size_kb * 1024), + max_size: I18n.toHumanSize(max_size_kb * 1024), }) ); return true; @@ -358,18 +358,3 @@ export function bindFileInputChangeListener(element, fileCallbackFn) { element.addEventListener("change", changeListener); return changeListener; } - -export function formatBytes(bytes, decimals) { - if (bytes === 0) { - return "0 Bytes"; - } - const kilobyte = 1024, - dm = decimals || 2, - sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"], - incr = Math.floor(Math.log(bytes) / Math.log(kilobyte)); - return ( - parseFloat((bytes / Math.pow(kilobyte, incr)).toFixed(dm)) + - " " + - sizes[incr] - ); -}