Count in binary bytes and remove i18 from file size format service
This commit is contained in:
parent
88145c5934
commit
6a00854189
@ -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()
|
||||
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user