mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-12-28 17:49:06 +01:00
Fix:Sync audiobook progress
This commit is contained in:
parent
4778d09501
commit
8ee4751cac
@ -40,7 +40,7 @@ class MeController {
|
||||
if (!audiobook) {
|
||||
return res.status(404).send('Audiobook not found')
|
||||
}
|
||||
var wasUpdated = req.user.updateAudiobookData(audiobook, req.body)
|
||||
var wasUpdated = req.user.updateAudiobookData(audiobook.id, req.body)
|
||||
if (wasUpdated) {
|
||||
await this.db.updateEntity('user', req.user)
|
||||
this.clientEmitter(req.user.id, 'user_updated', req.user.toJSONForBrowser())
|
||||
@ -59,7 +59,7 @@ class MeController {
|
||||
userAbDataPayloads.forEach((userAbData) => {
|
||||
var audiobook = this.db.audiobooks.find(ab => ab.id === userAbData.audiobookId)
|
||||
if (audiobook) {
|
||||
var wasUpdated = req.user.updateAudiobookData(audiobook, userAbData)
|
||||
var wasUpdated = req.user.updateAudiobookData(audiobook.id, userAbData)
|
||||
if (wasUpdated) shouldUpdate = true
|
||||
}
|
||||
})
|
||||
|
@ -140,7 +140,9 @@ class User {
|
||||
if (user.audiobooks) {
|
||||
this.audiobooks = {}
|
||||
for (const key in user.audiobooks) {
|
||||
if (user.audiobooks[key]) {
|
||||
if (key === '[object Object]') { // TEMP: Bug remove bad data
|
||||
Logger.warn('[User] Construct found invalid UAD')
|
||||
} else if (user.audiobooks[key]) {
|
||||
this.audiobooks[key] = new UserAudiobookData(user.audiobooks[key])
|
||||
}
|
||||
}
|
||||
@ -207,16 +209,16 @@ class User {
|
||||
return this.audiobooks[stream.audiobookId]
|
||||
}
|
||||
|
||||
updateAudiobookData(audiobook, updatePayload) {
|
||||
updateAudiobookData(audiobookId, updatePayload) {
|
||||
if (!this.audiobooks) this.audiobooks = {}
|
||||
if (!this.audiobooks[audiobook.id]) {
|
||||
this.audiobooks[audiobook.id] = new UserAudiobookData()
|
||||
this.audiobooks[audiobook.id].audiobookId = audiobook.id
|
||||
if (!this.audiobooks[audiobookId]) {
|
||||
this.audiobooks[audiobookId] = new UserAudiobookData()
|
||||
this.audiobooks[audiobookId].audiobookId = audiobookId
|
||||
}
|
||||
var wasUpdated = this.audiobooks[audiobook.id].update(updatePayload)
|
||||
var wasUpdated = this.audiobooks[audiobookId].update(updatePayload)
|
||||
if (wasUpdated) {
|
||||
// Logger.debug(`[User] UserAudiobookData was updated ${JSON.stringify(this.audiobooks[audiobook.id])}`)
|
||||
return this.audiobooks[audiobook.id]
|
||||
// Logger.debug(`[User] UserAudiobookData was updated ${JSON.stringify(this.audiobooks[audiobookId])}`)
|
||||
return this.audiobooks[audiobookId]
|
||||
}
|
||||
return false
|
||||
}
|
||||
@ -251,7 +253,7 @@ class User {
|
||||
if (!this.audiobooks || !this.audiobooks[audiobook.id]) {
|
||||
return false
|
||||
}
|
||||
return this.updateAudiobookData(audiobook, {
|
||||
return this.updateAudiobookData(audiobook.id, {
|
||||
progress: 0,
|
||||
currentTime: 0,
|
||||
isRead: false,
|
||||
|
@ -86,7 +86,7 @@ class UserAudiobookData {
|
||||
update(payload) {
|
||||
var hasUpdates = false
|
||||
for (const key in payload) {
|
||||
if (payload[key] !== this[key]) {
|
||||
if (this[key] !== undefined && payload[key] !== this[key]) {
|
||||
if (key === 'isRead') {
|
||||
if (!payload[key]) { // Updating to Not Read - Reset progress and current time
|
||||
this.finishedAt = null
|
||||
|
Loading…
Reference in New Issue
Block a user