From ea3e503d13b7be477c064b02b9b2e5a9ef06c9a9 Mon Sep 17 00:00:00 2001 From: Pitu Date: Fri, 29 Mar 2019 00:35:58 +0900 Subject: Added middleware for pages and switched to $axios --- src/site/pages/dashboard/albums/_id.vue | 13 +++++++------ src/site/pages/dashboard/albums/index.vue | 29 +++++++++++++++-------------- 2 files changed, 22 insertions(+), 20 deletions(-) (limited to 'src/site/pages/dashboard/albums') diff --git a/src/site/pages/dashboard/albums/_id.vue b/src/site/pages/dashboard/albums/_id.vue index f5ec683..ed5f8fd 100644 --- a/src/site/pages/dashboard/albums/_id.vue +++ b/src/site/pages/dashboard/albums/_id.vue @@ -61,6 +61,7 @@ export default { Sidebar, Grid }, + middleware: 'auth', data() { return { name: null, @@ -94,11 +95,11 @@ export default { }, async albumCheckboxClicked(value, id) { try { - const response = await this.axios.post(`${this.config.baseURL}/file/album/${value ? 'add' : 'del'}`, { + const response = await this.$axios.$post(`file/album/${value ? 'add' : 'del'}`, { albumId: id, fileId: this.showingModalForFile.id }); - this.$toast.open(response.data.message); + this.$toast.open(response.message); this.getFiles(); } catch (error) { this.$onPromiseError(error); @@ -107,16 +108,16 @@ export default { async getFiles() { // TODO: Make this think SSR with AsyncData try { - const response = await this.axios.get(`${this.config.baseURL}/album/${this.$route.params.id}/full`); - this.files = response.data.files; + const response = await this.$axios.$get(`album/${this.$route.params.id}/full`); + this.files = response.files; } catch (error) { console.error(error); } }, async getAlbums() { try { - const response = await this.axios.get(`${this.config.baseURL}/albums/dropdown`); - this.albums = response.data.albums; + const response = await this.$axios.$get(`albums/dropdown`); + this.albums = response.albums; } catch (error) { this.$onPromiseError(error); } diff --git a/src/site/pages/dashboard/albums/index.vue b/src/site/pages/dashboard/albums/index.vue index 1ad7653..c2c054d 100644 --- a/src/site/pages/dashboard/albums/index.vue +++ b/src/site/pages/dashboard/albums/index.vue @@ -275,6 +275,7 @@ export default { components: { Sidebar }, + middleware: 'auth', data() { return { albums: [], @@ -310,9 +311,9 @@ export default { }, async deleteAlbum(id, purge) { try { - const response = await this.axios.delete(`${this.config.baseURL}/album/${id}/${purge ? true : ''}`); + const response = await this.$axios.$delete(`album/${id}/${purge ? true : ''}`); this.getAlbums(); - return this.$toast.open(response.data.message); + return this.$toast.open(response.message); } catch (error) { return this.$onPromiseError(error); } @@ -326,21 +327,21 @@ export default { async deleteAlbumLink(identifier) { console.log('> deleteAlbumLink', identifier); try { - const response = await this.axios.delete(`${this.config.baseURL}/album/link/delete/${identifier}`); - return this.$toast.open(response.data.message); + const response = await this.$axios.$delete(`album/link/delete/${identifier}`); + return this.$toast.open(response.message); } catch (error) { return this.$onPromiseError(error); } }, async linkOptionsChanged(link) { try { - const response = await this.axios.post(`${this.config.baseURL}/album/link/edit`, + const response = await this.$axios.$post(`album/link/edit`, { identifier: link.identifier, enableDownload: link.enableDownload, enabled: link.enabled }); - this.$toast.open(response.data.message); + this.$toast.open(response.message); } catch (error) { this.$onPromiseError(error); } @@ -348,11 +349,11 @@ export default { async createLink(album) { album.isCreatingLink = true; try { - const response = await this.axios.post(`${this.config.baseURL}/album/link/new`, + const response = await this.$axios.$post(`album/link/new`, { albumId: album.id }); - this.$toast.open(response.data.message); + this.$toast.open(response.message); album.links.push({ - identifier: response.data.identifier, + identifier: response.identifier, views: 0, enabled: true, enableDownload: true, @@ -367,10 +368,10 @@ export default { async createAlbum() { if (!this.newAlbumName || this.newAlbumName === '') return; try { - const response = await this.axios.post(`${this.config.baseURL}/album/new`, + const response = await this.$axios.$post(`album/new`, { name: this.newAlbumName }); this.newAlbumName = null; - this.$toast.open(response.data.message); + this.$toast.open(response.message); this.getAlbums(); } catch (error) { this.$onPromiseError(error); @@ -378,11 +379,11 @@ export default { }, async getAlbums() { try { - const response = await this.axios.get(`${this.config.baseURL}/albums/mini`); - for (const album of response.data.albums) { + const response = await this.$axios.$get(`albums/mini`); + for (const album of response.albums) { album.isDetailsOpen = false; } - this.albums = response.data.albums; + this.albums = response.albums; } catch (error) { this.$onPromiseError(error); } -- cgit v1.2.3