mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-30 07:07:22 +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()
|
part.lastUpdateTime = System.currentTimeMillis()
|
||||||
currentDownloadItemParts.add(part)
|
currentDownloadItemParts.add(part)
|
||||||
persist(item, force = true)
|
persist(item, force = true)
|
||||||
|
val token =
|
||||||
|
DeviceManager.deviceData.serverConnectionConfigs
|
||||||
|
.find { it.id == item.serverConnectionConfigId }?.token ?: DeviceManager.token
|
||||||
activeCalls[part.id] =
|
activeCalls[part.id] =
|
||||||
InternalDownloadManager(stagingFile, part.fileSize, object : InternalProgressCallback {
|
InternalDownloadManager(stagingFile, part.fileSize, object : InternalProgressCallback {
|
||||||
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
||||||
@@ -204,7 +207,9 @@ class DownloadItemManager(
|
|||||||
persist(item, force = true)
|
persist(item, force = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, { hasAvailableSpace(part) }).download(serverUrl(item, part))
|
}, { hasAvailableSpace(part) }).download(
|
||||||
|
serverUrl(item, part),
|
||||||
|
token)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
@@ -445,11 +450,8 @@ class DownloadItemManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun serverUrl(item: DownloadItem, part: DownloadItemPart): String {
|
private fun serverUrl(item: DownloadItem, part: DownloadItemPart): String {
|
||||||
val token = DeviceManager.deviceData.serverConnectionConfigs
|
val rawCover = if (part.serverPath.endsWith("/cover")) "?raw=1" else ""
|
||||||
.find { it.id == item.serverConnectionConfigId }?.token ?: DeviceManager.token
|
return "${item.serverAddress}${part.serverPath}$rawCover"
|
||||||
var url = "${item.serverAddress}${part.serverPath}?token=$token"
|
|
||||||
if (part.serverPath.endsWith("/cover")) url += "&raw=1"
|
|
||||||
return url
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|||||||
+4
-2
@@ -22,16 +22,18 @@ class InternalDownloadManager(
|
|||||||
/**
|
/**
|
||||||
* Starts or resumes a download.
|
* 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
|
* @return active call, used to cancel a stalled transfer
|
||||||
*/
|
*/
|
||||||
fun download(url: String): Call {
|
fun download(url: String, token: String): Call {
|
||||||
destinationFile.parentFile?.mkdirs()
|
destinationFile.parentFile?.mkdirs()
|
||||||
val existingBytes = destinationFile.takeIf { it.exists() }?.length() ?: 0L
|
val existingBytes = destinationFile.takeIf { it.exists() }?.length() ?: 0L
|
||||||
val request =
|
val request =
|
||||||
Request.Builder()
|
Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.addHeader("Accept-Encoding", "identity")
|
.addHeader("Accept-Encoding", "identity")
|
||||||
|
.addHeader("Authorization", "Bearer $token")
|
||||||
.apply {
|
.apply {
|
||||||
if (existingBytes > 0L) header("Range", "bytes=$existingBytes-")
|
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 {
|
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 destinationUri = Uri.fromFile(destinationFile)
|
||||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
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")
|
Log.d("DownloadItemPart", "Audio File Destination Uri: $destinationUri | Final Destination Uri: $finalDestinationUri | Server Path $serverPath")
|
||||||
return DownloadItemPart(
|
return DownloadItemPart(
|
||||||
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
||||||
@@ -86,12 +82,4 @@ data class DownloadItemPart(
|
|||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
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