2022-06-02 00:15:13 +02:00
|
|
|
import { checkForUpdate, currentVersion } from '@/plugins/version'
|
2021-09-28 13:44:40 +02:00
|
|
|
import Vue from 'vue'
|
2022-08-14 01:18:42 +02:00
|
|
|
const { Constants } = require('../plugins/constants')
|
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,
|
2022-08-28 20:12:38 +02:00
|
|
|
playerQueueItems: [],
|
2022-08-28 21:21:28 +02:00
|
|
|
playerQueueAutoPlay: true,
|
2022-06-01 03:13:46 +02:00
|
|
|
playerIsFullscreen: 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-28 22:54:04 +02:00
|
|
|
innerModalOpen: false,
|
2022-10-01 23:07:30 +02:00
|
|
|
lastBookshelfScrollData: {},
|
|
|
|
routerBasePath: '/'
|
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]
|
|
|
|
},
|
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
|
|
|
},
|
2022-07-30 19:25:15 +02:00
|
|
|
getIsMediaStreaming: state => (libraryItemId, episodeId) => {
|
2022-03-26 23:41:26 +01:00
|
|
|
if (!state.streamLibraryItem) return null
|
2022-07-30 19:25:15 +02:00
|
|
|
if (!episodeId) return state.streamLibraryItem.id == libraryItemId
|
2022-03-26 23:41:26 +01:00
|
|
|
return state.streamLibraryItem.id == libraryItemId && state.streamEpisodeId == episodeId
|
2022-08-14 01:18:42 +02:00
|
|
|
},
|
|
|
|
getBookshelfView: state => {
|
|
|
|
if (!state.serverSettings || isNaN(state.serverSettings.bookshelfView)) return Constants.BookshelfView.STANDARD
|
|
|
|
return state.serverSettings.bookshelfView
|
|
|
|
},
|
|
|
|
getHomeBookshelfView: state => {
|
|
|
|
if (!state.serverSettings || isNaN(state.serverSettings.homeBookshelfView)) return Constants.BookshelfView.STANDARD
|
|
|
|
return state.serverSettings.homeBookshelfView
|
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 }) {
|
2022-06-02 00:15:13 +02:00
|
|
|
const VERSION_CHECK_BUFF = 1000 * 60 * 5 // 5 minutes
|
|
|
|
var lastVerCheck = localStorage.getItem('lastVerCheck') || 0
|
|
|
|
var savedVersionData = localStorage.getItem('versionData')
|
|
|
|
if (savedVersionData) {
|
|
|
|
try {
|
|
|
|
savedVersionData = JSON.parse(localStorage.getItem('versionData'))
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to parse version data', error)
|
|
|
|
savedVersionData = null
|
|
|
|
localStorage.removeItem('versionData')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var shouldCheckForUpdate = Date.now() - Number(lastVerCheck) > VERSION_CHECK_BUFF
|
|
|
|
if (!shouldCheckForUpdate && savedVersionData && savedVersionData.version !== currentVersion) {
|
|
|
|
// Version mismatch between saved data so check for update anyway
|
|
|
|
shouldCheckForUpdate = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if (shouldCheckForUpdate) {
|
|
|
|
return checkForUpdate()
|
|
|
|
.then((res) => {
|
|
|
|
if (res) {
|
|
|
|
localStorage.setItem('lastVerCheck', Date.now())
|
|
|
|
localStorage.setItem('versionData', JSON.stringify(res))
|
|
|
|
|
|
|
|
commit('setVersionData', res)
|
|
|
|
}
|
|
|
|
return res && res.hasUpdate
|
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
console.error('Update check failed', error)
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
} else if (savedVersionData) {
|
|
|
|
commit('setVersionData', savedVersionData)
|
|
|
|
}
|
|
|
|
return null
|
2021-09-05 02:58:39 +02:00
|
|
|
}
|
|
|
|
}
|
2021-08-18 00:01:11 +02:00
|
|
|
|
|
|
|
export const mutations = {
|
2022-10-01 23:07:30 +02:00
|
|
|
setRouterBasePath(state, rbp) {
|
|
|
|
state.routerBasePath = rbp
|
|
|
|
},
|
2022-05-21 18:21:03 +02:00
|
|
|
setSource(state, source) {
|
|
|
|
state.Source = source
|
|
|
|
},
|
2022-06-01 03:13:46 +02:00
|
|
|
setPlayerIsFullscreen(state, val) {
|
|
|
|
state.playerIsFullscreen = val
|
|
|
|
},
|
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
|
2022-08-28 20:12:38 +02:00
|
|
|
state.playerQueueItems = []
|
2022-03-26 23:41:26 +01:00
|
|
|
} else {
|
|
|
|
state.streamLibraryItem = payload.libraryItem
|
|
|
|
state.streamEpisodeId = payload.episodeId || null
|
2022-08-28 20:12:38 +02:00
|
|
|
state.playerQueueItems = payload.queueItems || []
|
2022-03-26 23:41:26 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
setIsPlaying(state, isPlaying) {
|
|
|
|
state.streamIsPlaying = isPlaying
|
2021-08-18 00:01:11 +02:00
|
|
|
},
|
2022-08-28 20:12:38 +02:00
|
|
|
setPlayerQueueItems(state, items) {
|
|
|
|
state.playerQueueItems = items || []
|
|
|
|
},
|
2022-08-28 21:21:28 +02:00
|
|
|
setPlayerQueueAutoPlay(state, autoPlay) {
|
|
|
|
state.playerQueueAutoPlay = !!autoPlay
|
|
|
|
localStorage.setItem('playerQueueAutoPlay', !!autoPlay ? '1' : '0')
|
|
|
|
},
|
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
|
|
|
},
|
2022-05-28 22:54:04 +02:00
|
|
|
setInnerModalOpen(state, val) {
|
|
|
|
state.innerModalOpen = val
|
2021-08-18 00:01:11 +02:00
|
|
|
}
|
|
|
|
}
|