From 3f8a1326dffb01512a1b19a141360180bf6b7fd8 Mon Sep 17 00:00:00 2001 From: Andinus Date: Fri, 4 Feb 2022 11:56:54 +0530 Subject: Implement upload functionality The authentication part on the server is not implemented properly. --- client/src/views/CreateSmiles.vue | 3 ++- client/src/views/ManageSmiles.vue | 43 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'client/src/views') diff --git a/client/src/views/CreateSmiles.vue b/client/src/views/CreateSmiles.vue index 7c285f0..88da1f4 100644 --- a/client/src/views/CreateSmiles.vue +++ b/client/src/views/CreateSmiles.vue @@ -112,7 +112,8 @@ export default { body: JSON.stringify(data) }).then(response => { if (!response.ok) - throw new Error('HTTP error, status = ' + response.status); + throw new Error('HTTP error, status = ' + response.status + + ' | ' + response.statusText); return response.json(); }).then(res => { this.id = res.id; diff --git a/client/src/views/ManageSmiles.vue b/client/src/views/ManageSmiles.vue index 9a535b7..370b908 100644 --- a/client/src/views/ManageSmiles.vue +++ b/client/src/views/ManageSmiles.vue @@ -25,7 +25,10 @@
- + @@ -61,6 +64,39 @@ export default { link.push(this.id); return link.join('/'); }, + beforeSend(xhr) { + xhr.formData.append('id', this.id); + xhr.formData.append('auth', this.auth); + }, + onError(error) { + this.$toast.add( + {severity: 'error', + summary: 'Upload failed', + detail: `${error.xhr.status} ${error.xhr.statusText} | ${error.xhr.response}`}); + }, + onUpload(res) { + const response = JSON.parse(res.xhr.response); + for(let i = 0; i < response.length; i++) { + const x = response[i]; + if (x.stored === false) { + this.$toast.add( + { + severity: 'error', + summary: 'Upload failed', + detail: `${x.filename}: ${x.messages}` + } + ); + } else if (x.messages.length !== 0) { + this.$toast.add( + { + severity: 'warn', + summary: 'Upload Issues', + detail: `${x.filename}: ${x.messages}` + } + ); + } + } + }, verify() { const data = { id: this.id, auth: this.auth }; const toast = this.$toast; @@ -73,12 +109,15 @@ export default { referrerPolicy: 'no-referrer', body: JSON.stringify(data) }).then(response => { + if (response.status === 401) + throw new Error(response.status + ' # ' + 'Authentication Failed'); + if (response.status === 404) + throw new Error(response.status + ' # ' + 'Smiles deleted or invalid link'); if (!response.ok) throw new Error('HTTP error, status = ' + response.status); return response.json(); }).then(res => { this.name = res.name; - console.log(res); this.verified = true; }).catch(error => { console.log(error) -- cgit 1.4.1-2-gfad0