Merge pull request #253 from Zephyrrus/fix/fetching_restricted_data_on_public_album

fix: trying to fetch tags and albums on a public album link
This commit is contained in:
Kana 2021-01-19 02:36:28 +09:00 committed by GitHub
commit e1e1a8ba0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 56 deletions

View File

@ -227,17 +227,14 @@ export default {
showList: 'displayTypeChange' showList: 'displayTypeChange'
}, },
created() { created() {
// TODO: Create a middleware for this if (!this.isPublic) {
this.getAlbums(); this.$handler.executeAction('albums/getTinyDetails', null, false);
this.getTags(); this.$handler.executeAction('tags/fetch', null, false);
}
this.showList = this.images.showList; this.showList = this.images.showList;
}, },
methods: { methods: {
async search() {
const data = await this.$search.do(this.searchTerm, ['name', 'original', 'type', 'albums:name']);
console.log('> Search result data', data); // eslint-disable-line no-console
},
deleteFile(file) { deleteFile(file) {
// this.$emit('delete', file); // this.$emit('delete', file);
this.$buefy.dialog.confirm({ this.$buefy.dialog.confirm({
@ -246,13 +243,7 @@ export default {
confirmText: 'Delete File', confirmText: 'Delete File',
type: 'is-danger', type: 'is-danger',
onConfirm: async () => { onConfirm: async () => {
try { await this.$handler.executeAction('images/deleteFile', file.id);
const response = await this.$store.dispatch('images/deleteFile', file.id);
this.$buefy.toast.open(response.message);
} catch (e) {
this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
} }
}); });
}, },
@ -266,41 +257,17 @@ export default {
this.showingModalForFile = file; this.showingModalForFile = file;
this.showingModalForFile.albums = []; this.showingModalForFile.albums = [];
try { await this.$handler.executeAction('images/getFileAlbums', id, false);
await this.$store.dispatch('images/getFileAlbums', id);
} catch (e) {
this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
this.showingModalForFile.albums = this.images.fileAlbumsMap[id]; this.showingModalForFile.albums = this.images.fileAlbumsMap[id];
this.isAlbumsModalActive = true; this.isAlbumsModalActive = true;
}, },
async albumCheckboxClicked(add, id) { async albumCheckboxClicked(add, id) {
try { await this.$handler.executeAction(add ? 'images/addToAlbum' : 'images/removeFromAlbum', {
let response; albumId: id,
if (add) { fileId: this.showingModalForFile.id
response = await this.$store.dispatch('images/addToAlbum', { });
albumId: id,
fileId: this.showingModalForFile.id
});
} else {
response = await this.$store.dispatch('images/removeFromAlbum', {
albumId: id,
fileId: this.showingModalForFile.id
});
}
this.$buefy.toast.open(response.message);
} catch (e) {
this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
},
async getAlbums() {
try {
await this.$store.dispatch('albums/getTinyDetails');
} catch (e) {
this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
}, },
async handleFileModal(file) { async handleFileModal(file) {
const { id } = file; const { id } = file;
@ -316,13 +283,6 @@ export default {
this.isAlbumsModalActive = true; this.isAlbumsModalActive = true;
}, },
async getTags() {
try {
await this.$store.dispatch('tags/fetch');
} catch (e) {
this.$store.dispatch('alert/set', { text: e.message, error: true }, { root: true });
}
},
mouseOver(id) { mouseOver(id) {
const foundIndex = this.hoveredItems.indexOf(id); const foundIndex = this.hoveredItems.indexOf(id);
if (foundIndex > -1) return; if (foundIndex > -1) return;

View File

@ -2,14 +2,16 @@ import AlertTypes from '~/constants/alertTypes';
export default ({ store }, inject) => { export default ({ store }, inject) => {
inject('handler', { inject('handler', {
async executeAction(action, param) { async executeAction(action, param, showSuccess = true) {
try { try {
const response = await store.dispatch(action, param); const response = await store.dispatch(action, param);
store.commit('alert/set', { if (showSuccess) {
message: response?.message ?? 'Executed sucesfully', store.commit('alert/set', {
type: AlertTypes.SUCCESS message: response?.message ?? 'Executed sucesfully',
}); type: AlertTypes.SUCCESS
});
}
return response; return response;
} catch (e) { } catch (e) {