mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-05 02:25:45 +02:00
Fix:Discard progress for local and server media progress #646
This commit is contained in:
parent
fafaad8b5f
commit
d7feb52dd8
2 changed files with 68 additions and 33 deletions
|
@ -144,10 +144,23 @@ export default {
|
|||
libraryItemId() {
|
||||
return this.libraryItem.id
|
||||
},
|
||||
localLibraryItemId() {
|
||||
if (this.localLibraryItem) return this.localLibraryItem.id
|
||||
isConnectedToServer() {
|
||||
if (!this.isLocal) return true
|
||||
if (!this.libraryItem.serverAddress) return false
|
||||
return this.$store.getters['user/getServerAddress'] === this.libraryItem.serverAddress
|
||||
},
|
||||
serverLibraryItemId() {
|
||||
if (!this.isLocal) return this.libraryItemId
|
||||
// Check if local library item is connected to the current server
|
||||
if (!this.libraryItem.libraryItemId) return null
|
||||
if (this.isConnectedToServer) {
|
||||
return this.libraryItem.libraryItemId
|
||||
}
|
||||
return null
|
||||
},
|
||||
localLibraryItemId() {
|
||||
return this.localLibraryItem?.id || null
|
||||
},
|
||||
localEpisode() {
|
||||
if (this.isLocal) return this.episode
|
||||
return this.episode.localEpisode
|
||||
|
@ -156,6 +169,13 @@ export default {
|
|||
if (this.localEpisode) return this.localEpisode.id
|
||||
return null
|
||||
},
|
||||
serverEpisodeId() {
|
||||
if (!this.isLocal) return this.episode.id
|
||||
if (this.isConnectedToServer) {
|
||||
return this.episode.serverEpisodeId
|
||||
}
|
||||
return null
|
||||
},
|
||||
podcast() {
|
||||
return this.libraryItem.media
|
||||
},
|
||||
|
@ -202,16 +222,16 @@ export default {
|
|||
return this.$store.state.playerIsPlaying && this.isPlaying
|
||||
},
|
||||
userItemProgress() {
|
||||
if (this.isLocal) return this.$store.getters['globals/getLocalMediaProgressById'](this.libraryItemId, this.episode.id)
|
||||
return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId, this.episode.id)
|
||||
if (this.isLocal) return this.localItemProgress
|
||||
return this.serverItemProgress
|
||||
},
|
||||
localMediaProgress() {
|
||||
if (this.isLocal) return this.$store.getters['globals/getLocalMediaProgressById'](this.libraryItemId, this.episode.id)
|
||||
else if (this.localLibraryItemId && this.localEpisodeId) {
|
||||
return this.$store.getters['globals/getLocalMediaProgressById'](this.localLibraryItemId, this.localEpisodeId)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
localItemProgress() {
|
||||
if (!this.localLibraryItemId || !this.localEpisodeId) return null
|
||||
return this.$store.getters['globals/getLocalMediaProgressById'](this.localLibraryItemId, this.localEpisodeId)
|
||||
},
|
||||
serverItemProgress() {
|
||||
if (!this.serverLibraryItemId || !this.serverEpisodeId) return null
|
||||
return this.$store.getters['user/getUserMediaProgress'](this.serverLibraryItemId, this.serverEpisodeId)
|
||||
},
|
||||
progressPercent() {
|
||||
return this.userItemProgress ? this.userItemProgress.progress : 0
|
||||
|
@ -293,13 +313,15 @@ export default {
|
|||
this.$eventBus.$emit('play-item', {
|
||||
libraryItemId: this.localLibraryItemId,
|
||||
episodeId: this.localEpisodeId,
|
||||
serverLibraryItemId: this.libraryItemId,
|
||||
serverEpisodeId: this.episode.id
|
||||
serverLibraryItemId: this.serverLibraryItemId,
|
||||
serverEpisodeId: this.serverEpisodeId
|
||||
})
|
||||
} else {
|
||||
this.$eventBus.$emit('play-item', {
|
||||
libraryItemId: this.libraryItemId,
|
||||
episodeId: this.episode.id
|
||||
episodeId: this.episode.id,
|
||||
serverLibraryItemId: this.serverLibraryItemId,
|
||||
serverEpisodeId: this.serverEpisodeId
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -395,22 +417,26 @@ export default {
|
|||
})
|
||||
if (value) {
|
||||
this.resettingProgress = true
|
||||
if (this.isLocal) {
|
||||
// TODO: If connected to server also sync with server
|
||||
await this.$db.removeLocalMediaProgress(this.localMediaProgress.id)
|
||||
this.$store.commit('globals/removeLocalMediaProgressForItem', this.localMediaProgress.id)
|
||||
} else {
|
||||
|
||||
const serverItemProgressId = this.serverItemProgress?.id
|
||||
if (this.localItemProgress) {
|
||||
await this.$db.removeLocalMediaProgress(this.localItemProgress.id)
|
||||
this.$store.commit('globals/removeLocalMediaProgress', this.localItemProgress.id)
|
||||
}
|
||||
|
||||
if (serverItemProgressId) {
|
||||
await this.$axios
|
||||
.$delete(`/api/me/progress/${this.userItemProgress.id}`)
|
||||
.$delete(`/api/me/progress/${serverItemProgressId}`)
|
||||
.then(() => {
|
||||
console.log('Progress reset complete')
|
||||
this.$toast.success(`Your progress was reset`)
|
||||
this.$store.commit('user/removeMediaProgress', this.userItemProgress.id)
|
||||
this.$store.commit('user/removeMediaProgress', serverItemProgressId)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Progress reset failed', error)
|
||||
})
|
||||
}
|
||||
|
||||
this.resettingProgress = false
|
||||
}
|
||||
},
|
||||
|
|
|
@ -204,12 +204,12 @@ export default {
|
|||
return this.libraryItem.localLibraryItem || null
|
||||
},
|
||||
localLibraryItemId() {
|
||||
return this.localLibraryItem ? this.localLibraryItem.id : null
|
||||
return this.localLibraryItem?.id || null
|
||||
},
|
||||
localLibraryItemEpisodes() {
|
||||
if (!this.isPodcast || !this.localLibraryItem) return []
|
||||
var podcastMedia = this.localLibraryItem.media
|
||||
return podcastMedia ? podcastMedia.episodes || [] : []
|
||||
return podcastMedia?.episodes || []
|
||||
},
|
||||
serverLibraryItemId() {
|
||||
if (!this.isLocal) return this.libraryItem.id
|
||||
|
@ -293,8 +293,16 @@ export default {
|
|||
},
|
||||
userItemProgress() {
|
||||
if (this.isPodcast) return null
|
||||
if (this.isLocal) return this.$store.getters['globals/getLocalMediaProgressById'](this.libraryItemId)
|
||||
return this.$store.getters['user/getUserMediaProgress'](this.libraryItemId)
|
||||
if (this.isLocal) return this.localItemProgress
|
||||
return this.serverItemProgress
|
||||
},
|
||||
localItemProgress() {
|
||||
if (this.isPodcast) return null
|
||||
return this.$store.getters['globals/getLocalMediaProgressById'](this.localLibraryItemId)
|
||||
},
|
||||
serverItemProgress() {
|
||||
if (this.isPodcast) return null
|
||||
return this.$store.getters['user/getUserMediaProgress'](this.serverLibraryItemId)
|
||||
},
|
||||
userIsFinished() {
|
||||
return this.userItemProgress ? !!this.userItemProgress.isFinished : false
|
||||
|
@ -554,18 +562,19 @@ export default {
|
|||
})
|
||||
if (value) {
|
||||
this.resettingProgress = true
|
||||
if (this.isLocal) {
|
||||
// TODO: If connected to server also sync with server
|
||||
await this.$db.removeLocalMediaProgress(this.libraryItemId)
|
||||
this.$store.commit('globals/removeLocalMediaProgressForItem', this.libraryItemId)
|
||||
} else {
|
||||
var progressId = this.userItemProgress.id
|
||||
const serverMediaProgressId = this.serverItemProgress?.id
|
||||
if (this.localLibraryItemId) {
|
||||
await this.$db.removeLocalMediaProgress(this.localLibraryItemId)
|
||||
this.$store.commit('globals/removeLocalMediaProgressForItem', this.localLibraryItemId)
|
||||
}
|
||||
|
||||
if (this.serverLibraryItemId && serverMediaProgressId) {
|
||||
await this.$axios
|
||||
.$delete(`/api/me/progress/${this.libraryItemId}`)
|
||||
.$delete(`/api/me/progress/${serverMediaProgressId}`)
|
||||
.then(() => {
|
||||
console.log('Progress reset complete')
|
||||
this.$toast.success(`Your progress was reset`)
|
||||
this.$store.commit('user/removeMediaProgress', progressId)
|
||||
this.$store.commit('user/removeMediaProgress', serverMediaProgressId)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('Progress reset failed', error)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue