Clean up ApiRouter adding MiscController, move upload and scan to api endpoints

This commit is contained in:
advplyr 2022-03-18 11:51:55 -05:00
parent 69fcb103e4
commit 57399bb79e
14 changed files with 299 additions and 270 deletions

View file

@ -155,7 +155,7 @@ export default {
},
settingsUpdated(settings) {},
scan() {
this.$root.socket.emit('scan', this.$store.state.libraries.currentLibraryId)
this.$store.dispatch('libraries/requestLibraryScan', { libraryId: this.$store.state.libraries.currentLibraryId })
},
libraryItemAdded(libraryItem) {
console.log('libraryItem added', libraryItem)

View file

@ -563,7 +563,7 @@ export default {
}
},
scan() {
this.$root.socket.emit('scan', this.currentLibraryId)
this.$store.dispatch('libraries/requestLibraryScan', { libraryId: this.currentLibraryId })
}
},
mounted() {

View file

@ -419,23 +419,28 @@ export default {
toast.error(`Failed to mark as ${updatePayload.isFinished ? 'Finished' : 'Not Finished'}`)
})
},
itemScanComplete(result) {
this.rescanning = false
var toast = this.$toast || this.$nuxt.$toast
if (!result) {
toast.error(`Re-Scan Failed for "${this.title}"`)
} else if (result === 'UPDATED') {
toast.success(`Re-Scan complete audiobook was updated`)
} else if (result === 'UPTODATE') {
toast.success(`Re-Scan complete audiobook was up to date`)
} else if (result === 'REMOVED') {
toast.error(`Re-Scan complete audiobook was removed`)
}
},
rescan() {
this.rescanning = true
this._socket.once('item_scan_complete', this.itemScanComplete)
this._socket.emit('scan_item', this.libraryItemId)
this.$axios
.$get(`/api/items/${this.libraryItemId}/scan`)
.then((data) => {
this.rescanning = false
var result = data.result
if (!result) {
this.$toast.error(`Re-Scan Failed for "${this.title}"`)
} else if (result === 'UPDATED') {
this.$toast.success(`Re-Scan complete item was updated`)
} else if (result === 'UPTODATE') {
this.$toast.success(`Re-Scan complete item was up to date`)
} else if (result === 'REMOVED') {
this.$toast.error(`Re-Scan complete item was removed`)
}
})
.catch((error) => {
console.error('Failed to scan library item', error)
this.$toast.error('Failed to scan library item')
this.rescanning = false
})
},
showEditModalTracks() {
// More menu func

View file

@ -117,22 +117,28 @@ export default {
this.quickMatching = false
})
},
libraryScanComplete(result) {
this.rescanning = false
if (!result) {
this.$toast.error(`Re-Scan Failed for "${this.title}"`)
} else if (result === 'UPDATED') {
this.$toast.success(`Re-Scan complete item was updated`)
} else if (result === 'UPTODATE') {
this.$toast.success(`Re-Scan complete item was up to date`)
} else if (result === 'REMOVED') {
this.$toast.error(`Re-Scan complete item was removed`)
}
},
rescan() {
this.rescanning = true
this.$root.socket.once('item_scan_complete', this.libraryScanComplete)
this.$root.socket.emit('scan_item', this.libraryItemId)
this.$axios
.$get(`/api/items/${this.libraryItemId}/scan`)
.then((data) => {
this.rescanning = false
var result = data.result
if (!result) {
this.$toast.error(`Re-Scan Failed for "${this.title}"`)
} else if (result === 'UPDATED') {
this.$toast.success(`Re-Scan complete item was updated`)
} else if (result === 'UPTODATE') {
this.$toast.success(`Re-Scan complete item was up to date`)
} else if (result === 'REMOVED') {
this.$toast.error(`Re-Scan complete item was removed`)
}
})
.catch((error) => {
console.error('Failed to scan library item', error)
this.$toast.error('Failed to scan library item')
this.rescanning = false
})
},
saveMetadataComplete(result) {
this.savingMetadata = false

View file

@ -76,10 +76,10 @@ export default {
this.$emit('edit', this.library)
},
scan() {
this.$root.socket.emit('scan', this.library.id)
this.$store.dispatch('libraries/requestLibraryScan', { libraryId: this.library.id })
},
forceScan() {
this.$root.socket.emit('scan', this.library.id, { forceRescan: true })
this.$store.dispatch('libraries/requestLibraryScan', { libraryId: this.library.id, force: 1 })
},
deleteClick() {
if (this.isMain) return