mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Update user progress reset and delete logic
This commit is contained in:
		
							parent
							
								
									9107620b3c
								
							
						
					
					
						commit
						5dd1542af0
					
				| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "audiobookshelf-client", |   "name": "audiobookshelf-client", | ||||||
|   "version": "1.1.5", |   "version": "1.1.6", | ||||||
|   "description": "Audiobook manager and player", |   "description": "Audiobook manager and player", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "audiobookshelf", |   "name": "audiobookshelf", | ||||||
|   "version": "1.1.5", |   "version": "1.1.6", | ||||||
|   "description": "Self-hosted audiobook server for managing and playing audiobooks.", |   "description": "Self-hosted audiobook server for managing and playing audiobooks.", | ||||||
|   "main": "index.js", |   "main": "index.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|  | |||||||
| @ -109,7 +109,7 @@ class ApiController { | |||||||
|     // Remove audiobook from users
 |     // Remove audiobook from users
 | ||||||
|     for (let i = 0; i < this.db.users.length; i++) { |     for (let i = 0; i < this.db.users.length; i++) { | ||||||
|       var user = this.db.users[i] |       var user = this.db.users[i] | ||||||
|       var madeUpdates = user.resetAudiobookProgress(audiobook.id) |       var madeUpdates = user.deleteAudiobookProgress(audiobook.id) | ||||||
|       if (madeUpdates) { |       if (madeUpdates) { | ||||||
|         await this.db.updateEntity('user', user) |         await this.db.updateEntity('user', user) | ||||||
|       } |       } | ||||||
|  | |||||||
| @ -245,7 +245,7 @@ class Server { | |||||||
|       Logger.error('[Server] audiobookProgressUpdate invalid socket client') |       Logger.error('[Server] audiobookProgressUpdate invalid socket client') | ||||||
|       return |       return | ||||||
|     } |     } | ||||||
|     client.user.updateAudiobookProgressFromStream(progressPayload) |     client.user.updateAudiobookProgress(progressPayload.audiobookId, progressPayload) | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async authenticateSocket(socket, token) { |   async authenticateSocket(socket, token) { | ||||||
|  | |||||||
| @ -205,16 +205,20 @@ class Stream extends EventEmitter { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   startLoop() { |   startLoop() { | ||||||
|  |     // Logger.info(`[Stream] ${this.audiobookTitle} (${this.id}) Start Loop`)
 | ||||||
|     this.socket.emit('stream_progress', { stream: this.id, chunks: [], numSegments: 0, percent: '0%' }) |     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) { |       if (!this.isTranscodeComplete) { | ||||||
|         this.checkFiles() |         this.checkFiles() | ||||||
|       } else { |       } else { | ||||||
|         Logger.info(`[Stream] ${this.audiobookTitle} sending stream_ready`) |         Logger.info(`[Stream] ${this.audiobookTitle} sending stream_ready`) | ||||||
|         this.socket.emit('stream_ready') |         this.socket.emit('stream_ready') | ||||||
|         clearInterval(this.loop) |         clearInterval(intervalId) | ||||||
|       } |       } | ||||||
|     }, 2000) |     }, 2000) | ||||||
|  |     this.loop = intervalId | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   async start() { |   async start() { | ||||||
| @ -260,13 +264,16 @@ class Stream extends EventEmitter { | |||||||
| 
 | 
 | ||||||
|     this.ffmpeg.on('start', (command) => { |     this.ffmpeg.on('start', (command) => { | ||||||
|       Logger.info('[INFO] FFMPEG transcoding started with command: ' + command) |       Logger.info('[INFO] FFMPEG transcoding started with command: ' + command) | ||||||
|  |       Logger.info('') | ||||||
|       if (this.isResetting) { |       if (this.isResetting) { | ||||||
|         setTimeout(() => { |         setTimeout(() => { | ||||||
|           Logger.info('[STREAM] Clearing isResetting') |           Logger.info('[STREAM] Clearing isResetting') | ||||||
|           this.isResetting = false |           this.isResetting = false | ||||||
|  |           this.startLoop() | ||||||
|         }, 500) |         }, 500) | ||||||
|  |       } else { | ||||||
|  |         this.startLoop() | ||||||
|       } |       } | ||||||
|       this.startLoop() |  | ||||||
|     }) |     }) | ||||||
| 
 | 
 | ||||||
|     this.ffmpeg.on('stderr', (stdErrline) => { |     this.ffmpeg.on('stderr', (stdErrline) => { | ||||||
|  | |||||||
| @ -184,6 +184,20 @@ class User { | |||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   resetAudiobookProgress(audiobookId) { |   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]) { |     if (!this.audiobooks || !this.audiobooks[audiobookId]) { | ||||||
|       return false |       return false | ||||||
|     } |     } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user