mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-13 17:07:03 +02:00
New model update details, author and series inputs with create new, compare & copy utils
This commit is contained in:
@ -2,6 +2,7 @@ const Logger = require('../Logger')
|
||||
const LibraryFile = require('./files/LibraryFile')
|
||||
const Book = require('./entities/Book')
|
||||
const Podcast = require('./entities/Podcast')
|
||||
const { areEquivalent, copyValue } = require('../utils/index')
|
||||
|
||||
class LibraryItem {
|
||||
constructor(libraryItem = null) {
|
||||
@ -132,5 +133,23 @@ class LibraryItem {
|
||||
this.libraryFiles.forEach((lf) => total += lf.metadata.size)
|
||||
return total
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
var json = this.toJSON()
|
||||
var hasUpdates = false
|
||||
for (const key in json) {
|
||||
if (payload[key] !== undefined) {
|
||||
if (key === 'media') {
|
||||
if (this.media.update(payload[key])) {
|
||||
hasUpdates = true
|
||||
}
|
||||
} else if (!areEquivalent(payload[key], json[key])) {
|
||||
this[key] = copyValue(payload[key])
|
||||
hasUpdates = true
|
||||
}
|
||||
}
|
||||
}
|
||||
return hasUpdates
|
||||
}
|
||||
}
|
||||
module.exports = LibraryItem
|
Reference in New Issue
Block a user