mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Save Locations locally, add separate progress tracker
This commit is contained in:
		
							parent
							
								
									5078818295
								
							
						
					
					
						commit
						4d29ebd647
					
				| @ -326,7 +326,7 @@ export default { | |||||||
|       return this.store.getters['user/getUserMediaProgress'](this.libraryItemId) |       return this.store.getters['user/getUserMediaProgress'](this.libraryItemId) | ||||||
|     }, |     }, | ||||||
|     userProgressPercent() { |     userProgressPercent() { | ||||||
|       return this.userProgress ? this.userProgress.progress || 0 : 0 |       return this.userProgress ? Math.max(this.userProgress.progress || 0, this.userProgress.ebookProgress || 0) : 0 | ||||||
|     }, |     }, | ||||||
|     itemIsFinished() { |     itemIsFinished() { | ||||||
|       return this.userProgress ? !!this.userProgress.isFinished : false |       return this.userProgress ? !!this.userProgress.isFinished : false | ||||||
|  | |||||||
| @ -53,6 +53,7 @@ export default { | |||||||
|       if (!this.libraryItemId) return |       if (!this.libraryItemId) return | ||||||
|       return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId) |       return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId) | ||||||
|     }, |     }, | ||||||
|  |     localStorageLocationsKey() { return `ebookLocations-${this.libraryItemId}` }, | ||||||
|   }, |   }, | ||||||
|   methods: { |   methods: { | ||||||
|     prev() { return this.rendition?.prev() }, |     prev() { return this.rendition?.prev() }, | ||||||
| @ -69,20 +70,29 @@ export default { | |||||||
|     /** |     /** | ||||||
|      * @param {object} payload |      * @param {object} payload | ||||||
|      * @param {string} payload.ebookLocation - CFI of the current location |      * @param {string} payload.ebookLocation - CFI of the current location | ||||||
|      * @param {string} payload.ebookLocations - list of CFI tags |      * @param {string} payload.ebookProgress - eBook Progress Percentage | ||||||
|      * @param {number} payload.progress - Progress Percentage |  | ||||||
|      */ |      */ | ||||||
|     updateProgress(payload) { |     updateProgress(payload) { | ||||||
|       this.$axios.$patch(`/api/me/progress/${this.libraryItemId}`, payload).catch((error) => { |       this.$axios.$patch(`/api/me/progress/${this.libraryItemId}`, payload).catch((error) => { | ||||||
|         console.error('EpubReader.updateProgress failed:', error) |         console.error('EpubReader.updateProgress failed:', error) | ||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
|  |     /** @param {string} locationString */ | ||||||
|  |     saveLocations(locationString) { | ||||||
|  |       localStorage.setItem(this.localStorageLocationsKey, locationString); | ||||||
|  |     }, | ||||||
|  |     hasSavedLocations() { | ||||||
|  |       return localStorage.getItem(this.localStorageLocationsKey) !== null; | ||||||
|  |     }, | ||||||
|  |     loadLocations() { | ||||||
|  |       return localStorage.getItem(this.localStorageLocationsKey); | ||||||
|  |     }, | ||||||
|     /** @param {string} location - CFI of the new location */ |     /** @param {string} location - CFI of the new location */ | ||||||
|     relocated(location) { |     relocated(location) { | ||||||
|       if (location.end.percentage) { |       if (location.end.percentage) { | ||||||
|         this.updateProgress({ |         this.updateProgress({ | ||||||
|           ebookLocation: location.start.cfi, |           ebookLocation: location.start.cfi, | ||||||
|           progress: location.end.percentage, |           ebookProgress: location.end.percentage, | ||||||
|         }); |         }); | ||||||
|       } else { |       } else { | ||||||
|         this.updateProgress({ |         this.updateProgress({ | ||||||
| @ -119,13 +129,11 @@ export default { | |||||||
|         document.addEventListener('keydown', reader.keyUp, false); |         document.addEventListener('keydown', reader.keyUp, false); | ||||||
| 
 | 
 | ||||||
|         // load ebook cfi locations |         // load ebook cfi locations | ||||||
|         if (this.userMediaProgress?.ebookLocations) { |         if (this.hasSavedLocations()) { | ||||||
|           reader.book.locations.load(this.userMediaProgress?.ebookLocations) |           reader.book.locations.load(this.loadLocations()); | ||||||
|         } else { |         } else { | ||||||
|           reader.book.locations.generate().then(() => { |           reader.book.locations.generate().then(() => { | ||||||
|             this.updateProgress({ |             this.saveLocations(reader.book.locations.save()); | ||||||
|               ebookLocations: reader.book.locations.save(), |  | ||||||
|             }); |  | ||||||
|           }); |           }); | ||||||
|         } |         } | ||||||
|       }); |       }); | ||||||
|  | |||||||
| @ -472,7 +472,7 @@ export default { | |||||||
|       return duration - this.userMediaProgress.currentTime |       return duration - this.userMediaProgress.currentTime | ||||||
|     }, |     }, | ||||||
|     progressPercent() { |     progressPercent() { | ||||||
|       return this.userMediaProgress ? Math.max(Math.min(1, this.userMediaProgress.progress), 0) : 0 |       return this.userMediaProgress ? Math.max(Math.min(1, Math.max(this.userMediaProgress.progress || 0, this.userMediaProgress.ebookProgress || 0)), 0) : 0 | ||||||
|     }, |     }, | ||||||
|     userProgressStartedAt() { |     userProgressStartedAt() { | ||||||
|       return this.userMediaProgress ? this.userMediaProgress.startedAt : 0 |       return this.userMediaProgress ? this.userMediaProgress.startedAt : 0 | ||||||
|  | |||||||
| @ -261,7 +261,7 @@ class MeController { | |||||||
| 
 | 
 | ||||||
|     var itemsInProgress = [] |     var itemsInProgress = [] | ||||||
|     for (const mediaProgress of req.user.mediaProgress) { |     for (const mediaProgress of req.user.mediaProgress) { | ||||||
|       if (!mediaProgress.isFinished && mediaProgress.progress > 0) { |       if (!mediaProgress.isFinished && (mediaProgress.progress > 0 || libraryItem.ebookProgress > 0)) { | ||||||
|         const libraryItem = await this.db.getLibraryItem(mediaProgress.libraryItemId) |         const libraryItem = await this.db.getLibraryItem(mediaProgress.libraryItemId) | ||||||
|         if (libraryItem) { |         if (libraryItem) { | ||||||
|           if (mediaProgress.episodeId && libraryItem.mediaType === 'podcast') { |           if (mediaProgress.episodeId && libraryItem.mediaType === 'podcast') { | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ class MediaProgress { | |||||||
|     this.hideFromContinueListening = false |     this.hideFromContinueListening = false | ||||||
| 
 | 
 | ||||||
|     this.ebookLocation = null // current cfi tag
 |     this.ebookLocation = null // current cfi tag
 | ||||||
|     this.ebookLocations = null // list of cfi tags
 |     this.ebookProgress = null // 0 to 1
 | ||||||
| 
 | 
 | ||||||
|     this.lastUpdate = null |     this.lastUpdate = null | ||||||
|     this.startedAt = null |     this.startedAt = null | ||||||
| @ -33,7 +33,7 @@ class MediaProgress { | |||||||
|       isFinished: this.isFinished, |       isFinished: this.isFinished, | ||||||
|       hideFromContinueListening: this.hideFromContinueListening, |       hideFromContinueListening: this.hideFromContinueListening, | ||||||
|       ebookLocation: this.ebookLocation, |       ebookLocation: this.ebookLocation, | ||||||
|       ebookLocations: this.ebookLocations, |       ebookProgress: this.ebookProgress, | ||||||
|       lastUpdate: this.lastUpdate, |       lastUpdate: this.lastUpdate, | ||||||
|       startedAt: this.startedAt, |       startedAt: this.startedAt, | ||||||
|       finishedAt: this.finishedAt |       finishedAt: this.finishedAt | ||||||
| @ -50,7 +50,7 @@ class MediaProgress { | |||||||
|     this.isFinished = !!progress.isFinished |     this.isFinished = !!progress.isFinished | ||||||
|     this.hideFromContinueListening = !!progress.hideFromContinueListening |     this.hideFromContinueListening = !!progress.hideFromContinueListening | ||||||
|     this.ebookLocation = progress.ebookLocation || null |     this.ebookLocation = progress.ebookLocation || null | ||||||
|     this.ebookLocations = progress.ebookLocations || null |     this.ebookProgress = progress.ebookProgress | ||||||
|     this.lastUpdate = progress.lastUpdate |     this.lastUpdate = progress.lastUpdate | ||||||
|     this.startedAt = progress.startedAt |     this.startedAt = progress.startedAt | ||||||
|     this.finishedAt = progress.finishedAt || null |     this.finishedAt = progress.finishedAt || null | ||||||
| @ -70,7 +70,7 @@ class MediaProgress { | |||||||
|     this.isFinished = !!progress.isFinished || this.progress == 1 |     this.isFinished = !!progress.isFinished || this.progress == 1 | ||||||
|     this.hideFromContinueListening = !!progress.hideFromContinueListening |     this.hideFromContinueListening = !!progress.hideFromContinueListening | ||||||
|     this.ebookLocation = progress.ebookLocation |     this.ebookLocation = progress.ebookLocation | ||||||
|     this.ebookLocations = progress.ebookLocations |     this.ebookProgress = Math.min(1, (progress.ebookProgress || 0)) | ||||||
|     this.lastUpdate = Date.now() |     this.lastUpdate = Date.now() | ||||||
|     this.finishedAt = null |     this.finishedAt = null | ||||||
|     if (this.isFinished) { |     if (this.isFinished) { | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user