Update user progress reset and delete logic

This commit is contained in:
Mark Cooper 2021-09-12 18:22:52 -05:00
parent 11f4caffa8
commit 6cb253598b
6 changed files with 28 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "audiobookshelf-client",
"version": "1.1.5",
"version": "1.1.6",
"description": "Audiobook manager and player",
"main": "index.js",
"scripts": {

View File

@ -1,6 +1,6 @@
{
"name": "audiobookshelf",
"version": "1.1.5",
"version": "1.1.6",
"description": "Self-hosted audiobook server for managing and playing audiobooks.",
"main": "index.js",
"scripts": {

View File

@ -109,7 +109,7 @@ class ApiController {
// Remove audiobook from users
for (let i = 0; i < this.db.users.length; i++) {
var user = this.db.users[i]
var madeUpdates = user.resetAudiobookProgress(audiobook.id)
var madeUpdates = user.deleteAudiobookProgress(audiobook.id)
if (madeUpdates) {
await this.db.updateEntity('user', user)
}

View File

@ -245,7 +245,7 @@ class Server {
Logger.error('[Server] audiobookProgressUpdate invalid socket client')
return
}
client.user.updateAudiobookProgressFromStream(progressPayload)
client.user.updateAudiobookProgress(progressPayload.audiobookId, progressPayload)
}
async authenticateSocket(socket, token) {

View File

@ -205,16 +205,20 @@ class Stream extends EventEmitter {
}
startLoop() {
// Logger.info(`[Stream] ${this.audiobookTitle} (${this.id}) Start Loop`)
this.socket.emit('stream_progress', { stream: this.id, chunks: [], numSegments: 0, percent: '0%' })
this.loop = setInterval(() => {
clearInterval(this.loop)
var intervalId = setInterval(() => {
if (!this.isTranscodeComplete) {
this.checkFiles()
} else {
Logger.info(`[Stream] ${this.audiobookTitle} sending stream_ready`)
this.socket.emit('stream_ready')
clearInterval(this.loop)
clearInterval(intervalId)
}
}, 2000)
this.loop = intervalId
}
async start() {
@ -260,13 +264,16 @@ class Stream extends EventEmitter {
this.ffmpeg.on('start', (command) => {
Logger.info('[INFO] FFMPEG transcoding started with command: ' + command)
Logger.info('')
if (this.isResetting) {
setTimeout(() => {
Logger.info('[STREAM] Clearing isResetting')
this.isResetting = false
this.startLoop()
}, 500)
} else {
this.startLoop()
}
this.startLoop()
})
this.ffmpeg.on('stderr', (stdErrline) => {

View File

@ -184,6 +184,20 @@ class User {
}
resetAudiobookProgress(audiobookId) {
if (!this.audiobooks || !this.audiobooks[audiobookId]) {
return false
}
return this.updateAudiobookProgress(audiobookId, {
progress: 0,
currentTime: 0,
isRead: false,
lastUpdate: Date.now(),
startedAt: null,
finishedAt: null
})
}
deleteAudiobookProgress(audiobookId) {
if (!this.audiobooks || !this.audiobooks[audiobookId]) {
return false
}