2022-03-23 17:59:14 -05:00
|
|
|
export const state = () => ({
|
2022-04-07 19:59:23 -05:00
|
|
|
itemDownloads: [],
|
2022-04-08 19:05:32 -05:00
|
|
|
bookshelfListView: false,
|
2022-04-09 12:03:37 -05:00
|
|
|
series: null,
|
|
|
|
localMediaProgress: []
|
2022-03-23 17:59:14 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = {
|
2022-04-07 18:46:58 -05:00
|
|
|
getDownloadItem: state => libraryItemId => {
|
|
|
|
return state.itemDownloads.find(i => i.id == libraryItemId)
|
|
|
|
},
|
2022-03-23 17:59:14 -05:00
|
|
|
getLibraryItemCoverSrc: (state, getters, rootState, rootGetters) => (libraryItem, placeholder = '/book_placeholder.jpg') => {
|
|
|
|
if (!libraryItem) return placeholder
|
|
|
|
var media = libraryItem.media
|
|
|
|
if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder
|
|
|
|
|
|
|
|
// Absolute URL covers (should no longer be used)
|
|
|
|
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
|
|
|
|
|
|
|
|
var userToken = rootGetters['user/getToken']
|
|
|
|
var lastUpdate = libraryItem.updatedAt || Date.now()
|
|
|
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') { // Testing
|
|
|
|
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}`
|
|
|
|
}
|
|
|
|
|
2022-04-03 14:24:17 -05:00
|
|
|
var url = new URL(`/api/items/${libraryItem.id}/cover`, rootGetters['user/getServerAddress'])
|
2022-03-23 17:59:14 -05:00
|
|
|
return `${url}?token=${userToken}&ts=${lastUpdate}`
|
2022-04-09 12:03:37 -05:00
|
|
|
},
|
|
|
|
getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => {
|
|
|
|
return state.localMediaProgress.find(lmp => {
|
|
|
|
if (episodeId != null && lmp.episodeId != episodeId) return false
|
|
|
|
return lmp.localLibraryItemId == localLibraryItemId
|
|
|
|
})
|
2022-03-23 17:59:14 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
2022-04-09 12:03:37 -05:00
|
|
|
async loadLocalMediaProgress({ state, commit }) {
|
|
|
|
var mediaProgress = await this.$db.getAllLocalMediaProgress()
|
|
|
|
console.log('Got all local media progress', JSON.stringify(mediaProgress))
|
|
|
|
commit('setLocalMediaProgress', mediaProgress)
|
|
|
|
}
|
2022-03-23 17:59:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
2022-04-07 18:46:58 -05:00
|
|
|
addUpdateItemDownload(state, downloadItem) {
|
|
|
|
var index = state.itemDownloads.findIndex(i => i.id == downloadItem.id)
|
|
|
|
if (index >= 0) {
|
|
|
|
state.itemDownloads.splice(index, 1, downloadItem)
|
|
|
|
} else {
|
|
|
|
state.itemDownloads.push(downloadItem)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeItemDownload(state, id) {
|
|
|
|
state.itemDownloads = state.itemDownloads.filter(i => i.id != id)
|
2022-04-07 19:59:23 -05:00
|
|
|
},
|
|
|
|
setBookshelfListView(state, val) {
|
|
|
|
state.bookshelfListView = val
|
2022-04-08 19:05:32 -05:00
|
|
|
},
|
|
|
|
setSeries(state, val) {
|
|
|
|
state.series = val
|
2022-04-09 12:03:37 -05:00
|
|
|
},
|
|
|
|
setLocalMediaProgress(state, val) {
|
|
|
|
state.localMediaProgress = val
|
|
|
|
},
|
|
|
|
updateLocalMediaProgress(state, prog) {
|
|
|
|
if (!prog || !prog.id) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
var index = state.localMediaProgress.findIndex(lmp => lmp.id == prog.id)
|
|
|
|
if (index >= 0) {
|
|
|
|
state.localMediaProgress.splice(index, 1, prog)
|
|
|
|
} else {
|
|
|
|
state.localMediaProgress.push(prog)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
removeLocalMediaProgress(state, id) {
|
|
|
|
state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.id != id)
|
2022-04-07 18:46:58 -05:00
|
|
|
}
|
2022-03-23 17:59:14 -05:00
|
|
|
}
|