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

Follow up to dba6a5eabf. I
introduced a new formatBytes function there unnecessarily
instead of using the existing toHumanSize.
This commit is contained in:
Martin Brennan 2021-09-22 10:27:18 +10:00 committed by GitHub
parent d0e1c222f7
commit effc3ef7b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 16 deletions

View File

@ -330,7 +330,7 @@ function displayErrorByResponseStatus(status, body, fileName, siteSettings) {
const max_size_kb = siteSettings[`max_${type}_size_kb`]; const max_size_kb = siteSettings[`max_${type}_size_kb`];
bootbox.alert( bootbox.alert(
I18n.t("post.errors.file_too_large_humanized", { 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; return true;
@ -358,18 +358,3 @@ export function bindFileInputChangeListener(element, fileCallbackFn) {
element.addEventListener("change", changeListener); element.addEventListener("change", changeListener);
return 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]
);
}