mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-16 04:14:58 +02:00
New data model update MeController user progress routes
This commit is contained in:
parent
c4eeb1cfb7
commit
1cf9e85272
13 changed files with 234 additions and 281 deletions
136
server/Server.js
136
server/Server.js
|
@ -273,7 +273,7 @@ class Server {
|
|||
// socket.on('stream_sync', (syncData) => this.streamManager.streamSync(socket, syncData))
|
||||
|
||||
// Used to sync when playing local book on mobile, will be moved to API route
|
||||
socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket, payload))
|
||||
// socket.on('progress_update', (payload) => this.audiobookProgressUpdate(socket, payload))
|
||||
|
||||
// Downloading
|
||||
socket.on('download', (payload) => this.downloadManager.downloadSocketRequest(socket, payload))
|
||||
|
@ -388,7 +388,7 @@ class Server {
|
|||
if (audiobookIdsToRemove.length) {
|
||||
Logger.debug(`[Server] Found ${audiobookIdsToRemove.length} audiobook data to remove from user ${_user.username}`)
|
||||
for (let y = 0; y < audiobookIdsToRemove.length; y++) {
|
||||
_user.deleteAudiobookData(audiobookIdsToRemove[y])
|
||||
_user.removeLibraryItemProgress(audiobookIdsToRemove[y])
|
||||
}
|
||||
await this.db.updateEntity('user', _user)
|
||||
}
|
||||
|
@ -500,89 +500,89 @@ class Server {
|
|||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
async audiobookProgressUpdate(socket, progressPayload) {
|
||||
var client = socket.sheepClient
|
||||
if (!client || !client.user) {
|
||||
Logger.error('[Server] audiobookProgressUpdate invalid socket client')
|
||||
return
|
||||
}
|
||||
var audiobookProgress = client.user.updateAudiobookData(progressPayload.audiobookId, progressPayload)
|
||||
if (audiobookProgress) {
|
||||
await this.db.updateEntity('user', client.user)
|
||||
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
id: progressPayload.audiobookId,
|
||||
data: audiobookProgress || null
|
||||
})
|
||||
}
|
||||
}
|
||||
// async audiobookProgressUpdate(socket, progressPayload) {
|
||||
// var client = socket.sheepClient
|
||||
// if (!client || !client.user) {
|
||||
// Logger.error('[Server] audiobookProgressUpdate invalid socket client')
|
||||
// return
|
||||
// }
|
||||
// var audiobookProgress = client.user.createUpdateLibraryItemProgress(progressPayload.audiobookId, progressPayload)
|
||||
// if (audiobookProgress) {
|
||||
// await this.db.updateEntity('user', client.user)
|
||||
// this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
// id: progressPayload.audiobookId,
|
||||
// data: audiobookProgress || null
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
async createBookmark(socket, payload) {
|
||||
var client = socket.sheepClient
|
||||
if (!client || !client.user) {
|
||||
Logger.error('[Server] createBookmark invalid socket client')
|
||||
return
|
||||
}
|
||||
var userAudiobook = client.user.createBookmark(payload)
|
||||
if (!userAudiobook || userAudiobook.error) {
|
||||
var failMessage = (userAudiobook ? userAudiobook.error : null) || 'Unknown Error'
|
||||
socket.emit('show_error_toast', `Failed to create Bookmark: ${failMessage}`)
|
||||
return
|
||||
}
|
||||
// var client = socket.sheepClient
|
||||
// if (!client || !client.user) {
|
||||
// Logger.error('[Server] createBookmark invalid socket client')
|
||||
// return
|
||||
// }
|
||||
// var userAudiobook = client.user.createBookmark(payload)
|
||||
// if (!userAudiobook || userAudiobook.error) {
|
||||
// var failMessage = (userAudiobook ? userAudiobook.error : null) || 'Unknown Error'
|
||||
// socket.emit('show_error_toast', `Failed to create Bookmark: ${failMessage}`)
|
||||
// return
|
||||
// }
|
||||
|
||||
await this.db.updateEntity('user', client.user)
|
||||
// await this.db.updateEntity('user', client.user)
|
||||
|
||||
socket.emit('show_success_toast', `${secondsToTimestamp(payload.time)} Bookmarked`)
|
||||
// socket.emit('show_success_toast', `${secondsToTimestamp(payload.time)} Bookmarked`)
|
||||
|
||||
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
id: userAudiobook.audiobookId,
|
||||
data: userAudiobook || null
|
||||
})
|
||||
// this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
// id: userAudiobook.audiobookId,
|
||||
// data: userAudiobook || null
|
||||
// })
|
||||
}
|
||||
|
||||
async updateBookmark(socket, payload) {
|
||||
var client = socket.sheepClient
|
||||
if (!client || !client.user) {
|
||||
Logger.error('[Server] updateBookmark invalid socket client')
|
||||
return
|
||||
}
|
||||
var userAudiobook = client.user.updateBookmark(payload)
|
||||
if (!userAudiobook || userAudiobook.error) {
|
||||
var failMessage = (userAudiobook ? userAudiobook.error : null) || 'Unknown Error'
|
||||
socket.emit('show_error_toast', `Failed to update Bookmark: ${failMessage}`)
|
||||
return
|
||||
}
|
||||
// var client = socket.sheepClient
|
||||
// if (!client || !client.user) {
|
||||
// Logger.error('[Server] updateBookmark invalid socket client')
|
||||
// return
|
||||
// }
|
||||
// var userAudiobook = client.user.updateBookmark(payload)
|
||||
// if (!userAudiobook || userAudiobook.error) {
|
||||
// var failMessage = (userAudiobook ? userAudiobook.error : null) || 'Unknown Error'
|
||||
// socket.emit('show_error_toast', `Failed to update Bookmark: ${failMessage}`)
|
||||
// return
|
||||
// }
|
||||
|
||||
await this.db.updateEntity('user', client.user)
|
||||
// await this.db.updateEntity('user', client.user)
|
||||
|
||||
socket.emit('show_success_toast', `Bookmark ${secondsToTimestamp(payload.time)} Updated`)
|
||||
// socket.emit('show_success_toast', `Bookmark ${secondsToTimestamp(payload.time)} Updated`)
|
||||
|
||||
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
id: userAudiobook.audiobookId,
|
||||
data: userAudiobook || null
|
||||
})
|
||||
// this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
// id: userAudiobook.audiobookId,
|
||||
// data: userAudiobook || null
|
||||
// })
|
||||
}
|
||||
|
||||
async deleteBookmark(socket, payload) {
|
||||
var client = socket.sheepClient
|
||||
if (!client || !client.user) {
|
||||
Logger.error('[Server] deleteBookmark invalid socket client')
|
||||
return
|
||||
}
|
||||
var userAudiobook = client.user.deleteBookmark(payload)
|
||||
if (!userAudiobook || userAudiobook.error) {
|
||||
var failMessage = (userAudiobook ? userAudiobook.error : null) || 'Unknown Error'
|
||||
socket.emit('show_error_toast', `Failed to delete Bookmark: ${failMessage}`)
|
||||
return
|
||||
}
|
||||
// var client = socket.sheepClient
|
||||
// if (!client || !client.user) {
|
||||
// Logger.error('[Server] deleteBookmark invalid socket client')
|
||||
// return
|
||||
// }
|
||||
// var userAudiobook = client.user.deleteBookmark(payload)
|
||||
// if (!userAudiobook || userAudiobook.error) {
|
||||
// var failMessage = (userAudiobook ? userAudiobook.error : null) || 'Unknown Error'
|
||||
// socket.emit('show_error_toast', `Failed to delete Bookmark: ${failMessage}`)
|
||||
// return
|
||||
// }
|
||||
|
||||
await this.db.updateEntity('user', client.user)
|
||||
// await this.db.updateEntity('user', client.user)
|
||||
|
||||
socket.emit('show_success_toast', `Bookmark ${secondsToTimestamp(payload.time)} Removed`)
|
||||
// socket.emit('show_success_toast', `Bookmark ${secondsToTimestamp(payload.time)} Removed`)
|
||||
|
||||
this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
id: userAudiobook.audiobookId,
|
||||
data: userAudiobook || null
|
||||
})
|
||||
// this.clientEmitter(client.user.id, 'current_user_audiobook_update', {
|
||||
// id: userAudiobook.audiobookId,
|
||||
// data: userAudiobook || null
|
||||
// })
|
||||
}
|
||||
|
||||
async authenticateSocket(socket, token) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue