mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-14 15:09:00 +02:00
Fix: more sync issues, Add: link audiobooks with folder names in selected download folder
This commit is contained in:
parent
3b6e7e1ce2
commit
f40e971b90
15 changed files with 95 additions and 293 deletions
|
@ -6,80 +6,6 @@ class LocalStorage {
|
|||
|
||||
this.userAudiobooksLoaded = false
|
||||
this.downloadFolder = null
|
||||
this.userAudiobooks = {}
|
||||
}
|
||||
|
||||
async getMostRecentUserAudiobook(audiobookId) {
|
||||
if (!this.userAudiobooksLoaded) {
|
||||
await this.loadUserAudiobooks()
|
||||
}
|
||||
var local = this.getUserAudiobook(audiobookId)
|
||||
var server = this.vuexStore.getters['user/getUserAudiobook'](audiobookId)
|
||||
|
||||
if (local && server) {
|
||||
if (local.lastUpdate > server.lastUpdate) {
|
||||
console.log('[LocalStorage] Most recent user audiobook is from LOCAL')
|
||||
return local
|
||||
}
|
||||
console.log('[LocalStorage] Most recent user audiobook is from SERVER')
|
||||
return server
|
||||
} else if (local) {
|
||||
console.log('[LocalStorage] Most recent user audiobook is from LOCAL')
|
||||
return local
|
||||
} else if (server) {
|
||||
console.log('[LocalStorage] Most recent user audiobook is from SERVER')
|
||||
return server
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async loadUserAudiobooks() {
|
||||
try {
|
||||
var val = (await Storage.get({ key: 'userAudiobooks' }) || {}).value || null
|
||||
this.userAudiobooks = val ? JSON.parse(val) : {}
|
||||
this.userAudiobooksLoaded = true
|
||||
this.vuexStore.commit('user/setLocalUserAudiobooks', { ...this.userAudiobooks })
|
||||
} catch (error) {
|
||||
console.error('[LocalStorage] Failed to load user audiobooks', error)
|
||||
}
|
||||
}
|
||||
|
||||
async saveUserAudiobooks() {
|
||||
try {
|
||||
await Storage.set({ key: 'userAudiobooks', value: JSON.stringify(this.userAudiobooks) })
|
||||
} catch (error) {
|
||||
console.error('[LocalStorage] Failed to set user audiobooks', error)
|
||||
}
|
||||
}
|
||||
|
||||
async setAllAudiobookProgress(progresses) {
|
||||
this.userAudiobooks = progresses
|
||||
await this.saveUserAudiobooks()
|
||||
|
||||
this.vuexStore.commit('user/setLocalUserAudiobooks', { ...this.userAudiobooks })
|
||||
}
|
||||
|
||||
async updateUserAudiobookData(progressPayload) {
|
||||
this.userAudiobooks[progressPayload.audiobookId] = {
|
||||
...progressPayload
|
||||
}
|
||||
await this.saveUserAudiobooks()
|
||||
|
||||
this.vuexStore.commit('user/setUserAudiobooks', { ...this.userAudiobooks })
|
||||
this.vuexStore.commit('user/setLocalUserAudiobooks', { ...this.userAudiobooks })
|
||||
}
|
||||
|
||||
async removeAudiobookProgress(audiobookId) {
|
||||
if (!this.userAudiobooks[audiobookId]) return
|
||||
delete this.userAudiobooks[audiobookId]
|
||||
await this.saveUserAudiobooks()
|
||||
|
||||
this.vuexStore.commit('user/setUserAudiobooks', { ...this.userAudiobooks })
|
||||
this.vuexStore.commit('user/setLocalUserAudiobooks', { ...this.userAudiobooks })
|
||||
}
|
||||
|
||||
getUserAudiobook(audiobookId) {
|
||||
return this.userAudiobooks[audiobookId] || null
|
||||
}
|
||||
|
||||
async setToken(token) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue