mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-07-10 22:14:48 +02:00
Remove token from image requests & fix download raw cover image #1328
This commit is contained in:
parent
d5fa36b11a
commit
111e8d38dc
8 changed files with 73 additions and 79 deletions
|
@ -41,8 +41,11 @@ data class DownloadItemPart(
|
|||
val destinationUri = Uri.fromFile(destinationFile)
|
||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||
|
||||
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
||||
if (serverPath.endsWith("/cover")) downloadUrl += "&format=jpeg&raw=1" // For cover images force to jpeg
|
||||
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}"
|
||||
|
||||
downloadUrl += if (serverPath.endsWith("/cover")) "?raw=1" // Download raw cover image
|
||||
else "?token=${DeviceManager.token}"
|
||||
|
||||
val downloadUri = Uri.parse(downloadUrl)
|
||||
Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri")
|
||||
return DownloadItemPart(
|
||||
|
@ -77,7 +80,7 @@ data class DownloadItemPart(
|
|||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
||||
|
||||
@get:JsonIgnore
|
||||
val serverUrl get() = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
||||
val serverUrl get() = uri.toString()
|
||||
|
||||
@JsonIgnore
|
||||
fun getDownloadRequest(): DownloadManager.Request {
|
||||
|
|
|
@ -42,9 +42,6 @@ export default {
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
userToken() {
|
||||
return this.$store.getters['user/getToken']
|
||||
},
|
||||
_author() {
|
||||
return this.author || {}
|
||||
},
|
||||
|
|
|
@ -39,9 +39,6 @@ export default {
|
|||
}
|
||||
},
|
||||
computed: {
|
||||
userToken() {
|
||||
return this.$store.getters['user/getToken']
|
||||
},
|
||||
_author() {
|
||||
return this.author || {}
|
||||
},
|
||||
|
@ -61,9 +58,9 @@ export default {
|
|||
if (!this.imagePath || !this.serverAddress) return null
|
||||
if (process.env.NODE_ENV !== 'production' && this.serverAddress.startsWith('http://192.168')) {
|
||||
// Testing
|
||||
return `http://localhost:3333/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}`
|
||||
return `http://localhost:3333/api/authors/${this.authorId}/image?ts=${this.updatedAt}`
|
||||
}
|
||||
return `${this.serverAddress}/api/authors/${this.authorId}/image?token=${this.userToken}&ts=${this.updatedAt}`
|
||||
return `${this.serverAddress}/api/authors/${this.authorId}/image?ts=${this.updatedAt}`
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -141,9 +141,6 @@ export default {
|
|||
},
|
||||
authorBottom() {
|
||||
return 0.75 * this.sizeMultiplier
|
||||
},
|
||||
userToken() {
|
||||
return this.$store.getters['user/getToken']
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -50,9 +50,6 @@ export default {
|
|||
libraryItemId() {
|
||||
return this.libraryItem.id
|
||||
},
|
||||
userToken() {
|
||||
return this.$store.getters['user/getToken']
|
||||
},
|
||||
ebookFiles() {
|
||||
return (this.libraryItem.libraryFiles || []).filter((lf) => lf.fileType === 'ebook')
|
||||
},
|
||||
|
|
|
@ -24,9 +24,6 @@ export default {
|
|||
return {}
|
||||
},
|
||||
computed: {
|
||||
userToken() {
|
||||
return this.$store.getters['user/getToken']
|
||||
},
|
||||
userCanUpdate() {
|
||||
return this.$store.getters['user/getUserCanUpdate']
|
||||
},
|
||||
|
|
|
@ -366,9 +366,6 @@ export default {
|
|||
user() {
|
||||
return this.$store.state.user.user
|
||||
},
|
||||
userToken() {
|
||||
return this.$store.getters['user/getToken']
|
||||
},
|
||||
userItemProgress() {
|
||||
if (this.isPodcast) return null
|
||||
if (this.isLocal) return this.localItemProgress
|
||||
|
|
|
@ -44,14 +44,18 @@ export const state = () => ({
|
|||
})
|
||||
|
||||
export const getters = {
|
||||
getDownloadItem: state => (libraryItemId, episodeId = null) => {
|
||||
return state.itemDownloads.find(i => {
|
||||
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) => {
|
||||
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
|
||||
|
@ -59,47 +63,52 @@ export const getters = {
|
|||
// 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
|
||||
if (!serverAddress) return placeholder
|
||||
|
||||
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' : ''}`
|
||||
return `${url}?ts=${lastUpdate}${raw ? '&raw=1' : ''}`
|
||||
},
|
||||
getLibraryItemCoverSrcById: (state, getters, rootState, rootGetters) => (libraryItemId, placeholder = null) => {
|
||||
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
|
||||
if (!serverAddress) return placeholder
|
||||
|
||||
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
|
||||
return `${url}?token=${userToken}`
|
||||
return url.toString()
|
||||
},
|
||||
getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => {
|
||||
return state.localMediaProgress.find(lmp => {
|
||||
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 => {
|
||||
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)
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue