mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-02 12:09:11 +01:00
New data model update for Match tab
This commit is contained in:
parent
7d66f1eec9
commit
7348432594
@ -169,14 +169,18 @@ export default {
|
|||||||
async updateDetails(updatedDetails) {
|
async updateDetails(updatedDetails) {
|
||||||
this.isProcessing = true
|
this.isProcessing = true
|
||||||
console.log('Sending update', updatedDetails.updatePayload)
|
console.log('Sending update', updatedDetails.updatePayload)
|
||||||
var updatedAudiobook = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatedDetails.updatePayload).catch((error) => {
|
var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatedDetails.updatePayload).catch((error) => {
|
||||||
console.error('Failed to update', error)
|
console.error('Failed to update', error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
this.isProcessing = false
|
this.isProcessing = false
|
||||||
if (updatedAudiobook) {
|
if (updateResult) {
|
||||||
this.$toast.success('Update Successful')
|
if (updateResult.updated) {
|
||||||
this.$emit('close')
|
this.$toast.success('Item details updated')
|
||||||
|
// this.$emit('close')
|
||||||
|
} else {
|
||||||
|
this.$toast.info('No updates were necessary')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeItem() {
|
removeItem() {
|
||||||
|
@ -229,9 +229,28 @@ export default {
|
|||||||
},
|
},
|
||||||
buildMatchUpdatePayload() {
|
buildMatchUpdatePayload() {
|
||||||
var updatePayload = {}
|
var updatePayload = {}
|
||||||
|
|
||||||
|
var volumeNumber = this.selectedMatchUsage.volumeNumber ? this.selectedMatch.volumeNumber || null : null
|
||||||
for (const key in this.selectedMatchUsage) {
|
for (const key in this.selectedMatchUsage) {
|
||||||
if (this.selectedMatchUsage[key] && this.selectedMatch[key]) {
|
if (this.selectedMatchUsage[key] && this.selectedMatch[key]) {
|
||||||
updatePayload[key] = this.selectedMatch[key]
|
if (key === 'series') {
|
||||||
|
var seriesItem = {
|
||||||
|
id: `new-${Math.floor(Math.random() * 10000)}`,
|
||||||
|
name: this.selectedMatch[key],
|
||||||
|
sequence: volumeNumber
|
||||||
|
}
|
||||||
|
updatePayload.series = [seriesItem]
|
||||||
|
} else if (key === 'author') {
|
||||||
|
var authorItem = {
|
||||||
|
id: `new-${Math.floor(Math.random() * 10000)}`,
|
||||||
|
name: this.selectedMatch[key]
|
||||||
|
}
|
||||||
|
updatePayload.authors = [authorItem]
|
||||||
|
} else if (key === 'narrator') {
|
||||||
|
updatePayload.narrators = [this.selectedMatch[key]]
|
||||||
|
} else if (key !== 'volumeNumber') {
|
||||||
|
updatePayload[key] = this.selectedMatch[key]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return updatePayload
|
return updatePayload
|
||||||
@ -252,28 +271,32 @@ export default {
|
|||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if (success) {
|
if (success) {
|
||||||
this.$toast.success('Book Cover Updated')
|
this.$toast.success('Item Cover Updated')
|
||||||
} else {
|
} else {
|
||||||
this.$toast.error('Book Cover Failed to Update')
|
this.$toast.error('Item Cover Failed to Update')
|
||||||
}
|
}
|
||||||
console.log('Updated cover')
|
console.log('Updated cover')
|
||||||
delete updatePayload.cover
|
delete updatePayload.cover
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(updatePayload).length) {
|
if (Object.keys(updatePayload).length) {
|
||||||
var bookUpdatePayload = {
|
var mediaUpdatePayload = {
|
||||||
book: updatePayload
|
metadata: updatePayload
|
||||||
}
|
}
|
||||||
var success = await this.$axios.$patch(`/api/items/${this.libraryItemId}`, bookUpdatePayload).catch((error) => {
|
var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, mediaUpdatePayload).catch((error) => {
|
||||||
console.error('Failed to update', error)
|
console.error('Failed to update', error)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
if (success) {
|
if (updateResult) {
|
||||||
this.$toast.success('Book Details Updated')
|
if (updateResult.updated) {
|
||||||
|
this.$toast.success('Item details updated')
|
||||||
|
} else {
|
||||||
|
this.$toast.info('No detail updates were necessary')
|
||||||
|
}
|
||||||
this.selectedMatch = null
|
this.selectedMatch = null
|
||||||
this.$emit('selectTab', 'details')
|
this.$emit('selectTab', 'details')
|
||||||
} else {
|
} else {
|
||||||
this.$toast.error('Book Details Failed to Update')
|
this.$toast.error('Item Details Failed to Update')
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.selectedMatch = null
|
this.selectedMatch = null
|
||||||
|
@ -49,12 +49,15 @@ class LibraryItemController {
|
|||||||
await this.db.updateLibraryItem(libraryItem)
|
await this.db.updateLibraryItem(libraryItem)
|
||||||
this.emitter('item_updated', libraryItem.toJSONExpanded())
|
this.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||||
}
|
}
|
||||||
res.json(libraryItem)
|
res.json({
|
||||||
|
updated: hasUpdates,
|
||||||
|
libraryItem
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST: api/items/:id/cover
|
// POST: api/items/:id/cover
|
||||||
async uploadCover(req, res) {
|
async uploadCover(req, res) {
|
||||||
if (!req.user.canUpload || !req.user.canUpdate) {
|
if (!req.user.canUpload) {
|
||||||
Logger.warn('User attempted to upload a cover without permission', req.user)
|
Logger.warn('User attempted to upload a cover without permission', req.user)
|
||||||
return res.sendStatus(403)
|
return res.sendStatus(403)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user