mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-09-01 08:07:20 +02:00
Fix: more sync issues, Add: link audiobooks with folder names in selected download folder
This commit is contained in:
+49
-1
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user