2021-08-24 01:31:04 +02:00
|
|
|
export const state = () => ({
|
|
|
|
user: null,
|
|
|
|
settings: {
|
2022-04-12 02:42:09 +02:00
|
|
|
orderBy: 'media.metadata.title',
|
2021-08-24 01:31:04 +02:00
|
|
|
orderDesc: false,
|
|
|
|
filterBy: 'all',
|
2021-08-26 16:47:51 +02:00
|
|
|
playbackRate: 1,
|
2022-01-25 01:03:54 +01:00
|
|
|
bookshelfCoverSize: 120,
|
2022-11-06 17:55:44 +01:00
|
|
|
collapseSeries: false,
|
2022-12-17 21:50:01 +01:00
|
|
|
collapseBookSeries: false,
|
2024-07-04 19:35:58 +02:00
|
|
|
showSubtitles: false,
|
2022-12-17 22:10:25 +01:00
|
|
|
useChapterTrack: false,
|
|
|
|
seriesSortBy: 'name',
|
|
|
|
seriesSortDesc: false,
|
2024-02-04 04:48:35 +01:00
|
|
|
seriesFilterBy: 'all',
|
|
|
|
authorSortBy: 'name',
|
2024-07-13 00:52:48 +02:00
|
|
|
authorSortDesc: false,
|
|
|
|
jumpForwardAmount: 10,
|
|
|
|
jumpBackwardAmount: 10,
|
2022-12-17 21:50:01 +01:00
|
|
|
}
|
2021-08-24 01:31:04 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
export const getters = {
|
2021-08-27 14:01:47 +02:00
|
|
|
getIsRoot: (state) => state.user && state.user.type === 'root',
|
2022-04-29 23:42:40 +02:00
|
|
|
getIsAdminOrUp: (state) => state.user && (state.user.type === 'admin' || state.user.type === 'root'),
|
2021-08-24 01:31:04 +02:00
|
|
|
getToken: (state) => {
|
2023-05-28 17:47:28 +02:00
|
|
|
return state.user?.token || null
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
2022-03-26 23:41:26 +01:00
|
|
|
getUserMediaProgress: (state) => (libraryItemId, episodeId = null) => {
|
2022-03-26 17:59:34 +01:00
|
|
|
if (!state.user.mediaProgress) return null
|
2024-06-03 08:04:03 +02:00
|
|
|
return state.user.mediaProgress.find((li) => {
|
2022-03-26 23:41:26 +01:00
|
|
|
if (episodeId && li.episodeId !== episodeId) return false
|
2022-04-09 02:27:35 +02:00
|
|
|
return li.libraryItemId == libraryItemId
|
2022-03-26 23:41:26 +01:00
|
|
|
})
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
2022-03-18 02:28:04 +01:00
|
|
|
getUserBookmarksForItem: (state) => (libraryItemId) => {
|
|
|
|
if (!state.user.bookmarks) return []
|
2024-06-03 08:04:03 +02:00
|
|
|
return state.user.bookmarks.filter((bm) => bm.libraryItemId === libraryItemId)
|
2022-03-18 02:28:04 +01:00
|
|
|
},
|
2021-08-24 01:31:04 +02:00
|
|
|
getUserSetting: (state) => (key) => {
|
2023-06-11 20:22:58 +02:00
|
|
|
return state.settings?.[key] || null
|
2021-08-24 01:31:04 +02:00
|
|
|
},
|
2021-09-07 00:42:15 +02:00
|
|
|
getUserCanUpdate: (state) => {
|
2023-06-11 20:22:58 +02:00
|
|
|
return !!state.user?.permissions?.update
|
2021-09-07 00:42:15 +02:00
|
|
|
},
|
|
|
|
getUserCanDelete: (state) => {
|
2023-06-11 20:22:58 +02:00
|
|
|
return !!state.user?.permissions?.delete
|
2021-09-07 00:42:15 +02:00
|
|
|
},
|
|
|
|
getUserCanDownload: (state) => {
|
2023-06-11 20:22:58 +02:00
|
|
|
return !!state.user?.permissions?.download
|
2021-09-18 19:45:34 +02:00
|
|
|
},
|
|
|
|
getUserCanUpload: (state) => {
|
2023-06-11 20:22:58 +02:00
|
|
|
return !!state.user?.permissions?.upload
|
2021-10-23 03:08:02 +02:00
|
|
|
},
|
|
|
|
getUserCanAccessAllLibraries: (state) => {
|
2023-06-11 20:22:58 +02:00
|
|
|
return !!state.user?.permissions?.accessAllLibraries
|
2021-10-23 03:08:02 +02:00
|
|
|
},
|
|
|
|
getLibrariesAccessible: (state, getters) => {
|
|
|
|
if (!state.user) return []
|
|
|
|
if (getters.getUserCanAccessAllLibraries) return []
|
|
|
|
return state.user.librariesAccessible || []
|
|
|
|
},
|
|
|
|
getCanAccessLibrary: (state, getters) => (libraryId) => {
|
|
|
|
if (!state.user) return false
|
|
|
|
if (getters.getUserCanAccessAllLibraries) return true
|
|
|
|
return getters.getLibrariesAccessible.includes(libraryId)
|
2022-11-16 00:20:57 +01:00
|
|
|
},
|
|
|
|
getIsSeriesRemovedFromContinueListening: (state) => (seriesId) => {
|
|
|
|
if (!state.user || !state.user.seriesHideFromContinueListening || !state.user.seriesHideFromContinueListening.length) return false
|
|
|
|
return state.user.seriesHideFromContinueListening.includes(seriesId)
|
2024-06-03 08:04:03 +02:00
|
|
|
},
|
|
|
|
getSizeMultiplier: (state) => {
|
|
|
|
return state.settings.bookshelfCoverSize / 120
|
2021-08-24 01:31:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const actions = {
|
2022-04-12 02:42:09 +02:00
|
|
|
// When changing libraries make sure sort and filter is still valid
|
|
|
|
checkUpdateLibrarySortFilter({ state, dispatch, commit }, mediaType) {
|
2022-12-17 21:50:01 +01:00
|
|
|
const settingsUpdate = {}
|
2022-04-12 02:42:09 +02:00
|
|
|
if (mediaType == 'podcast') {
|
|
|
|
if (state.settings.orderBy == 'media.metadata.authorName' || state.settings.orderBy == 'media.metadata.authorNameLF') {
|
|
|
|
settingsUpdate.orderBy = 'media.metadata.author'
|
|
|
|
}
|
2022-05-04 00:50:19 +02:00
|
|
|
if (state.settings.orderBy == 'media.duration') {
|
|
|
|
settingsUpdate.orderBy = 'media.numTracks'
|
|
|
|
}
|
2022-08-19 22:07:47 +02:00
|
|
|
if (state.settings.orderBy == 'media.metadata.publishedYear') {
|
|
|
|
settingsUpdate.orderBy = 'media.metadata.title'
|
|
|
|
}
|
2023-07-15 19:22:13 +02:00
|
|
|
const invalidFilters = ['series', 'authors', 'narrators', 'publishers', 'languages', 'progress', 'issues', 'ebooks', 'abridged']
|
2022-12-17 21:50:01 +01:00
|
|
|
const filterByFirstPart = (state.settings.filterBy || '').split('.').shift()
|
2022-04-12 02:42:09 +02:00
|
|
|
if (invalidFilters.includes(filterByFirstPart)) {
|
|
|
|
settingsUpdate.filterBy = 'all'
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (state.settings.orderBy == 'media.metadata.author') {
|
|
|
|
settingsUpdate.orderBy = 'media.metadata.authorName'
|
|
|
|
}
|
2022-05-04 00:50:19 +02:00
|
|
|
if (state.settings.orderBy == 'media.numTracks') {
|
|
|
|
settingsUpdate.orderBy = 'media.duration'
|
|
|
|
}
|
2022-04-12 02:42:09 +02:00
|
|
|
}
|
|
|
|
if (Object.keys(settingsUpdate).length) {
|
|
|
|
dispatch('updateUserSettings', settingsUpdate)
|
|
|
|
}
|
|
|
|
},
|
2022-12-17 21:50:01 +01:00
|
|
|
updateUserSettings({ state, commit }, payload) {
|
|
|
|
if (!payload) return false
|
|
|
|
|
|
|
|
let hasChanges = false
|
|
|
|
const existingSettings = { ...state.settings }
|
|
|
|
for (const key in existingSettings) {
|
|
|
|
if (payload[key] !== undefined && existingSettings[key] !== payload[key]) {
|
|
|
|
hasChanges = true
|
|
|
|
existingSettings[key] = payload[key]
|
|
|
|
}
|
2021-08-24 01:31:04 +02:00
|
|
|
}
|
2022-12-17 21:50:01 +01:00
|
|
|
if (hasChanges) {
|
|
|
|
commit('setSettings', existingSettings)
|
|
|
|
this.$eventBus.$emit('user-settings', state.settings)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
loadUserSettings({ state, commit }) {
|
|
|
|
// Load settings from local storage
|
|
|
|
try {
|
|
|
|
let userSettingsFromLocal = localStorage.getItem('userSettings')
|
|
|
|
if (userSettingsFromLocal) {
|
|
|
|
userSettingsFromLocal = JSON.parse(userSettingsFromLocal)
|
|
|
|
const userSettings = { ...state.settings }
|
|
|
|
for (const key in userSettings) {
|
|
|
|
if (userSettingsFromLocal[key] !== undefined) {
|
|
|
|
userSettings[key] = userSettingsFromLocal[key]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
commit('setSettings', userSettings)
|
|
|
|
this.$eventBus.$emit('user-settings', state.settings)
|
2021-08-24 01:31:04 +02:00
|
|
|
}
|
2022-12-17 21:50:01 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to load userSettings from local storage', error)
|
|
|
|
}
|
2021-08-24 01:31:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mutations = {
|
|
|
|
setUser(state, user) {
|
|
|
|
state.user = user
|
2021-08-24 02:37:40 +02:00
|
|
|
if (user) {
|
|
|
|
if (user.token) localStorage.setItem('token', user.token)
|
|
|
|
} else {
|
2021-08-24 01:31:04 +02:00
|
|
|
localStorage.removeItem('token')
|
|
|
|
}
|
|
|
|
},
|
2022-07-19 00:19:16 +02:00
|
|
|
setUserToken(state, token) {
|
|
|
|
state.user.token = token
|
|
|
|
localStorage.setItem('token', user.token)
|
|
|
|
},
|
2022-03-26 17:59:34 +01:00
|
|
|
updateMediaProgress(state, { id, data }) {
|
2021-10-24 22:53:51 +02:00
|
|
|
if (!state.user) return
|
2022-03-17 19:33:22 +01:00
|
|
|
if (!data) {
|
2024-06-03 08:04:03 +02:00
|
|
|
state.user.mediaProgress = state.user.mediaProgress.filter((lip) => lip.id != id)
|
2022-03-17 19:33:22 +01:00
|
|
|
} else {
|
2024-06-03 08:04:03 +02:00
|
|
|
var indexOf = state.user.mediaProgress.findIndex((lip) => lip.id == id)
|
2022-03-17 19:33:22 +01:00
|
|
|
if (indexOf >= 0) {
|
2022-03-26 17:59:34 +01:00
|
|
|
state.user.mediaProgress.splice(indexOf, 1, data)
|
2022-03-17 19:33:22 +01:00
|
|
|
} else {
|
2022-03-26 17:59:34 +01:00
|
|
|
state.user.mediaProgress.push(data)
|
2022-03-17 19:33:22 +01:00
|
|
|
}
|
2021-10-24 22:53:51 +02:00
|
|
|
}
|
|
|
|
},
|
2021-08-24 01:31:04 +02:00
|
|
|
setSettings(state, settings) {
|
|
|
|
if (!settings) return
|
2022-12-17 22:10:25 +01:00
|
|
|
localStorage.setItem('userSettings', JSON.stringify(settings))
|
2022-12-17 21:50:01 +01:00
|
|
|
state.settings = settings
|
2022-11-12 00:28:05 +01:00
|
|
|
}
|
2024-06-03 08:04:03 +02:00
|
|
|
}
|