diff --git a/client/components/modals/BatchQuickMatchModel.vue b/client/components/modals/BatchQuickMatchModel.vue index 77eb851e..0df66dfd 100644 --- a/client/components/modals/BatchQuickMatchModel.vue +++ b/client/components/modals/BatchQuickMatchModel.vue @@ -124,17 +124,8 @@ export default { options: this.options, libraryItemIds: this.selectedBookIds }) - .then((result) => { - var success = result.success || false - var toast = 'Batch quick match complete!\n' + result.updates + ' Updated' - if (result.unmatched && (result.unmatched > 0)) { - toast += '\n' + result.unmatched + ' with no matches' - } - if (success) { - this.$toast.success(toast) - } else { - this.$toast.info(toast) - } + .then(() => { + this.$toast.info('Batch quick match of ' + this.selectedBookIds.length + ' books started!') this.processing = false this.$store.commit('setProcessingBatch', false) this.show = false diff --git a/client/layouts/default.vue b/client/layouts/default.vue index 8998a92c..1a23cde7 100644 --- a/client/layouts/default.vue +++ b/client/layouts/default.vue @@ -359,6 +359,18 @@ export default { // Force refresh location.reload() }, + batchQuickMatchComplete(result) { + var success = result.success || false + var toast = 'Batch quick match complete!\n' + result.updates + ' Updated' + if (result.unmatched && (result.unmatched > 0)) { + toast += '\n' + result.unmatched + ' with no matches' + } + if (success) { + this.$toast.success(toast) + } else { + this.$toast.info(toast) + } + }, initializeSocket() { this.socket = this.$nuxtSocket({ name: process.env.NODE_ENV === 'development' ? 'dev' : 'prod', @@ -430,6 +442,8 @@ export default { this.socket.on('rss_feed_closed', this.rssFeedClosed) this.socket.on('backup_applied', this.backupApplied) + + this.socket.on('batch_quickmatch_complete', this.batchQuickMatchComplete) }, showUpdateToast(versionData) { var ignoreVersion = localStorage.getItem('ignoreVersion') diff --git a/server/controllers/LibraryItemController.js b/server/controllers/LibraryItemController.js index 79e9c673..32c297ec 100644 --- a/server/controllers/LibraryItemController.js +++ b/server/controllers/LibraryItemController.js @@ -307,6 +307,11 @@ class LibraryItemController { // POST: api/items/batch/quickmatch async batchQuickMatch(req, res) { + if (!req.user.isAdminOrUp) { + Logger.warn('User other than admin attempted to batch quick match library items', req.user) + return res.sendStatus(403) + } + var itemsUpdated = 0 var itemsUnmatched = 0 @@ -316,6 +321,7 @@ class LibraryItemController { if (!items || !items.length) { return res.sendStatus(500) } + res.sendStatus(200); for (let i = 0; i < items.length; i++) { var libraryItem = this.db.libraryItems.find(_li => _li.id === items[i]) @@ -327,11 +333,12 @@ class LibraryItemController { } } - res.json({ + var result = { success: itemsUpdated > 0, updates: itemsUpdated, - unmatched: itemsUnmatched - }) + unmatched: itemsUnmatched + }; + this.clientEmitter(req.user.id, 'batch_quickmatch_complete', result) } // DELETE: api/items/all