Remove token from image requests & fix download raw cover image #1328

This commit is contained in:
advplyr 2025-01-18 15:42:40 -06:00
parent d5fa36b11a
commit 111e8d38dc
8 changed files with 73 additions and 79 deletions

View file

@ -44,62 +44,71 @@ export const state = () => ({
})
export const getters = {
getDownloadItem: state => (libraryItemId, episodeId = null) => {
return state.itemDownloads.find(i => {
// if (episodeId && !i.episodes.some(e => e.id == episodeId)) return false
if (episodeId && i.episodeId !== episodeId) return false
return i.libraryItemId == libraryItemId
})
},
getLibraryItemCoverSrc: (state, getters, rootState, rootGetters) => (libraryItem, placeholder, raw = false) => {
if (!libraryItem) return placeholder
const media = libraryItem.media
if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder
getDownloadItem:
(state) =>
(libraryItemId, episodeId = null) => {
return state.itemDownloads.find((i) => {
// if (episodeId && !i.episodes.some(e => e.id == episodeId)) return false
if (episodeId && i.episodeId !== episodeId) return false
return i.libraryItemId == libraryItemId
})
},
getLibraryItemCoverSrc:
(state, getters, rootState, rootGetters) =>
(libraryItem, placeholder, raw = false) => {
if (!libraryItem) return placeholder
const 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
// Absolute URL covers (should no longer be used)
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
const userToken = rootGetters['user/getToken']
const serverAddress = rootGetters['user/getServerAddress']
if (!userToken || !serverAddress) return placeholder
const serverAddress = rootGetters['user/getServerAddress']
if (!serverAddress) return placeholder
const lastUpdate = libraryItem.updatedAt || Date.now()
const 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}`
}
if (process.env.NODE_ENV !== 'production') {
// Testing
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?ts=${lastUpdate}`
}
const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`)
return `${url}?token=${userToken}&ts=${lastUpdate}${raw ? '&raw=1' : ''}`
},
getLibraryItemCoverSrcById: (state, getters, rootState, rootGetters) => (libraryItemId, placeholder = null) => {
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg`
if (!libraryItemId) return placeholder
const userToken = rootGetters['user/getToken']
const serverAddress = rootGetters['user/getServerAddress']
if (!userToken || !serverAddress) return placeholder
const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`)
return `${url}?ts=${lastUpdate}${raw ? '&raw=1' : ''}`
},
getLibraryItemCoverSrcById:
(state, getters, rootState, rootGetters) =>
(libraryItemId, placeholder = null) => {
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg`
if (!libraryItemId) return placeholder
const serverAddress = rootGetters['user/getServerAddress']
if (!serverAddress) return placeholder
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
return `${url}?token=${userToken}`
},
getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => {
return state.localMediaProgress.find(lmp => {
if (episodeId != null && lmp.localEpisodeId != episodeId) return false
return lmp.localLibraryItemId == localLibraryItemId
})
},
getLocalMediaProgressByServerItemId: (state) => (libraryItemId, episodeId = null) => {
return state.localMediaProgress.find(lmp => {
if (episodeId != null && lmp.episodeId != episodeId) return false
return lmp.libraryItemId == libraryItemId
})
},
getJumpForwardIcon: state => (jumpForwardTime) => {
const item = state.jumpForwardItems.find(i => i.value == jumpForwardTime)
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
return url.toString()
},
getLocalMediaProgressById:
(state) =>
(localLibraryItemId, episodeId = null) => {
return state.localMediaProgress.find((lmp) => {
if (episodeId != null && lmp.localEpisodeId != episodeId) return false
return lmp.localLibraryItemId == localLibraryItemId
})
},
getLocalMediaProgressByServerItemId:
(state) =>
(libraryItemId, episodeId = null) => {
return state.localMediaProgress.find((lmp) => {
if (episodeId != null && lmp.episodeId != episodeId) return false
return lmp.libraryItemId == libraryItemId
})
},
getJumpForwardIcon: (state) => (jumpForwardTime) => {
const item = state.jumpForwardItems.find((i) => i.value == jumpForwardTime)
return item ? item.icon : 'forward_10'
},
getJumpBackwardsIcon: state => (jumpBackwardsTime) => {
const item = state.jumpBackwardsItems.find(i => i.value == jumpBackwardsTime)
getJumpBackwardsIcon: (state) => (jumpBackwardsTime) => {
const item = state.jumpBackwardsItems.find((i) => i.value == jumpBackwardsTime)
return item ? item.icon : 'replay_10'
}
}
@ -116,7 +125,7 @@ export const mutations = {
state.isModalOpen = val
},
addUpdateItemDownload(state, downloadItem) {
var index = state.itemDownloads.findIndex(i => i.id == downloadItem.id)
var index = state.itemDownloads.findIndex((i) => i.id == downloadItem.id)
if (index >= 0) {
state.itemDownloads.splice(index, 1, downloadItem)
} else {
@ -124,7 +133,7 @@ export const mutations = {
}
},
updateDownloadItemPart(state, downloadItemPart) {
const downloadItem = state.itemDownloads.find(i => i.id == downloadItemPart.downloadItemId)
const downloadItem = state.itemDownloads.find((i) => i.id == downloadItemPart.downloadItemId)
if (!downloadItem) {
console.error('updateDownloadItemPart: Download item not found for itemPart', JSON.stringify(downloadItemPart))
return
@ -132,7 +141,7 @@ export const mutations = {
let totalBytes = 0
let totalBytesDownloaded = 0
downloadItem.downloadItemParts = downloadItem.downloadItemParts.map(dip => {
downloadItem.downloadItemParts = downloadItem.downloadItemParts.map((dip) => {
let newDip = dip.id == downloadItemPart.id ? downloadItemPart : dip
totalBytes += newDip.completed ? Number(newDip.bytesDownloaded) : Number(newDip.fileSize)
@ -149,7 +158,7 @@ export const mutations = {
}
},
removeItemDownload(state, id) {
state.itemDownloads = state.itemDownloads.filter(i => i.id != id)
state.itemDownloads = state.itemDownloads.filter((i) => i.id != id)
},
setBookshelfListView(state, val) {
state.bookshelfListView = val
@ -164,7 +173,7 @@ export const mutations = {
if (!prog || !prog.id) {
return
}
var index = state.localMediaProgress.findIndex(lmp => lmp.id == prog.id)
var index = state.localMediaProgress.findIndex((lmp) => lmp.id == prog.id)
if (index >= 0) {
state.localMediaProgress.splice(index, 1, prog)
} else {
@ -172,10 +181,10 @@ export const mutations = {
}
},
removeLocalMediaProgress(state, id) {
state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.id != id)
state.localMediaProgress = state.localMediaProgress.filter((lmp) => lmp.id != id)
},
removeLocalMediaProgressForItem(state, llid) {
state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.localLibraryItemId !== llid)
state.localMediaProgress = state.localMediaProgress.filter((lmp) => lmp.localLibraryItemId !== llid)
},
setLastSearch(state, val) {
state.lastSearch = val
@ -203,4 +212,4 @@ export const mutations = {
state.rssFeedEntity = entity
state.showRSSFeedOpenCloseModal = true
}
}
}