DEV: Use i18n.toHumanSize instead of formatBytes (#14415)

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.

diff --git a/app/assets/javascripts/discourse/app/lib/uploads.js b/app/assets/javascripts/discourse/app/lib/uploads.js
index f84f737..dc1f960 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]
-  );
-}

GitHub sha: effc3ef7b450eddaeae2e181ec53b1b53ab6f801

This commit appears in #14415 which was approved by awesomerobot. It was merged by martin.