Skip to content

Commit

Permalink
Fix crash downloading with old server, check server version to append…
Browse files Browse the repository at this point in the history
… token on image requests #1450
  • Loading branch information
advplyr committed Jan 26, 2025
1 parent 08651d2 commit c79ecbb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 6 additions & 2 deletions components/covers/AuthorImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
11 changes: 10 additions & 1 deletion store/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit c79ecbb

Please sign in to comment.