From 6a008541898e354fbd98857787020640407b1dd3 Mon Sep 17 00:00:00 2001
From: Rinpatch <rinpatch@sdf.org>
Date: Mon, 10 Dec 2018 17:06:32 +0300
Subject: [PATCH] Count in binary bytes and remove i18 from file size format
 service

---
 src/components/media_upload/media_upload.js     |   4 +++-
 src/i18n/en.json                                |  10 +++++-----
 .../file_size_format/.file_size_format.js.swp   | Bin 12288 -> 0 bytes
 .../file_size_format/file_size_format.js        |  10 +++++-----
 4 files changed, 13 insertions(+), 11 deletions(-)
 delete mode 100644 src/services/file_size_format/.file_size_format.js.swp

diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js
index 37dab32b..31d36487 100644
--- a/src/components/media_upload/media_upload.js
+++ b/src/components/media_upload/media_upload.js
@@ -23,7 +23,9 @@ const mediaUpload = {
       const self = this
       const store = this.$store
       if (file.size > store.state.instance.uploadlimit) {
-        self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: fileSizeFormatService.fileSizeFormat(file.size, self.$t), allowedsize: fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit, self.$t)})
+        const filesize = fileSizeFormatService.fileSizeFormat(file.size)
+        const allowedsize = fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit)
+        self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})
         return
       }
       const formData = new FormData()
diff --git a/src/i18n/en.json b/src/i18n/en.json
index ace0a315..5697bae7 100644
--- a/src/i18n/en.json
+++ b/src/i18n/en.json
@@ -53,7 +53,7 @@
     "account_not_locked_warning_link": "locked",
     "attachments_sensitive": "Mark attachments as sensitive",
     "upload_error": "Upload failed.",
-    "upload_error_file_too_big": "File too big [{filesize} / {allowedsize}]",
+    "upload_error_file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]",
     "upload_error_generic": "Try again later",
     "content_type": {
       "plain_text": "Plain text"
@@ -232,9 +232,9 @@
   },
   "file_size_units": {
     "B": "B",
-    "KB": "KB",
-    "MB": "MB",
-    "GB": "GB",
-    "TB": "TB"
+    "KiB": "KiB",
+    "MiB": "MiB",
+    "GiB": "GiB",
+    "TiB": "TiB"
   }
 }
diff --git a/src/services/file_size_format/.file_size_format.js.swp b/src/services/file_size_format/.file_size_format.js.swp
deleted file mode 100644
index ec2e601a88a5a48a3ac815db974cb0346e64ff92..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 12288
zcmeI2&2G~`5XaX@hyyfyJpe-yicK5aDH6(|0Tn?JLOGy9F9B61S+_>EH(IYt1p<z|
z3@^bM!~?(s@EXkeLr9@67cQXxM*r-`%#LS%Q4Ue&MY#KLLL)yEJT3_F_-yalnQvd6
z(cBSQCie7?<Nof}APoIf&7$-q=XV@1xTj`iCUa8+i&ScrMT1xdg`Ne4)Q8DT7D1e(
za<52U%e`3XEHb|x_%Dl-9s?T)fWR_=(!_(&inzHktiI~kR<F|KOHY@*um=GU009sH
z0T2KI5C8!X_>T#gg(Kc`eW#ilFE+EYG&fsJAOHd&00JNY0w4eaAOHd&00JNY0{<X^
zXfDKu6(N4G?EnAm@Bi=Th4{ky#Ja`0&N|I<Sc3JjCxl^5SzD|-tShV@>m19*`)p%k
zfB*=900@8p2!H?xfB*=900{hD0<s=Q3#E<hc&E9HqcSyQTda4u!+N`Fu->UVuf<zI
zOBOLxdC}ocV|r6v(bAMUr@YK)jr#mrqcTqn2eT8q*{PV?q;hWje$EE#J0{mo0Zk%v
z;4joGcNm7@I<<bD=Nq-19Lc%6;n58m^1ar^m#bS@lDpL+PL<O2GFAIFu-8VmdmGvF
z*6U3CROb8UfCe=51P8Tc6LnNkOhcP+64%*o@*OUl=rGcCG)`q|-2Sho^{QI`Zl51_
l%=x1(!=%gbpv&-t4K}wnm1fy8I`*?`sB>x_jc;=$KLN3F@D2a~

diff --git a/src/services/file_size_format/file_size_format.js b/src/services/file_size_format/file_size_format.js
index 5d22b473..add56ee0 100644
--- a/src/services/file_size_format/file_size_format.js
+++ b/src/services/file_size_format/file_size_format.js
@@ -1,15 +1,15 @@
-const fileSizeFormat = (num, t) => {
+const fileSizeFormat = (num) => {
   var exponent
   var unit
-  var units = [t('file_size_units.B'), t('file_size_units.KB'), t('file_size_units.MB'), t('file_size_units.GB'), t('file_size_units.TB')]
+  var units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']
   if (num < 1) {
     return num + ' ' + units[0]
   }
 
-  exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1)
-  num = (num / Math.pow(1000, exponent)).toFixed(2) * 1
+  exponent = Math.min(Math.floor(Math.log(num) / Math.log(1024)), units.length - 1)
+  num = (num / Math.pow(1024, exponent)).toFixed(2) * 1
   unit = units[exponent]
-  return num + ' ' + unit
+  return {num: num, unit: unit}
 }
 const fileSizeFormatService = {
   fileSizeFormat