mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 15:19:42 +02:00
Add: Experimental bookmarks edit and delete #115
This commit is contained in:
parent
fffa02e7e8
commit
9f66054a72
10 changed files with 234 additions and 39 deletions
|
@ -107,11 +107,26 @@ class AudiobookProgress {
|
|||
return hasUpdates
|
||||
}
|
||||
|
||||
checkBookmarkExists(time) {
|
||||
return this.bookmarks.find(bm => bm.time === time)
|
||||
}
|
||||
|
||||
createBookmark(time, title) {
|
||||
var newBookmark = new AudioBookmark()
|
||||
newBookmark.setData(time, title)
|
||||
this.bookmarks.push(newBookmark)
|
||||
return newBookmark
|
||||
}
|
||||
|
||||
updateBookmark(time, title) {
|
||||
var bookmark = this.bookmarks.find(bm => bm.time === time)
|
||||
if (!bookmark) return false
|
||||
bookmark.title = title
|
||||
return bookmark
|
||||
}
|
||||
|
||||
deleteBookmark(time) {
|
||||
this.bookmarks = this.bookmarks.filter(bm => bm.time !== time)
|
||||
}
|
||||
}
|
||||
module.exports = AudiobookProgress
|
|
@ -281,11 +281,52 @@ class User {
|
|||
|
||||
createBookmark({ audiobookId, time, title }) {
|
||||
if (!this.audiobooks || !this.audiobooks[audiobookId]) {
|
||||
return false
|
||||
return {
|
||||
error: 'Invalid Audiobook'
|
||||
}
|
||||
}
|
||||
if (this.audiobooks[audiobookId].checkBookmarkExists(time)) {
|
||||
return {
|
||||
error: 'Bookmark already exists'
|
||||
}
|
||||
}
|
||||
|
||||
var success = this.audiobooks[audiobookId].createBookmark(time, title)
|
||||
if (success) return this.audiobooks[audiobookId]
|
||||
return null
|
||||
}
|
||||
|
||||
updateBookmark({ audiobookId, time, title }) {
|
||||
if (!this.audiobooks || !this.audiobooks[audiobookId]) {
|
||||
return {
|
||||
error: 'Invalid Audiobook'
|
||||
}
|
||||
}
|
||||
if (!this.audiobooks[audiobookId].checkBookmarkExists(time)) {
|
||||
return {
|
||||
error: 'Bookmark does not exist'
|
||||
}
|
||||
}
|
||||
|
||||
var success = this.audiobooks[audiobookId].updateBookmark(time, title)
|
||||
if (success) return this.audiobooks[audiobookId]
|
||||
return null
|
||||
}
|
||||
|
||||
deleteBookmark({ audiobookId, time }) {
|
||||
if (!this.audiobooks || !this.audiobooks[audiobookId]) {
|
||||
return {
|
||||
error: 'Invalid Audiobook'
|
||||
}
|
||||
}
|
||||
if (!this.audiobooks[audiobookId].checkBookmarkExists(time)) {
|
||||
return {
|
||||
error: 'Bookmark does not exist'
|
||||
}
|
||||
}
|
||||
|
||||
this.audiobooks[audiobookId].deleteBookmark(time)
|
||||
return this.audiobooks[audiobookId]
|
||||
}
|
||||
}
|
||||
module.exports = User
|
Loading…
Add table
Add a link
Reference in a new issue