From 6cb253598bf7cb16c341858f2fff5cd77b47c541 Mon Sep 17 00:00:00 2001 From: Mark Cooper Date: Sun, 12 Sep 2021 18:22:52 -0500 Subject: [PATCH] Update user progress reset and delete logic --- client/package.json | 2 +- package.json | 2 +- server/ApiController.js | 2 +- server/Server.js | 2 +- server/objects/Stream.js | 13 ++++++++++--- server/objects/User.js | 14 ++++++++++++++ 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/client/package.json b/client/package.json index b553d2d4..f344fa22 100644 --- a/client/package.json +++ b/client/package.json @@ -1,6 +1,6 @@ { "name": "audiobookshelf-client", - "version": "1.1.5", + "version": "1.1.6", "description": "Audiobook manager and player", "main": "index.js", "scripts": { diff --git a/package.json b/package.json index 7cfc02bc..8a88e279 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/server/ApiController.js b/server/ApiController.js index 72ed8bb4..e46f2e07 100644 --- a/server/ApiController.js +++ b/server/ApiController.js @@ -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) } diff --git a/server/Server.js b/server/Server.js index 7423db4f..baee4945 100644 --- a/server/Server.js +++ b/server/Server.js @@ -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) { diff --git a/server/objects/Stream.js b/server/objects/Stream.js index 4c76355a..cf4e7f77 100644 --- a/server/objects/Stream.js +++ b/server/objects/Stream.js @@ -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) => { diff --git a/server/objects/User.js b/server/objects/User.js index 0486f5d8..d8badfab 100644 --- a/server/objects/User.js +++ b/server/objects/User.js @@ -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 }