Fix: more sync issues, Add: link audiobooks with folder names in selected download folder

This commit is contained in:
advplyr
2021-11-20 10:59:34 -06:00
parent 3b6e7e1ce2
commit f40e971b90
15 changed files with 95 additions and 293 deletions
+49 -1
View File
@@ -1,6 +1,9 @@
import { Capacitor } from '@capacitor/core'
export const state = () => ({
downloads: [],
showModal: false
showModal: false,
mediaScanResults: {},
})
export const getters = {
@@ -28,6 +31,48 @@ export const actions = {
ab.isPreparing = false
commit('setDownload', ab)
})
},
linkOrphanDownloads({ state, commit }, audiobooks) {
if (!state.mediaScanResults || !state.mediaScanResults.folders) {
return
}
console.log('Link orphan downloads', JSON.stringify(state.mediaScanResults.folders))
state.mediaScanResults.folders.forEach((folder) => {
if (!folder.files || !folder.files.length) return
console.log('Link orphan downloads check folder', folder.name)
var download = state.downloads.find(dl => dl.folderName === folder.name)
if (!download) {
var matchingAb = audiobooks.find(ab => ab.book.title === folder.name)
if (matchingAb) {
// Found matching download for ab
var audioFile = folder.files.find(f => f.isAudio)
if (!audioFile) {
return
}
var coverImg = folder.files.find(f => !f.isAudio)
const downloadObj = {
id: matchingAb.id,
audiobook: { ...matchingAb },
contentUrl: audioFile.uri,
simplePath: audioFile.simplePath,
folderUrl: folder.uri,
folderName: folder.name,
storageType: '',
storageId: '',
basePath: '',
size: audioFile.size,
coverUrl: coverImg ? coverImg.uri : null,
cover: coverImg ? Capacitor.convertFileSrc(coverImg.uri) : null,
coverSize: coverImg ? coverImg.size : 0,
coverBasePath: ''
}
console.log('Linking orphan download: ' + JSON.stringify(downloadObj))
commit('addUpdateDownload', downloadObj)
}
}
})
}
}
@@ -61,5 +106,8 @@ export const mutations = {
removeDownload(state, download) {
state.downloads = state.downloads.filter(d => d.id !== download.id)
this.$sqlStore.removeDownload(download.id)
},
setMediaScanResults(state, val) {
state.mediaScanResults = val
}
}