mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-06 20:08:48 +02:00
Ensure token is not part of download URL
This commit is contained in:
@@ -182,6 +182,9 @@ class DownloadItemManager(
|
||||
part.lastUpdateTime = System.currentTimeMillis()
|
||||
currentDownloadItemParts.add(part)
|
||||
persist(item, force = true)
|
||||
val token =
|
||||
DeviceManager.deviceData.serverConnectionConfigs
|
||||
.find { it.id == item.serverConnectionConfigId }?.token ?: DeviceManager.token
|
||||
activeCalls[part.id] =
|
||||
InternalDownloadManager(stagingFile, part.fileSize, object : InternalProgressCallback {
|
||||
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
||||
@@ -204,7 +207,9 @@ class DownloadItemManager(
|
||||
persist(item, force = true)
|
||||
}
|
||||
}
|
||||
}, { hasAvailableSpace(part) }).download(serverUrl(item, part))
|
||||
}, { hasAvailableSpace(part) }).download(
|
||||
serverUrl(item, part),
|
||||
token)
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
@@ -445,11 +450,8 @@ class DownloadItemManager(
|
||||
}
|
||||
|
||||
private fun serverUrl(item: DownloadItem, part: DownloadItemPart): String {
|
||||
val token = DeviceManager.deviceData.serverConnectionConfigs
|
||||
.find { it.id == item.serverConnectionConfigId }?.token ?: DeviceManager.token
|
||||
var url = "${item.serverAddress}${part.serverPath}?token=$token"
|
||||
if (part.serverPath.endsWith("/cover")) url += "&raw=1"
|
||||
return url
|
||||
val rawCover = if (part.serverPath.endsWith("/cover")) "?raw=1" else ""
|
||||
return "${item.serverAddress}${part.serverPath}$rawCover"
|
||||
}
|
||||
|
||||
private companion object {
|
||||
|
||||
+4
-2
@@ -22,16 +22,18 @@ class InternalDownloadManager(
|
||||
/**
|
||||
* Starts or resumes a download.
|
||||
*
|
||||
* @param url authenticated download URL
|
||||
* @param url download URL
|
||||
* @param token access token sent in the Authorization header
|
||||
* @return active call, used to cancel a stalled transfer
|
||||
*/
|
||||
fun download(url: String): Call {
|
||||
fun download(url: String, token: String): Call {
|
||||
destinationFile.parentFile?.mkdirs()
|
||||
val existingBytes = destinationFile.takeIf { it.exists() }?.length() ?: 0L
|
||||
val request =
|
||||
Request.Builder()
|
||||
.url(url)
|
||||
.addHeader("Accept-Encoding", "identity")
|
||||
.addHeader("Authorization", "Bearer $token")
|
||||
.apply {
|
||||
if (existingBytes > 0L) header("Range", "bytes=$existingBytes-")
|
||||
}
|
||||
|
||||
@@ -44,13 +44,9 @@ data class DownloadItemPart(
|
||||
fun make(downloadItemId:String, filename:String, fileSize: Long, destinationFile: File, finalDestinationFile: File, subfolder:String, serverPath:String, localFolder: LocalFolder, ebookFile: EBookFile?, audioTrack: AudioTrack?, episode: PodcastEpisode?) :DownloadItemPart {
|
||||
val destinationUri = Uri.fromFile(destinationFile)
|
||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||
val rawCover = if (serverPath.endsWith("/cover")) "?raw=1" else ""
|
||||
val downloadUri = Uri.parse("${DeviceManager.serverAddress}${serverPath}$rawCover")
|
||||
|
||||
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 | Server Path $serverPath")
|
||||
return DownloadItemPart(
|
||||
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
||||
@@ -86,12 +82,4 @@ data class DownloadItemPart(
|
||||
@get:JsonIgnore
|
||||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
||||
|
||||
@get:JsonIgnore
|
||||
val serverUrl: String
|
||||
get() {
|
||||
var url = "${DeviceManager.serverAddress}${serverPath}?token=${DeviceManager.token}"
|
||||
if (serverPath.endsWith("/cover")) url += "&raw=1"
|
||||
return url
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user