2021-09-16 00:59:38 +02:00
|
|
|
import { checkForUpdate } from '@/plugins/version'
|
2021-09-28 13:44:40 +02:00
|
|
|
import Vue from 'vue'
|
2021-08-18 00:01:11 +02:00
|
|
|
|
|
|
|
export const state = () => ({
|
2021-09-16 00:59:38 +02:00
|
|
|
versionData: null,
|
2021-09-05 02:58:39 +02:00
|
|
|
serverSettings: null,
|
2021-08-18 00:01:11 +02:00
|
|
|
streamAudiobook: null,
|
2021-09-06 21:13:01 +02:00
|
|
|
editModalTab: 'details',
|
2021-08-18 00:01:11 +02:00
|
|
|
showEditModal: false,
|
2021-10-10 23:36:21 +02:00
|
|
|
showEReader: false,
|
2021-08-18 00:01:11 +02:00
|
|
|
selectedAudiobook: null,
|
2021-10-16 03:31:00 +02:00
|
|
|
selectedAudiobookFile: null,
|
2021-08-18 00:01:11 +02:00
|
|
|
playOnLoad: false,
|
2021-08-27 01:32:05 +02:00
|
|
|
developerMode: false,
|
|
|
|
selectedAudiobooks: [],
|
2021-09-29 00:36:41 +02:00
|
|
|
processingBatch: false,
|
|
|
|
previousPath: '/',
|
2021-10-02 20:50:39 +02:00
|
|
|
routeHistory: [],
|
2021-10-09 00:30:20 +02:00
|
|
|
showExperimentalFeatures: false,
|
2021-10-16 03:31:00 +02:00
|
|
|
backups: [],
|
2021-10-23 03:08:02 +02:00
|
|
|
bookshelfBookIds: [],
|
|
|
|
openModal: null
|
2021-08-18 00:01:11 +02:00
|
|
|
})
|
|
|
|
|
2021-08-27 01:32:05 +02:00
|
|
|
export const getters = {
|
|
|
|
getIsAudiobookSelected: state => audiobookId => {
|
|
|
|
return !!state.selectedAudiobooks.includes(audiobookId)
|
|
|
|
},
|
2021-10-23 03:08:02 +02:00
|
|
|
getNumAudiobooksSelected: state => state.selectedAudiobooks.length,
|
|
|
|
getAudiobookIdStreaming: state => {
|
|
|
|
return state.streamAudiobook ? state.streamAudiobook.id : null
|
|
|
|
}
|
2021-08-27 01:32:05 +02:00
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
|
2021-09-05 02:58:39 +02:00
|
|
|
export const actions = {
|
|
|
|
updateServerSettings({ commit }, payload) {
|
|
|
|
var updatePayload = {
|
|
|
|
...payload
|
|
|
|
}
|
|
|
|
return this.$axios.$patch('/api/serverSettings', updatePayload).then((result) => {
|
|
|
|
if (result.success) {
|
2021-10-06 04:10:49 +02:00
|
|
|
commit('setServerSettings', result.serverSettings)
|
2021-09-05 02:58:39 +02:00
|
|
|
return true
|
|
|
|
} else {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}).catch((error) => {
|
|
|
|
console.error('Failed to update server settings', error)
|
|
|
|
return false
|
|
|
|
})
|
2021-09-16 00:59:38 +02:00
|
|
|
},
|
|
|
|
checkForUpdate({ commit }) {
|
|
|
|
return checkForUpdate()
|
|
|
|
.then((res) => {
|
|
|
|
commit('setVersionData', res)
|
|
|
|
return res
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Update check failed', error)
|
|
|
|
return false
|
|
|
|
})
|
2021-09-29 00:36:41 +02:00
|
|
|
},
|
|
|
|
popRoute({ commit, state }) {
|
|
|
|
if (!state.routeHistory.length) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
var _history = [...state.routeHistory]
|
|
|
|
var last = _history.pop()
|
|
|
|
commit('setRouteHistory', _history)
|
|
|
|
return last
|
2021-09-05 02:58:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
|
|
|
|
export const mutations = {
|
2021-10-16 03:31:00 +02:00
|
|
|
setBookshelfBookIds(state, val) {
|
|
|
|
state.bookshelfBookIds = val || []
|
|
|
|
},
|
2021-09-29 00:36:41 +02:00
|
|
|
setRouteHistory(state, val) {
|
|
|
|
state.routeHistory = val
|
|
|
|
},
|
|
|
|
setPreviousPath(state, val) {
|
|
|
|
state.previousPath = val
|
|
|
|
},
|
2021-09-16 00:59:38 +02:00
|
|
|
setVersionData(state, versionData) {
|
|
|
|
state.versionData = versionData
|
|
|
|
},
|
2021-09-05 02:58:39 +02:00
|
|
|
setServerSettings(state, settings) {
|
2021-10-06 04:10:49 +02:00
|
|
|
if (!settings) return
|
2021-09-05 02:58:39 +02:00
|
|
|
state.serverSettings = settings
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
setStreamAudiobook(state, audiobook) {
|
|
|
|
state.playOnLoad = true
|
|
|
|
state.streamAudiobook = audiobook
|
|
|
|
},
|
|
|
|
setStream(state, stream) {
|
|
|
|
state.playOnLoad = false
|
|
|
|
state.streamAudiobook = stream ? stream.audiobook : null
|
|
|
|
},
|
|
|
|
clearStreamAudiobook(state, audiobookId) {
|
|
|
|
if (state.streamAudiobook && state.streamAudiobook.id === audiobookId) {
|
|
|
|
state.playOnLoad = false
|
|
|
|
state.streamAudiobook = null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setPlayOnLoad(state, val) {
|
|
|
|
state.playOnLoad = val
|
|
|
|
},
|
|
|
|
showEditModal(state, audiobook) {
|
2021-09-06 21:13:01 +02:00
|
|
|
state.editModalTab = 'details'
|
2021-08-18 00:01:11 +02:00
|
|
|
state.selectedAudiobook = audiobook
|
|
|
|
state.showEditModal = true
|
|
|
|
},
|
2021-09-06 21:13:01 +02:00
|
|
|
showEditModalOnTab(state, { audiobook, tab }) {
|
|
|
|
state.editModalTab = tab
|
|
|
|
state.selectedAudiobook = audiobook
|
|
|
|
state.showEditModal = true
|
|
|
|
},
|
|
|
|
setEditModalTab(state, tab) {
|
|
|
|
state.editModalTab = tab
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
setShowEditModal(state, val) {
|
|
|
|
state.showEditModal = val
|
|
|
|
},
|
2021-10-10 23:36:21 +02:00
|
|
|
showEReader(state, audiobook) {
|
2021-10-16 03:31:00 +02:00
|
|
|
state.selectedAudiobookFile = null
|
|
|
|
state.selectedAudiobook = audiobook
|
|
|
|
|
|
|
|
state.showEReader = true
|
|
|
|
},
|
|
|
|
showEReaderForFile(state, { audiobook, file }) {
|
|
|
|
state.selectedAudiobookFile = file
|
2021-10-10 23:36:21 +02:00
|
|
|
state.selectedAudiobook = audiobook
|
2021-10-16 03:31:00 +02:00
|
|
|
|
2021-10-10 23:36:21 +02:00
|
|
|
state.showEReader = true
|
|
|
|
},
|
|
|
|
setShowEReader(state, val) {
|
|
|
|
state.showEReader = val
|
|
|
|
},
|
2021-08-23 21:08:54 +02:00
|
|
|
setDeveloperMode(state, val) {
|
|
|
|
state.developerMode = val
|
2021-08-27 01:32:05 +02:00
|
|
|
},
|
|
|
|
setSelectedAudiobooks(state, audiobooks) {
|
2021-09-28 13:44:40 +02:00
|
|
|
Vue.set(state, 'selectedAudiobooks', audiobooks)
|
2021-08-27 01:32:05 +02:00
|
|
|
},
|
|
|
|
toggleAudiobookSelected(state, audiobookId) {
|
|
|
|
if (state.selectedAudiobooks.includes(audiobookId)) {
|
|
|
|
state.selectedAudiobooks = state.selectedAudiobooks.filter(a => a !== audiobookId)
|
|
|
|
} else {
|
2021-09-28 13:44:40 +02:00
|
|
|
var newSel = state.selectedAudiobooks.concat([audiobookId])
|
|
|
|
Vue.set(state, 'selectedAudiobooks', newSel)
|
2021-08-27 01:32:05 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setProcessingBatch(state, val) {
|
|
|
|
state.processingBatch = val
|
2021-10-02 20:50:39 +02:00
|
|
|
},
|
|
|
|
setExperimentalFeatures(state, val) {
|
|
|
|
state.showExperimentalFeatures = val
|
2021-10-07 04:08:52 +02:00
|
|
|
localStorage.setItem('experimental', val ? 1 : 0)
|
2021-10-09 00:30:20 +02:00
|
|
|
},
|
|
|
|
setBackups(state, val) {
|
|
|
|
state.backups = val.sort((a, b) => b.createdAt - a.createdAt)
|
2021-10-23 03:08:02 +02:00
|
|
|
},
|
|
|
|
setOpenModal(state, val) {
|
|
|
|
state.openModal = val
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|