mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 07:07:22 +02:00
Offline support, downloading, syncing progress
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
export const state = () => ({
|
||||
downloads: [],
|
||||
orphanDownloads: [],
|
||||
showModal: false
|
||||
})
|
||||
|
||||
export const getters = {
|
||||
getDownload: (state) => id => {
|
||||
return state.downloads.find(d => d.id === id)
|
||||
},
|
||||
getDownloadIfReady: (state) => id => {
|
||||
var download = state.downloads.find(d => d.id === id)
|
||||
return !!download && !download.isDownloading && !download.isPreparing ? download : null
|
||||
}
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
async loadFromStorage({ commit }) {
|
||||
var downloads = await this.$sqlStore.getAllDownloads()
|
||||
|
||||
downloads.forEach(ab => {
|
||||
if (ab.isDownloading || ab.isPreparing) {
|
||||
ab.isIncomplete = true
|
||||
}
|
||||
ab.isDownloading = false
|
||||
ab.isPreparing = false
|
||||
commit('setDownload', ab)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const mutations = {
|
||||
setShowModal(state, val) {
|
||||
state.showModal = val
|
||||
},
|
||||
setDownload(state, download) {
|
||||
var index = state.downloads.findIndex(d => d.id === download.id)
|
||||
if (index >= 0) {
|
||||
state.downloads.splice(index, 1, download)
|
||||
} else {
|
||||
state.downloads.push(download)
|
||||
}
|
||||
},
|
||||
addUpdateDownload(state, download) {
|
||||
var key = download.isOrphan ? 'orphanDownloads' : 'downloads'
|
||||
var index = state[key].findIndex(d => d.id === download.id)
|
||||
if (index >= 0) {
|
||||
state[key].splice(index, 1, download)
|
||||
} else {
|
||||
state[key].push(download)
|
||||
}
|
||||
|
||||
if (key === 'downloads') {
|
||||
this.$sqlStore.setDownload(download)
|
||||
}
|
||||
},
|
||||
removeDownload(state, download) {
|
||||
var key = download.isOrphan ? 'orphanDownloads' : 'downloads'
|
||||
state[key] = state[key].filter(d => d.id !== download.id)
|
||||
|
||||
if (key === 'downloads') {
|
||||
this.$sqlStore.removeDownload(download.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user