mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-06-20 20:05:44 +02:00
Fix crash downloading with old server, check server version to append token on image requests #1450
This commit is contained in:
parent
08651d28ef
commit
c79ecbb92e
4 changed files with 34 additions and 7 deletions
|
@ -41,10 +41,10 @@ data class DownloadItemPart(
|
|||
val destinationUri = Uri.fromFile(destinationFile)
|
||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||
|
||||
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}"
|
||||
|
||||
downloadUrl += if (serverPath.endsWith("/cover")) "?raw=1" // Download raw cover image
|
||||
else "?token=${DeviceManager.token}"
|
||||
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
||||
if (serverPath.endsWith("/cover")) {
|
||||
downloadUrl += "&raw=1" // Download raw cover image
|
||||
}
|
||||
|
||||
val downloadUri = Uri.parse(downloadUrl)
|
||||
Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Download URI $downloadUri")
|
||||
|
|
|
@ -56,11 +56,15 @@ export default {
|
|||
},
|
||||
imgSrc() {
|
||||
if (!this.imagePath || !this.serverAddress) return null
|
||||
const urlQuery = new URLSearchParams({ ts: this.updatedAt })
|
||||
if (this.$store.getters.getDoesServerImagesRequireToken) {
|
||||
urlQuery.append('token', this.$store.getters['user/getToken'])
|
||||
}
|
||||
if (process.env.NODE_ENV !== 'production' && this.serverAddress.startsWith('http://192.168')) {
|
||||
// Testing
|
||||
return `http://localhost:3333/api/authors/${this.authorId}/image?ts=${this.updatedAt}`
|
||||
return `http://localhost:3333/api/authors/${this.authorId}/image?${urlQuery.toString()}`
|
||||
}
|
||||
return `${this.serverAddress}/api/authors/${this.authorId}/image?ts=${this.updatedAt}`
|
||||
return `${this.serverAddress}/api/authors/${this.authorId}/image?${urlQuery.toString()}`
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -74,7 +74,13 @@ export const getters = {
|
|||
}
|
||||
|
||||
const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`)
|
||||
return `${url}?ts=${lastUpdate}${raw ? '&raw=1' : ''}`
|
||||
const urlQuery = new URLSearchParams()
|
||||
urlQuery.append('ts', lastUpdate)
|
||||
if (raw) urlQuery.append('raw', '1')
|
||||
if (rootGetters.getDoesServerImagesRequireToken) {
|
||||
urlQuery.append('token', rootGetters['user/getToken'])
|
||||
}
|
||||
return `${url}?${urlQuery}`
|
||||
},
|
||||
getLibraryItemCoverSrcById:
|
||||
(state, getters, rootState, rootGetters) =>
|
||||
|
@ -85,6 +91,9 @@ export const getters = {
|
|||
if (!serverAddress) return placeholder
|
||||
|
||||
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
|
||||
if (rootGetters.getDoesServerImagesRequireToken) {
|
||||
return `${url}?token=${rootGetters['user/getToken']}`
|
||||
}
|
||||
return url.toString()
|
||||
},
|
||||
getLocalMediaProgressById:
|
||||
|
|
|
@ -85,6 +85,20 @@ export const getters = {
|
|||
getCanStreamingUsingCellular: (state) => {
|
||||
if (!state.deviceData?.deviceSettings?.streamingUsingCellular) return 'ALWAYS'
|
||||
return state.deviceData.deviceSettings.streamingUsingCellular || 'ALWAYS'
|
||||
},
|
||||
/**
|
||||
* Old server versions require a token for images
|
||||
*
|
||||
* @param {*} state
|
||||
* @returns {boolean} True if server version is less than 2.17
|
||||
*/
|
||||
getDoesServerImagesRequireToken: (state) => {
|
||||
const serverVersion = state.serverSettings?.version
|
||||
if (!serverVersion) return false
|
||||
const versionParts = serverVersion.split('.')
|
||||
const majorVersion = parseInt(versionParts[0])
|
||||
const minorVersion = parseInt(versionParts[1])
|
||||
return majorVersion < 2 || (majorVersion == 2 && minorVersion < 17)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue