فهرست منبع

Use 1024 based file size units to follow consistency

Ribas160 1 سال پیش
والد
کامیت
a2ca2ecb37
3فایلهای تغییر یافته به همراه11 افزوده شده و 30 حذف شده
  1. 3 22
      js/privatebin.js
  2. 7 7
      js/test/Helper.js
  3. 1 1
      lib/Configuration.php

+ 3 - 22
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
          *

+ 7 - 7
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';
         });
     });
 });

+ 1 - 1
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==',