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 destinationUri = Uri.fromFile(destinationFile)
|
||||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||||
|
|
||||||
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}"
|
||||||
if (serverPath.endsWith("/cover")) downloadUrl += "&format=jpeg&raw=1" // For cover images force to jpeg
|
|
||||||
|
downloadUrl += if (serverPath.endsWith("/cover")) "?raw=1" // Download raw cover image
|
||||||
|
else "?token=${DeviceManager.token}"
|
||||||
|
|
||||||
val downloadUri = Uri.parse(downloadUrl)
|
val downloadUri = Uri.parse(downloadUrl)
|
||||||
Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri")
|
Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri")
|
||||||
return DownloadItemPart(
|
return DownloadItemPart(
|
||||||
|
@ -77,7 +80,7 @@ data class DownloadItemPart(
|
||||||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
||||||
|
|
||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val serverUrl get() = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
val serverUrl get() = uri.toString()
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
fun getDownloadRequest(): DownloadManager.Request {
|
fun getDownloadRequest(): DownloadManager.Request {
|
||||||
|
|
|
@ -42,9 +42,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
userToken() {
|
|
||||||
return this.$store.getters['user/getToken']
|
|
||||||
},
|
|
||||||
_author() {
|
_author() {
|
||||||
return this.author || {}
|
return this.author || {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -39,9 +39,6 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
userToken() {
|
|
||||||
return this.$store.getters['user/getToken']
|
|
||||||
},
|
|
||||||
_author() {
|
_author() {
|
||||||
return this.author || {}
|
return this.author || {}
|
||||||
},
|
},
|
||||||
|
@ -61,9 +58,9 @@ export default {
|
||||||
if (!this.imagePath || !this.serverAddress) return null
|
if (!this.imagePath || !this.serverAddress) return null
|
||||||
if (process.env.NODE_ENV !== 'production' && this.serverAddress.startsWith('http://192.168')) {
|
if (process.env.NODE_ENV !== 'production' && this.serverAddress.startsWith('http://192.168')) {
|
||||||
// Testing
|
// 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: {
|
methods: {
|
||||||
|
|
|
@ -141,9 +141,6 @@ export default {
|
||||||
},
|
},
|
||||||
authorBottom() {
|
authorBottom() {
|
||||||
return 0.75 * this.sizeMultiplier
|
return 0.75 * this.sizeMultiplier
|
||||||
},
|
|
||||||
userToken() {
|
|
||||||
return this.$store.getters['user/getToken']
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
|
@ -50,9 +50,6 @@ export default {
|
||||||
libraryItemId() {
|
libraryItemId() {
|
||||||
return this.libraryItem.id
|
return this.libraryItem.id
|
||||||
},
|
},
|
||||||
userToken() {
|
|
||||||
return this.$store.getters['user/getToken']
|
|
||||||
},
|
|
||||||
ebookFiles() {
|
ebookFiles() {
|
||||||
return (this.libraryItem.libraryFiles || []).filter((lf) => lf.fileType === 'ebook')
|
return (this.libraryItem.libraryFiles || []).filter((lf) => lf.fileType === 'ebook')
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,9 +24,6 @@ export default {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
userToken() {
|
|
||||||
return this.$store.getters['user/getToken']
|
|
||||||
},
|
|
||||||
userCanUpdate() {
|
userCanUpdate() {
|
||||||
return this.$store.getters['user/getUserCanUpdate']
|
return this.$store.getters['user/getUserCanUpdate']
|
||||||
},
|
},
|
||||||
|
|
|
@ -366,9 +366,6 @@ export default {
|
||||||
user() {
|
user() {
|
||||||
return this.$store.state.user.user
|
return this.$store.state.user.user
|
||||||
},
|
},
|
||||||
userToken() {
|
|
||||||
return this.$store.getters['user/getToken']
|
|
||||||
},
|
|
||||||
userItemProgress() {
|
userItemProgress() {
|
||||||
if (this.isPodcast) return null
|
if (this.isPodcast) return null
|
||||||
if (this.isLocal) return this.localItemProgress
|
if (this.isLocal) return this.localItemProgress
|
||||||
|
|
121
store/globals.js
121
store/globals.js
|
@ -44,62 +44,71 @@ export const state = () => ({
|
||||||
})
|
})
|
||||||
|
|
||||||
export const getters = {
|
export const getters = {
|
||||||
getDownloadItem: state => (libraryItemId, episodeId = null) => {
|
getDownloadItem:
|
||||||
return state.itemDownloads.find(i => {
|
(state) =>
|
||||||
// if (episodeId && !i.episodes.some(e => e.id == episodeId)) return false
|
(libraryItemId, episodeId = null) => {
|
||||||
if (episodeId && i.episodeId !== episodeId) return false
|
return state.itemDownloads.find((i) => {
|
||||||
return i.libraryItemId == libraryItemId
|
// 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
|
getLibraryItemCoverSrc:
|
||||||
if (!media || !media.coverPath || media.coverPath === placeholder) return placeholder
|
(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)
|
// Absolute URL covers (should no longer be used)
|
||||||
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
|
if (media.coverPath.startsWith('http:') || media.coverPath.startsWith('https:')) return media.coverPath
|
||||||
|
|
||||||
const userToken = rootGetters['user/getToken']
|
const serverAddress = rootGetters['user/getServerAddress']
|
||||||
const serverAddress = rootGetters['user/getServerAddress']
|
if (!serverAddress) return placeholder
|
||||||
if (!userToken || !serverAddress) return placeholder
|
|
||||||
|
|
||||||
const lastUpdate = libraryItem.updatedAt || Date.now()
|
const lastUpdate = libraryItem.updatedAt || Date.now()
|
||||||
|
|
||||||
if (process.env.NODE_ENV !== 'production') { // Testing
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?token=${userToken}&ts=${lastUpdate}`
|
// Testing
|
||||||
}
|
// return `http://localhost:3333/api/items/${libraryItem.id}/cover?ts=${lastUpdate}`
|
||||||
|
}
|
||||||
|
|
||||||
const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`)
|
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:
|
||||||
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg`
|
(state, getters, rootState, rootGetters) =>
|
||||||
if (!libraryItemId) return placeholder
|
(libraryItemId, placeholder = null) => {
|
||||||
const userToken = rootGetters['user/getToken']
|
if (!placeholder) placeholder = `${rootState.routerBasePath}/book_placeholder.jpg`
|
||||||
const serverAddress = rootGetters['user/getServerAddress']
|
if (!libraryItemId) return placeholder
|
||||||
if (!userToken || !serverAddress) return placeholder
|
const serverAddress = rootGetters['user/getServerAddress']
|
||||||
|
if (!serverAddress) return placeholder
|
||||||
|
|
||||||
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
|
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
|
||||||
return `${url}?token=${userToken}`
|
return url.toString()
|
||||||
},
|
},
|
||||||
getLocalMediaProgressById: (state) => (localLibraryItemId, episodeId = null) => {
|
getLocalMediaProgressById:
|
||||||
return state.localMediaProgress.find(lmp => {
|
(state) =>
|
||||||
if (episodeId != null && lmp.localEpisodeId != episodeId) return false
|
(localLibraryItemId, episodeId = null) => {
|
||||||
return lmp.localLibraryItemId == localLibraryItemId
|
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
|
getLocalMediaProgressByServerItemId:
|
||||||
return lmp.libraryItemId == libraryItemId
|
(state) =>
|
||||||
})
|
(libraryItemId, episodeId = null) => {
|
||||||
},
|
return state.localMediaProgress.find((lmp) => {
|
||||||
getJumpForwardIcon: state => (jumpForwardTime) => {
|
if (episodeId != null && lmp.episodeId != episodeId) return false
|
||||||
const item = state.jumpForwardItems.find(i => i.value == jumpForwardTime)
|
return lmp.libraryItemId == libraryItemId
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getJumpForwardIcon: (state) => (jumpForwardTime) => {
|
||||||
|
const item = state.jumpForwardItems.find((i) => i.value == jumpForwardTime)
|
||||||
return item ? item.icon : 'forward_10'
|
return item ? item.icon : 'forward_10'
|
||||||
},
|
},
|
||||||
getJumpBackwardsIcon: state => (jumpBackwardsTime) => {
|
getJumpBackwardsIcon: (state) => (jumpBackwardsTime) => {
|
||||||
const item = state.jumpBackwardsItems.find(i => i.value == jumpBackwardsTime)
|
const item = state.jumpBackwardsItems.find((i) => i.value == jumpBackwardsTime)
|
||||||
return item ? item.icon : 'replay_10'
|
return item ? item.icon : 'replay_10'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +125,7 @@ export const mutations = {
|
||||||
state.isModalOpen = val
|
state.isModalOpen = val
|
||||||
},
|
},
|
||||||
addUpdateItemDownload(state, downloadItem) {
|
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) {
|
if (index >= 0) {
|
||||||
state.itemDownloads.splice(index, 1, downloadItem)
|
state.itemDownloads.splice(index, 1, downloadItem)
|
||||||
} else {
|
} else {
|
||||||
|
@ -124,7 +133,7 @@ export const mutations = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateDownloadItemPart(state, downloadItemPart) {
|
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) {
|
if (!downloadItem) {
|
||||||
console.error('updateDownloadItemPart: Download item not found for itemPart', JSON.stringify(downloadItemPart))
|
console.error('updateDownloadItemPart: Download item not found for itemPart', JSON.stringify(downloadItemPart))
|
||||||
return
|
return
|
||||||
|
@ -132,7 +141,7 @@ export const mutations = {
|
||||||
|
|
||||||
let totalBytes = 0
|
let totalBytes = 0
|
||||||
let totalBytesDownloaded = 0
|
let totalBytesDownloaded = 0
|
||||||
downloadItem.downloadItemParts = downloadItem.downloadItemParts.map(dip => {
|
downloadItem.downloadItemParts = downloadItem.downloadItemParts.map((dip) => {
|
||||||
let newDip = dip.id == downloadItemPart.id ? downloadItemPart : dip
|
let newDip = dip.id == downloadItemPart.id ? downloadItemPart : dip
|
||||||
|
|
||||||
totalBytes += newDip.completed ? Number(newDip.bytesDownloaded) : Number(newDip.fileSize)
|
totalBytes += newDip.completed ? Number(newDip.bytesDownloaded) : Number(newDip.fileSize)
|
||||||
|
@ -149,7 +158,7 @@ export const mutations = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeItemDownload(state, id) {
|
removeItemDownload(state, id) {
|
||||||
state.itemDownloads = state.itemDownloads.filter(i => i.id != id)
|
state.itemDownloads = state.itemDownloads.filter((i) => i.id != id)
|
||||||
},
|
},
|
||||||
setBookshelfListView(state, val) {
|
setBookshelfListView(state, val) {
|
||||||
state.bookshelfListView = val
|
state.bookshelfListView = val
|
||||||
|
@ -164,7 +173,7 @@ export const mutations = {
|
||||||
if (!prog || !prog.id) {
|
if (!prog || !prog.id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var index = state.localMediaProgress.findIndex(lmp => lmp.id == prog.id)
|
var index = state.localMediaProgress.findIndex((lmp) => lmp.id == prog.id)
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
state.localMediaProgress.splice(index, 1, prog)
|
state.localMediaProgress.splice(index, 1, prog)
|
||||||
} else {
|
} else {
|
||||||
|
@ -172,10 +181,10 @@ export const mutations = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
removeLocalMediaProgress(state, id) {
|
removeLocalMediaProgress(state, id) {
|
||||||
state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.id != id)
|
state.localMediaProgress = state.localMediaProgress.filter((lmp) => lmp.id != id)
|
||||||
},
|
},
|
||||||
removeLocalMediaProgressForItem(state, llid) {
|
removeLocalMediaProgressForItem(state, llid) {
|
||||||
state.localMediaProgress = state.localMediaProgress.filter(lmp => lmp.localLibraryItemId !== llid)
|
state.localMediaProgress = state.localMediaProgress.filter((lmp) => lmp.localLibraryItemId !== llid)
|
||||||
},
|
},
|
||||||
setLastSearch(state, val) {
|
setLastSearch(state, val) {
|
||||||
state.lastSearch = val
|
state.lastSearch = val
|
||||||
|
@ -203,4 +212,4 @@ export const mutations = {
|
||||||
state.rssFeedEntity = entity
|
state.rssFeedEntity = entity
|
||||||
state.showRSSFeedOpenCloseModal = true
|
state.showRSSFeedOpenCloseModal = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue