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 ec2e601a..00000000 Binary files a/src/services/file_size_format/.file_size_format.js.swp and /dev/null differ 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