summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2023-09-24 16:45:50 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2023-09-24 17:13:00 +0200
commiteb73c0bafa1888e486c98187b19e152f3e549138 (patch)
tree7b9e624c47177b03d5381335a5107b3da7ecaa14
parente0adcc587ecf484502303ebf93b22af3d0d9d895 (diff)
downloadnextcloud-server-eb73c0bafa1888e486c98187b19e152f3e549138.tar.gz
nextcloud-server-eb73c0bafa1888e486c98187b19e152f3e549138.zip
fix: Revert change that made `OC.Util.humanFileSize` return base 10 instead of base 2
Previously the `OC.Util.humanFileSize` was returning file sizes base 2, meaning 1024 bytes = 1 KiB, but the `@nextcloud/files` library had a regression that set the default to base 10. Meaning 1000 bytes = 1 KB. This is fixed for current `@nextcloud/libraries` but for stable27 we need to fix this manually by wrapping the function. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
-rw-r--r--core/src/OC/util.js14
1 files changed, 6 insertions, 8 deletions
diff --git a/core/src/OC/util.js b/core/src/OC/util.js
index f0dd7e0ac14..9c3e5ffe9b5 100644
--- a/core/src/OC/util.js
+++ b/core/src/OC/util.js
@@ -64,9 +64,11 @@ export default {
History,
/**
- * @deprecated use https://nextcloud.github.io/nextcloud-files/functions/formatFileSize.html
+ * @param {number} size Size in bytes
+ * @param {boolean} skipSmallSizes return '< 1 KiB' for small files
+ * @deprecated use `@nextcloud/files`, see https://nextcloud-libraries.github.io/nextcloud-files/functions/formatFileSize.html
*/
- humanFileSize,
+ humanFileSize: (size, skipSmallSizes) => humanFileSize(size, skipSmallSizes, true).replace('iB', 'B'), // the replace is for backwards compatibility, where binary sizes but decimal units were used
/**
* Returns a file size in bytes from a humanly readable string
@@ -87,20 +89,16 @@ export default {
let bytes = null
const bytesArray = {
+ '': 1,
b: 1,
k: 1024,
- kb: 1024,
- mb: 1024 * 1024,
m: 1024 * 1024,
- gb: 1024 * 1024 * 1024,
g: 1024 * 1024 * 1024,
- tb: 1024 * 1024 * 1024 * 1024,
t: 1024 * 1024 * 1024 * 1024,
- pb: 1024 * 1024 * 1024 * 1024 * 1024,
p: 1024 * 1024 * 1024 * 1024 * 1024,
}
- const matches = s.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?b?)$/i)
+ const matches = s.match(/^[\s+]?([0-9]*)(\.([0-9]+))?( +)?([kmgtp]?)i?b?$/i)
if (matches !== null) {
bytes = parseFloat(s)
if (!isFinite(bytes)) {