From a2ca2ecb3730a14e4472eaf9796f4580e9db431b Mon Sep 17 00:00:00 2001 From: Ribas160 Date: Sat, 28 Jun 2025 14:00:50 +0300 Subject: [PATCH] Use 1024 based file size units to follow consistency --- js/privatebin.js | 25 +++---------------------- js/test/Helper.js | 14 +++++++------- lib/Configuration.php | 2 +- 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/js/privatebin.js b/js/privatebin.js index 639fff54..7298db65 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -592,7 +592,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { }; /** - * Convert Bytes to KB/MB/GB + * Convert Bytes to KiB/MiB/GiB * * @name Helper.formatBytes * @function @@ -603,9 +603,9 @@ jQuery.PrivateBin = (function($, RawDeflate) { me.formatBytes = function (bytes) { let result = ''; - const kilobyte = 1000; + const kilobyte = 1024; const decimalPoint = 2; - const sizes = [I18n._('B'), I18n._('KB'), I18n._('MB'), I18n._('GB')]; + const sizes = [I18n._('B'), I18n._('KiB'), I18n._('MiB'), I18n._('GiB')]; const index = Math.floor(Math.log(bytes) / Math.log(kilobyte)); if (bytes > 0) { @@ -3230,25 +3230,6 @@ jQuery.PrivateBin = (function($, RawDeflate) { return attachmentData.substring(5, mimeTypeEnd); } - /** - * Get attachment size in B/KB/MB/GB - * - * @name AttachmentViewer.getAttachmentSize - * @function - * @param {string} attachmentData - Base64 string - */ - me.getAttachmentSize = function(attachmentData) - { - const base64Start = attachmentData.indexOf(',') + 1; - const rawData = attachmentData.substring(base64Start); - const decodedData = rawData.length > 0 ? atob(rawData) : ''; - - const buf = new Uint8Array(decodedData.length); - const bytes = new Blob([buf]).size; - - return Helper.formatBytes(bytes); - } - /** * moves the attachment link to another element * diff --git a/js/test/Helper.js b/js/test/Helper.js index 4f751897..6308fdc0 100644 --- a/js/test/Helper.js +++ b/js/test/Helper.js @@ -300,20 +300,20 @@ describe('Helper', function () { return $.PrivateBin.Helper.formatBytes(500) === '500 B'; }); - jsc.property('formats kilobytes correctly', function () { - return $.PrivateBin.Helper.formatBytes(1500) === '1.5 KB'; + jsc.property('formats kibibytes correctly', function () { + return $.PrivateBin.Helper.formatBytes(1500) === '1.46 KiB'; }); - jsc.property('formats megabytes correctly', function () { - return $.PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '2 MB'; + jsc.property('formats mebibytes correctly', function () { + return $.PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '1.91 MiB'; }); - jsc.property('formats gigabytes correctly', function () { - return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.45 GB'; + jsc.property('formats gibibytes correctly', function () { + return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.21 GiB'; }); jsc.property('rounds to two decimal places', function () { - return $.PrivateBin.Helper.formatBytes(1234567) === '1.23 MB'; + return $.PrivateBin.Helper.formatBytes(1234567) === '1.18 MiB'; }); }); }); diff --git a/lib/Configuration.php b/lib/Configuration.php index f097e288..ab8aaf19 100644 --- a/lib/Configuration.php +++ b/lib/Configuration.php @@ -119,7 +119,7 @@ class Configuration 'js/kjua-0.9.0.js' => 'sha512-CVn7af+vTMBd9RjoS4QM5fpLFEOtBCoB0zPtaqIDC7sF4F8qgUSRFQQpIyEDGsr6yrjbuOLzdf20tkHHmpaqwQ==', 'js/legacy.js' => 'sha512-UxW/TOZKon83n6dk/09GsYKIyeO5LeBHokxyIq+r7KFS5KMBeIB/EM7NrkVYIezwZBaovnyNtY2d9tKFicRlXg==', 'js/prettify.js' => 'sha512-puO0Ogy++IoA2Pb9IjSxV1n4+kQkKXYAEUtVzfZpQepyDPyXk8hokiYDS7ybMogYlyyEIwMLpZqVhCkARQWLMg==', - 'js/privatebin.js' => 'sha512-rRy19m1V347H457Vcvy0IpbuohAuvIPgVY4s+FgoSn9avqFj3lYA4W/Ewz3DS+BekCUvVm9I8/YMbW82PzgFmQ==', + 'js/privatebin.js' => 'sha512-zvJ6Feu2NvROB236BBxbP+8eYbUTJ5GCfhOJVL/RI6pJQpR3AS4ps0d1cVDqgUFW8wY0tiwE7JTE13gPWO3lHA==', 'js/purify-3.2.6.js' => 'sha512-zqwL4OoBLFx89QPewkz4Lz5CSA2ktU+f31fuECkF0iK3Id5qd3Zpq5dMby8KwHjIEpsUgOqwF58cnmcaNem0EA==', 'js/rawinflate-0.3.js' => 'sha512-g8uelGgJW9A/Z1tB6Izxab++oj5kdD7B4qC7DHwZkB6DGMXKyzx7v5mvap2HXueI2IIn08YlRYM56jwWdm2ucQ==', 'js/showdown-2.1.0.js' => 'sha512-WYXZgkTR0u/Y9SVIA4nTTOih0kXMEd8RRV6MLFdL6YU8ymhR528NLlYQt1nlJQbYz4EW+ZsS0fx1awhiQJme1Q==',