Fix crash downloading with old server, check server version to append token on image requests #1450

This commit is contained in:
advplyr 2025-01-26 14:22:35 -06:00
parent 08651d28ef
commit c79ecbb92e
4 changed files with 34 additions and 7 deletions

View file

@ -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")

View file

@ -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: {

View file

@ -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:

View file

@ -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)
}
}