Add: Experimental bookmarks edit and delete #115

This commit is contained in:
advplyr 2021-10-26 20:09:04 -05:00
parent fffa02e7e8
commit 9f66054a72
10 changed files with 234 additions and 39 deletions

View file

@ -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

View file

@ -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