mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-06-21 04:15:46 +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 destinationUri = Uri.fromFile(destinationFile)
|
||||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||||
|
|
||||||
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}"
|
var downloadUrl = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
||||||
|
if (serverPath.endsWith("/cover")) {
|
||||||
downloadUrl += if (serverPath.endsWith("/cover")) "?raw=1" // Download raw cover image
|
downloadUrl += "&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")
|
||||||
|
|
|
@ -56,11 +56,15 @@ export default {
|
||||||
},
|
},
|
||||||
imgSrc() {
|
imgSrc() {
|
||||||
if (!this.imagePath || !this.serverAddress) return null
|
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')) {
|
if (process.env.NODE_ENV !== 'production' && this.serverAddress.startsWith('http://192.168')) {
|
||||||
// Testing
|
// 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: {
|
methods: {
|
||||||
|
|
|
@ -74,7 +74,13 @@ export const getters = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = new URL(`${serverAddress}/api/items/${libraryItem.id}/cover`)
|
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:
|
getLibraryItemCoverSrcById:
|
||||||
(state, getters, rootState, rootGetters) =>
|
(state, getters, rootState, rootGetters) =>
|
||||||
|
@ -85,6 +91,9 @@ export const getters = {
|
||||||
if (!serverAddress) return placeholder
|
if (!serverAddress) return placeholder
|
||||||
|
|
||||||
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
|
const url = new URL(`${serverAddress}/api/items/${libraryItemId}/cover`)
|
||||||
|
if (rootGetters.getDoesServerImagesRequireToken) {
|
||||||
|
return `${url}?token=${rootGetters['user/getToken']}`
|
||||||
|
}
|
||||||
return url.toString()
|
return url.toString()
|
||||||
},
|
},
|
||||||
getLocalMediaProgressById:
|
getLocalMediaProgressById:
|
||||||
|
|
|
@ -85,6 +85,20 @@ export const getters = {
|
||||||
getCanStreamingUsingCellular: (state) => {
|
getCanStreamingUsingCellular: (state) => {
|
||||||
if (!state.deviceData?.deviceSettings?.streamingUsingCellular) return 'ALWAYS'
|
if (!state.deviceData?.deviceSettings?.streamingUsingCellular) return 'ALWAYS'
|
||||||
return state.deviceData.deviceSettings.streamingUsingCellular || '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