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 = () => ({
|
2022-05-21 18:21:03 +02:00
|
|
|
Source: null,
|
2021-09-16 00:59:38 +02:00
|
|
|
versionData: null,
|
2021-09-05 02:58:39 +02:00
|
|
|
serverSettings: null,
|
2022-03-13 02:59:35 +01:00
|
|
|
streamLibraryItem: null,
|
2022-03-26 23:41:26 +01:00
|
|
|
streamEpisodeId: null,
|
|
|
|
streamIsPlaying: false,
|
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,
|
2022-03-11 01:45:02 +01:00
|
|
|
selectedLibraryItem: null,
|
2021-08-27 01:32:05 +02:00
|
|
|
developerMode: false,
|
2022-03-13 23:10:48 +01:00
|
|
|
selectedLibraryItems: [],
|
2021-09-29 00:36:41 +02:00
|
|
|
processingBatch: false,
|
|
|
|
previousPath: '/',
|
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: [],
|
2021-11-28 03:11:35 +01:00
|
|
|
openModal: null,
|
2022-05-19 01:37:38 +02:00
|
|
|
selectedBookshelfTexture: '/textures/wood_default.jpg',
|
|
|
|
lastBookshelfScrollData: {}
|
2021-08-18 00:01:11 +02:00
|
|
|
})
|
|
|
|
|
2021-08-27 01:32:05 +02:00
|
|
|
export const getters = {
|
2022-03-13 23:10:48 +01:00
|
|
|
getIsLibraryItemSelected: state => libraryItemId => {
|
|
|
|
return !!state.selectedLibraryItems.includes(libraryItemId)
|
2021-08-27 01:32:05 +02:00
|
|
|
},
|
2021-12-02 22:49:03 +01:00
|
|
|
getServerSetting: state => key => {
|
|
|
|
if (!state.serverSettings) return null
|
|
|
|
return state.serverSettings[key]
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
getBookCoverAspectRatio: state => {
|
2022-05-09 01:40:43 +02:00
|
|
|
if (!state.serverSettings || isNaN(state.serverSettings.coverAspectRatio)) return 1
|
2021-12-03 02:02:38 +01:00
|
|
|
return state.serverSettings.coverAspectRatio === 0 ? 1.6 : 1
|
|
|
|
},
|
2022-03-13 23:10:48 +01:00
|
|
|
getNumLibraryItemsSelected: state => state.selectedLibraryItems.length,
|
2022-03-13 02:59:35 +01:00
|
|
|
getLibraryItemIdStreaming: state => {
|
|
|
|
return state.streamLibraryItem ? state.streamLibraryItem.id : null
|
2022-03-26 23:41:26 +01:00
|
|
|
},
|
|
|
|
getIsEpisodeStreaming: state => (libraryItemId, episodeId) => {
|
|
|
|
if (!state.streamLibraryItem) return null
|
|
|
|
return state.streamLibraryItem.id == libraryItemId && state.streamEpisodeId == episodeId
|
2021-10-23 03:08:02 +02:00
|
|
|
}
|
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
|
|
|
|
}
|
2022-03-18 17:51:55 +01:00
|
|
|
return this.$axios.$patch('/api/settings', updatePayload).then((result) => {
|
2021-09-05 02:58:39 +02:00
|
|
|
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
|
|
|
},
|
2021-11-28 03:11:35 +01:00
|
|
|
setBookshelfTexture({ commit, state }, img) {
|
|
|
|
let root = document.documentElement;
|
|
|
|
commit('setBookshelfTexture', img)
|
|
|
|
root.style.setProperty('--bookshelf-texture-img', `url(${img})`);
|
2021-09-05 02:58:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
|
|
|
|
export const mutations = {
|
2022-05-21 18:21:03 +02:00
|
|
|
setSource(state, source) {
|
|
|
|
state.Source = source
|
|
|
|
},
|
2022-05-19 01:37:38 +02:00
|
|
|
setLastBookshelfScrollData(state, { scrollTop, path, name }) {
|
|
|
|
state.lastBookshelfScrollData[name] = { scrollTop, path }
|
|
|
|
},
|
2021-10-16 03:31:00 +02:00
|
|
|
setBookshelfBookIds(state, val) {
|
|
|
|
state.bookshelfBookIds = val || []
|
|
|
|
},
|
2021-09-29 00:36:41 +02:00
|
|
|
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
|
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
setMediaPlaying(state, payload) {
|
|
|
|
if (!payload) {
|
|
|
|
state.streamLibraryItem = null
|
|
|
|
state.streamEpisodeId = null
|
|
|
|
state.streamIsPlaying = false
|
|
|
|
} else {
|
|
|
|
state.streamLibraryItem = payload.libraryItem
|
|
|
|
state.streamEpisodeId = payload.episodeId || null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setIsPlaying(state, isPlaying) {
|
|
|
|
state.streamIsPlaying = isPlaying
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
showEditModal(state, libraryItem) {
|
2021-09-06 21:13:01 +02:00
|
|
|
state.editModalTab = 'details'
|
2022-03-11 01:45:02 +01:00
|
|
|
state.selectedLibraryItem = libraryItem
|
2021-08-18 00:01:11 +02:00
|
|
|
state.showEditModal = true
|
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
showEditModalOnTab(state, { libraryItem, tab }) {
|
2021-09-06 21:13:01 +02:00
|
|
|
state.editModalTab = tab
|
2022-03-11 01:45:02 +01:00
|
|
|
state.selectedLibraryItem = libraryItem
|
2021-09-06 21:13:01 +02:00
|
|
|
state.showEditModal = true
|
|
|
|
},
|
|
|
|
setEditModalTab(state, tab) {
|
|
|
|
state.editModalTab = tab
|
|
|
|
},
|
2021-08-18 00:01:11 +02:00
|
|
|
setShowEditModal(state, val) {
|
|
|
|
state.showEditModal = val
|
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
showEReader(state, libraryItem) {
|
|
|
|
state.selectedLibraryItem = libraryItem
|
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
|
|
|
},
|
2022-03-11 01:45:02 +01:00
|
|
|
setSelectedLibraryItem(state, val) {
|
|
|
|
Vue.set(state, 'selectedLibraryItem', val)
|
2021-11-06 02:24:02 +01:00
|
|
|
},
|
2022-03-13 23:10:48 +01:00
|
|
|
setSelectedLibraryItems(state, items) {
|
|
|
|
Vue.set(state, 'selectedLibraryItems', items)
|
2021-08-27 01:32:05 +02:00
|
|
|
},
|
2022-03-13 23:10:48 +01:00
|
|
|
toggleLibraryItemSelected(state, itemId) {
|
|
|
|
if (state.selectedLibraryItems.includes(itemId)) {
|
|
|
|
state.selectedLibraryItems = state.selectedLibraryItems.filter(a => a !== itemId)
|
2021-08-27 01:32:05 +02:00
|
|
|
} else {
|
2022-03-13 23:10:48 +01:00
|
|
|
var newSel = state.selectedLibraryItems.concat([itemId])
|
|
|
|
Vue.set(state, 'selectedLibraryItems', newSel)
|
2021-08-27 01:32:05 +02:00
|
|
|
}
|
|
|
|
},
|
2022-03-13 23:10:48 +01:00
|
|
|
setLibraryItemSelected(state, { libraryItemId, selected }) {
|
|
|
|
var isThere = state.selectedLibraryItems.includes(libraryItemId)
|
2021-10-30 03:42:28 +02:00
|
|
|
if (isThere && !selected) {
|
2022-03-13 23:10:48 +01:00
|
|
|
state.selectedLibraryItems = state.selectedLibraryItems.filter(a => a !== libraryItemId)
|
2021-10-30 03:42:28 +02:00
|
|
|
} else if (selected && !isThere) {
|
2022-03-13 23:10:48 +01:00
|
|
|
var newSel = state.selectedLibraryItems.concat([libraryItemId])
|
|
|
|
Vue.set(state, 'selectedLibraryItems', newSel)
|
2021-10-30 03:42:28 +02:00
|
|
|
}
|
|
|
|
},
|
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-11-28 03:11:35 +01:00
|
|
|
},
|
|
|
|
setBookshelfTexture(state, val) {
|
|
|
|
state.selectedBookshelfTexture = val
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|