mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-17 00:08:55 +01:00
Merge pull request #2573 from mikiher/fix-match-update
Merge cover and media update in Match.vue into a single /media API call
This commit is contained in:
commit
af8dffaa33
@ -546,24 +546,11 @@ export default {
|
|||||||
// Persist in local storage
|
// Persist in local storage
|
||||||
localStorage.setItem('selectedMatchUsage', JSON.stringify(this.selectedMatchUsage))
|
localStorage.setItem('selectedMatchUsage', JSON.stringify(this.selectedMatchUsage))
|
||||||
|
|
||||||
if (updatePayload.metadata.cover) {
|
|
||||||
const coverPayload = {
|
|
||||||
url: updatePayload.metadata.cover
|
|
||||||
}
|
|
||||||
const success = await this.$axios.$post(`/api/items/${this.libraryItemId}/cover`, coverPayload).catch((error) => {
|
|
||||||
console.error('Failed to update', error)
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
if (success) {
|
|
||||||
this.$toast.success(this.$strings.ToastItemCoverUpdateSuccess)
|
|
||||||
} else {
|
|
||||||
this.$toast.error(this.$strings.ToastItemCoverUpdateFailed)
|
|
||||||
}
|
|
||||||
console.log('Updated cover')
|
|
||||||
delete updatePayload.metadata.cover
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Object.keys(updatePayload).length) {
|
if (Object.keys(updatePayload).length) {
|
||||||
|
if (updatePayload.metadata.cover) {
|
||||||
|
updatePayload.url = updatePayload.metadata.cover
|
||||||
|
delete updatePayload.metadata.cover
|
||||||
|
}
|
||||||
const mediaUpdatePayload = updatePayload
|
const mediaUpdatePayload = updatePayload
|
||||||
const updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, mediaUpdatePayload).catch((error) => {
|
const 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)
|
||||||
|
@ -124,6 +124,11 @@ class LibraryItemController {
|
|||||||
const libraryItem = req.libraryItem
|
const libraryItem = req.libraryItem
|
||||||
const mediaPayload = req.body
|
const mediaPayload = req.body
|
||||||
|
|
||||||
|
if (mediaPayload.url) {
|
||||||
|
await LibraryItemController.prototype.uploadCover.bind(this)(req, res, false)
|
||||||
|
if (res.writableEnded) return
|
||||||
|
}
|
||||||
|
|
||||||
// Book specific
|
// Book specific
|
||||||
if (libraryItem.isBook) {
|
if (libraryItem.isBook) {
|
||||||
await this.createAuthorsAndSeriesForItemUpdate(mediaPayload, libraryItem.libraryId)
|
await this.createAuthorsAndSeriesForItemUpdate(mediaPayload, libraryItem.libraryId)
|
||||||
@ -146,7 +151,7 @@ class LibraryItemController {
|
|||||||
seriesRemoved = libraryItem.media.metadata.series.filter(se => !seriesIdsInUpdate.includes(se.id))
|
seriesRemoved = libraryItem.media.metadata.series.filter(se => !seriesIdsInUpdate.includes(se.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasUpdates = libraryItem.media.update(mediaPayload)
|
const hasUpdates = libraryItem.media.update(mediaPayload) || mediaPayload.url
|
||||||
if (hasUpdates) {
|
if (hasUpdates) {
|
||||||
libraryItem.updatedAt = Date.now()
|
libraryItem.updatedAt = Date.now()
|
||||||
|
|
||||||
@ -171,7 +176,7 @@ class LibraryItemController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// POST: api/items/:id/cover
|
// POST: api/items/:id/cover
|
||||||
async uploadCover(req, res) {
|
async uploadCover(req, res, updateAndReturnJson = true) {
|
||||||
if (!req.user.canUpload) {
|
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)
|
||||||
@ -196,12 +201,14 @@ class LibraryItemController {
|
|||||||
return res.status(500).send('Unknown error occurred')
|
return res.status(500).send('Unknown error occurred')
|
||||||
}
|
}
|
||||||
|
|
||||||
await Database.updateLibraryItem(libraryItem)
|
if (updateAndReturnJson) {
|
||||||
SocketAuthority.emitter('item_updated', libraryItem.toJSONExpanded())
|
await Database.updateLibraryItem(libraryItem)
|
||||||
res.json({
|
SocketAuthority.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||||
success: true,
|
res.json({
|
||||||
cover: result.cover
|
success: true,
|
||||||
})
|
cover: result.cover
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PATCH: api/items/:id/cover
|
// PATCH: api/items/:id/cover
|
||||||
|
@ -378,6 +378,9 @@ class LibraryItem extends Model {
|
|||||||
if (!areEquivalent(updatedLibraryItem[key], existingValue, true)) {
|
if (!areEquivalent(updatedLibraryItem[key], existingValue, true)) {
|
||||||
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" ${key} updated from ${existingValue} to ${updatedLibraryItem[key]}`)
|
Logger.debug(`[LibraryItem] "${libraryItemExpanded.media.title}" ${key} updated from ${existingValue} to ${updatedLibraryItem[key]}`)
|
||||||
hasLibraryItemUpdates = true
|
hasLibraryItemUpdates = true
|
||||||
|
if (key === 'updatedAt') {
|
||||||
|
libraryItemExpanded.changed('updatedAt', true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hasLibraryItemUpdates) {
|
if (hasLibraryItemUpdates) {
|
||||||
@ -405,6 +408,7 @@ class LibraryItem extends Model {
|
|||||||
isInvalid: !!oldLibraryItem.isInvalid,
|
isInvalid: !!oldLibraryItem.isInvalid,
|
||||||
mtime: oldLibraryItem.mtimeMs,
|
mtime: oldLibraryItem.mtimeMs,
|
||||||
ctime: oldLibraryItem.ctimeMs,
|
ctime: oldLibraryItem.ctimeMs,
|
||||||
|
updatedAt: oldLibraryItem.updatedAt,
|
||||||
birthtime: oldLibraryItem.birthtimeMs,
|
birthtime: oldLibraryItem.birthtimeMs,
|
||||||
size: oldLibraryItem.size,
|
size: oldLibraryItem.size,
|
||||||
lastScan: oldLibraryItem.lastScan,
|
lastScan: oldLibraryItem.lastScan,
|
||||||
|
Loading…
Reference in New Issue
Block a user