mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-20 19:06:06 +01:00
Switch to using the websocket for confirmation of batch updates, allowing the main request to be done asynchronously
This commit is contained in:
parent
2d6f9bab8b
commit
3e7a76574b
@ -124,17 +124,8 @@ export default {
|
|||||||
options: this.options,
|
options: this.options,
|
||||||
libraryItemIds: this.selectedBookIds
|
libraryItemIds: this.selectedBookIds
|
||||||
})
|
})
|
||||||
.then((result) => {
|
.then(() => {
|
||||||
var success = result.success || false
|
this.$toast.info('Batch quick match of ' + this.selectedBookIds.length + ' books started!')
|
||||||
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)
|
|
||||||
}
|
|
||||||
this.processing = false
|
this.processing = false
|
||||||
this.$store.commit('setProcessingBatch', false)
|
this.$store.commit('setProcessingBatch', false)
|
||||||
this.show = false
|
this.show = false
|
||||||
|
@ -359,6 +359,18 @@ export default {
|
|||||||
// Force refresh
|
// Force refresh
|
||||||
location.reload()
|
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() {
|
initializeSocket() {
|
||||||
this.socket = this.$nuxtSocket({
|
this.socket = this.$nuxtSocket({
|
||||||
name: process.env.NODE_ENV === 'development' ? 'dev' : 'prod',
|
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('rss_feed_closed', this.rssFeedClosed)
|
||||||
|
|
||||||
this.socket.on('backup_applied', this.backupApplied)
|
this.socket.on('backup_applied', this.backupApplied)
|
||||||
|
|
||||||
|
this.socket.on('batch_quickmatch_complete', this.batchQuickMatchComplete)
|
||||||
},
|
},
|
||||||
showUpdateToast(versionData) {
|
showUpdateToast(versionData) {
|
||||||
var ignoreVersion = localStorage.getItem('ignoreVersion')
|
var ignoreVersion = localStorage.getItem('ignoreVersion')
|
||||||
|
@ -307,6 +307,11 @@ class LibraryItemController {
|
|||||||
|
|
||||||
// POST: api/items/batch/quickmatch
|
// POST: api/items/batch/quickmatch
|
||||||
async batchQuickMatch(req, res) {
|
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 itemsUpdated = 0
|
||||||
var itemsUnmatched = 0
|
var itemsUnmatched = 0
|
||||||
|
|
||||||
@ -316,6 +321,7 @@ class LibraryItemController {
|
|||||||
if (!items || !items.length) {
|
if (!items || !items.length) {
|
||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
|
res.sendStatus(200);
|
||||||
|
|
||||||
for (let i = 0; i < items.length; i++) {
|
for (let i = 0; i < items.length; i++) {
|
||||||
var libraryItem = this.db.libraryItems.find(_li => _li.id === items[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,
|
success: itemsUpdated > 0,
|
||||||
updates: itemsUpdated,
|
updates: itemsUpdated,
|
||||||
unmatched: itemsUnmatched
|
unmatched: itemsUnmatched
|
||||||
})
|
};
|
||||||
|
this.clientEmitter(req.user.id, 'batch_quickmatch_complete', result)
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE: api/items/all
|
// DELETE: api/items/all
|
||||||
|
Loading…
Reference in New Issue
Block a user