diff --git a/CHANGELOG.md b/CHANGELOG.md
index 726f330..c7979ec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ As this project is a user-facing application, the places in the semantic version
### Fixed
- Downloading source file was broken for binary files
+- Correct file size outputs using binary base instead of decimal
## [1.0.2] (2023-10-03)
diff --git a/src/corpus/sources/UploadSizeLimits.vue b/src/corpus/sources/UploadSizeLimits.vue
index 796996b..b09d28d 100644
--- a/src/corpus/sources/UploadSizeLimits.vue
+++ b/src/corpus/sources/UploadSizeLimits.vue
@@ -3,6 +3,7 @@ import useMinkBackendInfo from "@/api/backendInfo.composable";
import useLocale from "@/i18n/locale.composable";
const { hasInfo, findInfo } = useMinkBackendInfo();
+// Use filesize with precision 0 to have "1 MB" instead of "1.0 MB".
const { filesize } = useLocale();
@@ -11,19 +12,19 @@ const { filesize } = useLocale();
{{ $t("source.limit.file.recommended") }} |
- {{ filesize(findInfo("recommended_file_size", "max_file_length")) }}
+ {{ filesize(findInfo("recommended_file_size", "max_file_length"), 0) }}
|
{{ $t("source.limit.file.max") }} |
- {{ filesize(findInfo("file_size_limits", "max_file_length")) }}
+ {{ filesize(findInfo("file_size_limits", "max_file_length"), 0) }}
|
{{ $t("source.limit.upload.max") }} |
- {{ filesize(findInfo("file_size_limits", "max_content_length")) }}
+ {{ filesize(findInfo("file_size_limits", "max_content_length"), 0) }}
|
diff --git a/src/i18n/locale.composable.js b/src/i18n/locale.composable.js
index 7ec4347..9b3e92e 100644
--- a/src/i18n/locale.composable.js
+++ b/src/i18n/locale.composable.js
@@ -40,8 +40,10 @@ export default function useLocale() {
);
}
- function myFilesize(bytes) {
- const str = filesize(bytes, { base: 2, locale: locale.value });
+ /** Wrap the filesize lib with some sane defaults and avoiding exponential notation. */
+ function myFilesize(bytes, precision = 2) {
+ // Default precision is 0 which means up until 2 decimals?
+ const str = filesize(bytes, { precision, base: 2, locale: locale.value });
// Convert exponential notation to ordinary.
return str.replace(/[\d.]+e[+\d]+/, parseFloat);
}