mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-13 02:45:02 +02:00
Add:Parse abmetadata metadata.abs file, save metadata.abs on all audiobook insert/update
This commit is contained in:
parent
295c6b0c74
commit
779d22bf55
4 changed files with 131 additions and 18 deletions
31
server/Db.js
31
server/Db.js
|
@ -172,7 +172,15 @@ class Db {
|
|||
}
|
||||
}
|
||||
|
||||
updateAudiobook(audiobook) {
|
||||
async updateAudiobook(audiobook) {
|
||||
if (audiobook && audiobook.saveAbMetadata) {
|
||||
// TODO: Book may have updates where this save is not necessary
|
||||
// add check first if metadata update is needed
|
||||
await audiobook.saveAbMetadata()
|
||||
} else {
|
||||
Logger.error(`[Db] Invalid audiobook object passed to updateAudiobook`, audiobook)
|
||||
}
|
||||
|
||||
return this.audiobooksDb.update((record) => record.id === audiobook.id, () => audiobook).then((results) => {
|
||||
Logger.debug(`[DB] Audiobook updated ${results.updated}`)
|
||||
return true
|
||||
|
@ -182,6 +190,27 @@ class Db {
|
|||
})
|
||||
}
|
||||
|
||||
insertAudiobook(audiobook) {
|
||||
return this.insertAudiobooks([audiobook])
|
||||
}
|
||||
|
||||
async insertAudiobooks(audiobooks) {
|
||||
// TODO: Books may have updates where this save is not necessary
|
||||
// add check first if metadata update is needed
|
||||
await Promise.all(audiobooks.map(async (ab) => {
|
||||
if (ab && ab.saveAbMetadata) return ab.saveAbMetadata()
|
||||
return null
|
||||
}))
|
||||
|
||||
return this.audiobooksDb.insert(audiobooks).then((results) => {
|
||||
Logger.debug(`[DB] Audiobooks inserted ${results.updated}`)
|
||||
return true
|
||||
}).catch((error) => {
|
||||
Logger.error(`[DB] Audiobooks insert failed ${error}`)
|
||||
return false
|
||||
})
|
||||
}
|
||||
|
||||
updateUserStream(userId, streamId) {
|
||||
return this.usersDb.update((record) => record.id === userId, (user) => {
|
||||
user.stream = streamId
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue