From ba188eddab7f6eb8747bc43c179a8478d4f2a5a4 Mon Sep 17 00:00:00 2001 From: Rinpatch Date: Sat, 8 Dec 2018 18:23:21 +0300 Subject: [PATCH] [pleroma#36] Add upload errors --- src/boot/after_store.js | 3 ++- src/components/media_upload/media_upload.js | 4 ++++ src/components/post_status_form/post_status_form.js | 5 +++++ src/components/post_status_form/post_status_form.vue | 2 +- src/i18n/en.json | 2 ++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/boot/after_store.js b/src/boot/after_store.js index a80baaf5..38810326 100644 --- a/src/boot/after_store.js +++ b/src/boot/after_store.js @@ -21,11 +21,12 @@ const afterStoreSetup = ({store, i18n}) => { window.fetch('/api/statusnet/config.json') .then((res) => res.json()) .then((data) => { - const {name, closed: registrationClosed, textlimit, server} = data.site + const {name, closed: registrationClosed, textlimit, uploadlimit, server} = data.site store.dispatch('setInstanceOption', { name: 'name', value: name }) store.dispatch('setInstanceOption', { name: 'registrationOpen', value: (registrationClosed === '0') }) store.dispatch('setInstanceOption', { name: 'textlimit', value: parseInt(textlimit) }) + store.dispatch('setInstanceOption', { name: 'uploadlimit', value: parseInt(uploadlimit) }) store.dispatch('setInstanceOption', { name: 'server', value: server }) var apiConfig = data.site.pleromafe 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) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index 789243cf..f7ba3cd5 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -262,6 +262,11 @@ 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) + this.enableSubmit() + }, disableSubmit () { this.submitDisabled = true }, diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index e4c46b9a..59ae9af4 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -64,7 +64,7 @@
- +

{{ charactersLeft }}

{{ charactersLeft }}

diff --git a/src/i18n/en.json b/src/i18n/en.json index 44291ad0..93a24743 100644 --- a/src/i18n/en.json +++ b/src/i18n/en.json @@ -52,6 +52,8 @@ "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": "Upload failed. File too big", "content_type": { "plain_text": "Plain text" },