From ba188eddab7f6eb8747bc43c179a8478d4f2a5a4 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Sat, 8 Dec 2018 18:23:21 +0300 Subject: [pleroma#36] Add upload errors --- src/components/media_upload/media_upload.js | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 66337c3f..c2f3c3c7 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -21,6 +21,10 @@ const mediaUpload = { uploadFile (file) { const self = this const store = this.$store + if (file.size > store.state.instance.uploadlimit) { + self.$emit('upload-failed', 'upload_error_file_too_big') + return + } const formData = new FormData() formData.append('media', file) -- cgit v1.2.3-70-g09d2 From f69331e49d19a26be27d1188f721703fe04a493d Mon Sep 17 00:00:00 2001 From: rinpatch Date: Sat, 8 Dec 2018 22:36:54 +0100 Subject: Improve error messages --- src/components/media_upload/media_upload.js | 4 ++-- src/components/post_status_form/post_status_form.js | 6 +++--- src/i18n/en.json | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index c2f3c3c7..91ae3627 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -22,7 +22,7 @@ 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') + self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: file.size, allowedsize: store.state.instance.uploadlimit}) return } const formData = new FormData() @@ -36,7 +36,7 @@ const mediaUpload = { self.$emit('uploaded', fileData) self.uploading = false }, (error) => { // eslint-disable-line handle-callback-err - self.$emit('upload-failed') + self.$emit('upload-failed', 'upload_error_generic') self.uploading = false }) }, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index f7ba3cd5..5f092da3 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -262,9 +262,9 @@ const PostStatusForm = { let index = this.newStatus.files.indexOf(fileInfo) this.newStatus.files.splice(index, 1) }, - uploadFailed (errString) { - errString = errString || 'upload_error' - this.error = this.$t('post_status.' + errString) + uploadFailed (errString, templateArgs) { + templateArgs = templateArgs || {}; + this.error = this.$t('post_status.upload_error') + ' ' + this.$t('post_status.' + errString, templateArgs) this.enableSubmit() }, disableSubmit () { diff --git a/src/i18n/en.json b/src/i18n/en.json index 93a24743..17c28c61 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -53,7 +53,8 @@ "account_not_locked_warning_link": "locked", "attachments_sensitive": "Mark attachments as sensitive", "upload_error": "Upload failed.", - "upload_error_file_too_big": "Upload failed. File too big", + "upload_error_file_too_big": "File too big [{filesize}/{allowedsize}]", + "upload_error_generic": "Try again later", "content_type": { "plain_text": "Plain text" }, -- cgit v1.2.3-70-g09d2 From c69a8dc197c87eb69272c28c1c1501e3c6d6d9aa Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 09:50:04 +0300 Subject: Add file size formating --- src/components/media_upload/media_upload.js | 4 +++- src/i18n/en.json | 7 +++++++ src/services/file_size_format/.file_size_format.js.swp | Bin 0 -> 12288 bytes src/services/file_size_format/file_size_format.js | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/services/file_size_format/.file_size_format.js.swp create mode 100644 src/services/file_size_format/file_size_format.js (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 91ae3627..1927a194 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -1,5 +1,7 @@ /* eslint-env browser */ import statusPosterService from '../../services/status_poster/status_poster.service.js' +import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' + const mediaUpload = { mounted () { @@ -22,7 +24,7 @@ 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: file.size, allowedsize: 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)}) return } const formData = new FormData() diff --git a/src/i18n/en.json b/src/i18n/en.json index 17c28c61..885974e4 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -229,5 +229,12 @@ "reply": "Reply", "favorite": "Favorite", "user_settings": "User Settings" + }, + "file_size_units": { + "B": "B", + "KB": "KB", + "MB": "MB", + "GB": "GB", + "TB": "TB" } } diff --git a/src/services/file_size_format/.file_size_format.js.swp b/src/services/file_size_format/.file_size_format.js.swp new file mode 100644 index 00000000..ec2e601a Binary files /dev/null and b/src/services/file_size_format/.file_size_format.js.swp differ diff --git a/src/services/file_size_format/file_size_format.js b/src/services/file_size_format/file_size_format.js new file mode 100644 index 00000000..5d22b473 --- /dev/null +++ b/src/services/file_size_format/file_size_format.js @@ -0,0 +1,17 @@ +const fileSizeFormat = (num, t) => { + 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')] + 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 + unit = units[exponent] + return num + ' ' + unit +} +const fileSizeFormatService = { + fileSizeFormat +} +export default fileSizeFormatService -- cgit v1.2.3-70-g09d2 From 5c7a316df96ef81dde37d27a816616017192a415 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 09:56:07 +0300 Subject: Lint --- src/components/media_upload/media_upload.js | 1 - 1 file changed, 1 deletion(-) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 1927a194..37dab32b 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -2,7 +2,6 @@ import statusPosterService from '../../services/status_poster/status_poster.service.js' import fileSizeFormatService from '../../services/file_size_format/file_size_format.js' - const mediaUpload = { mounted () { const input = this.$el.querySelector('input') -- cgit v1.2.3-70-g09d2 From 6a008541898e354fbd98857787020640407b1dd3 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Mon, 10 Dec 2018 17:06:32 +0300 Subject: 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 +++++----- src/services/file_size_format/.file_size_format.js.swp | Bin 12288 -> 0 bytes src/services/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 (limited to 'src/components/media_upload/media_upload.js') 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 -- cgit v1.2.3-70-g09d2 From bf8bb9ce134c8712885e52d005c6d130fca4e553 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Wed, 12 Dec 2018 16:38:01 +0300 Subject: Moved upload errors in user_settings to an array. Moved upload error strings to its separate section in i18n --- src/components/media_upload/media_upload.js | 4 +-- .../post_status_form/post_status_form.js | 2 +- src/components/user_settings/user_settings.js | 41 ++++------------------ src/components/user_settings/user_settings.vue | 12 +++---- src/i18n/en.json | 22 +++++++----- 5 files changed, 29 insertions(+), 52 deletions(-) (limited to 'src/components/media_upload/media_upload.js') diff --git a/src/components/media_upload/media_upload.js b/src/components/media_upload/media_upload.js index 31d36487..42d900d3 100644 --- a/src/components/media_upload/media_upload.js +++ b/src/components/media_upload/media_upload.js @@ -25,7 +25,7 @@ const mediaUpload = { if (file.size > store.state.instance.uploadlimit) { 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}) + self.$emit('upload-failed', 'file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) return } const formData = new FormData() @@ -39,7 +39,7 @@ const mediaUpload = { self.$emit('uploaded', fileData) self.uploading = false }, (error) => { // eslint-disable-line handle-callback-err - self.$emit('upload-failed', 'upload_error_generic') + self.$emit('upload-failed', 'default') self.uploading = false }) }, diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index f8225fb2..3899027f 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -264,7 +264,7 @@ const PostStatusForm = { }, uploadFailed (errString, templateArgs) { templateArgs = templateArgs || {} - this.error = this.$t('post_status.upload_error') + ' ' + this.$t('post_status.' + errString, templateArgs) + this.error = this.$t('upload.error.base') + ' ' + this.$t('upload.error.' + errString, templateArgs) this.enableSubmit() }, disableSubmit () { diff --git a/src/components/user_settings/user_settings.js b/src/components/user_settings/user_settings.js index ed9178fa..424d0b85 100644 --- a/src/components/user_settings/user_settings.js +++ b/src/components/user_settings/user_settings.js @@ -5,9 +5,7 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for const UserSettings = { data () { return { - avataruploaderror: null, - backgrounduploaderror: null, - banneruploaderror: null, + uploaderror: [null, null, null], newname: this.$store.state.users.currentUser.name, newbio: this.$store.state.users.currentUser.description, newlocked: this.$store.state.users.currentUser.locked, @@ -73,27 +71,12 @@ const UserSettings = { uploadFile (slot, e) { const file = e.target.files[0] if (!file) { return } - var limit = 0 - var error = () => {} - switch (slot) { - case 0: - limit = this.$store.state.instance.avatarlimit - error = (error) => { this.avataruploaderror = error } - break - case 1: - limit = this.$store.state.instance.bannerlimit - error = (error) => { this.banneruploaderror = error } - break - case 2: - limit = this.$store.state.instance.backgroundlimit - error = (error) => { this.backgrounduploaderror = error } - } - console.log(this.$store) - console.log(file.size + ' ' + slot + ' ' + limit) - if (file.size > limit) { + var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit] + console.log(file.size, limit) + if (file.size > limit[slot]) { const filesize = fileSizeFormatService.fileSizeFormat(file.size) - const allowedsize = fileSizeFormatService.fileSizeFormat(limit) - error(this.$t('post_status.upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) + const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot]) + this.$set(this.uploaderror, slot, this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) return } // eslint-disable-next-line no-undef @@ -135,17 +118,7 @@ const UserSettings = { }) }, clearUploadError (slot) { - switch (slot) { - case 0: - this.avataruploaderror = null - break - case 1: - this.banneruploaderror = null - break - case 2: - this.backgrounduploaderror = null - break - } + this.$set(this.uploaderror, slot, null) }, submitBanner () { if (!this.previews[1]) { return } diff --git a/src/components/user_settings/user_settings.vue b/src/components/user_settings/user_settings.vue index 12bc953e..22c4fe41 100644 --- a/src/components/user_settings/user_settings.vue +++ b/src/components/user_settings/user_settings.vue @@ -43,8 +43,8 @@ -
- Error: {{ avataruploaderror }} +
+ Error: {{ uploaderror[0] }}
@@ -60,8 +60,8 @@ -
- Error: {{ banneruploaderror }} +
+ Error: {{ uploaderror[1] }}
@@ -75,8 +75,8 @@ -
- Error: {{ backgrounduploaderror }} +
+ Error: {{ uploaderror[2] }}
diff --git a/src/i18n/en.json b/src/i18n/en.json index 5697bae7..dae2f286 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -52,9 +52,6 @@ "account_not_locked_warning": "Your account is not {0}. Anyone can follow you to view your follower-only posts.", "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}{filesizeunit} / {allowedsize}{allowedsizeunit}]", - "upload_error_generic": "Try again later", "content_type": { "plain_text": "Plain text" }, @@ -230,11 +227,18 @@ "favorite": "Favorite", "user_settings": "User Settings" }, - "file_size_units": { - "B": "B", - "KiB": "KiB", - "MiB": "MiB", - "GiB": "GiB", - "TiB": "TiB" + "upload":{ + "error": { + "base": "Upload failed.", + "file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]", + "default": "Try again later" + }, + "file_size_units": { + "B": "B", + "KiB": "KiB", + "MiB": "MiB", + "GiB": "GiB", + "TiB": "TiB" + } } } -- cgit v1.2.3-70-g09d2