mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-30 22:59:37 +02:00
This commit is contained in:
parent
f9bf846b30
commit
c5eafdfa8a
9 changed files with 284 additions and 21 deletions
|
@ -1,3 +1,5 @@
|
|||
const AudioBookmark = require('./AudioBookmark')
|
||||
|
||||
class AudiobookProgress {
|
||||
constructor(progress) {
|
||||
this.audiobookId = null
|
||||
|
@ -10,12 +12,18 @@ class AudiobookProgress {
|
|||
this.lastUpdate = null
|
||||
this.startedAt = null
|
||||
this.finishedAt = null
|
||||
this.bookmarks = []
|
||||
|
||||
if (progress) {
|
||||
this.construct(progress)
|
||||
}
|
||||
}
|
||||
|
||||
bookmarksToJSON() {
|
||||
if (!this.bookmarks) return []
|
||||
return this.bookmarks.map(b => b.toJSON())
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
audiobookId: this.audiobookId,
|
||||
|
@ -25,7 +33,8 @@ class AudiobookProgress {
|
|||
isRead: this.isRead,
|
||||
lastUpdate: this.lastUpdate,
|
||||
startedAt: this.startedAt,
|
||||
finishedAt: this.finishedAt
|
||||
finishedAt: this.finishedAt,
|
||||
bookmarks: this.bookmarksToJSON()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,6 +47,11 @@ class AudiobookProgress {
|
|||
this.lastUpdate = progress.lastUpdate
|
||||
this.startedAt = progress.startedAt
|
||||
this.finishedAt = progress.finishedAt || null
|
||||
if (progress.bookmarks) {
|
||||
this.bookmarks = progress.bookmarks.map(b => new AudioBookmark(b))
|
||||
} else {
|
||||
this.bookmarks = []
|
||||
}
|
||||
}
|
||||
|
||||
updateFromStream(stream) {
|
||||
|
@ -90,5 +104,12 @@ class AudiobookProgress {
|
|||
}
|
||||
return hasUpdates
|
||||
}
|
||||
|
||||
createBookmark(time, title) {
|
||||
var newBookmark = new AudioBookmark()
|
||||
newBookmark.setData(time, title)
|
||||
this.bookmarks.push(newBookmark)
|
||||
return newBookmark
|
||||
}
|
||||
}
|
||||
module.exports = AudiobookProgress
|
Loading…
Add table
Add a link
Reference in a new issue