mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-29 22:57:16 +02:00
Download part removed after no updates for 10 seconds, still need to fix the UI
This commit is contained in:
@@ -127,6 +127,11 @@ class DownloadItemManager(
|
||||
val internalProgressCallback =
|
||||
object : InternalProgressCallback {
|
||||
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
||||
// Store time progress was last changed to prevent stale downloads from getting
|
||||
// stuck in an infinite loop
|
||||
if (downloadItemPart.bytesDownloaded != totalBytesWritten) {
|
||||
downloadItemPart.lastUpdateTime = System.currentTimeMillis()
|
||||
}
|
||||
downloadItemPart.bytesDownloaded = totalBytesWritten
|
||||
downloadItemPart.progress = progress
|
||||
}
|
||||
@@ -215,6 +220,21 @@ class DownloadItemManager(
|
||||
downloadItem?.let { checkDownloadItemFinished(it) }
|
||||
}
|
||||
currentDownloadItemParts.remove(downloadItemPart)
|
||||
} else {
|
||||
// Check for stalled downloads
|
||||
val currentTimeMillis = System.currentTimeMillis()
|
||||
val lastUpdateTime = downloadItemPart.lastUpdateTime ?: currentTimeMillis
|
||||
val timeSinceLastUpdate = currentTimeMillis - lastUpdateTime
|
||||
val stallTimeoutMillis = 10 * 1000 // 10 seconds
|
||||
if (timeSinceLastUpdate > stallTimeoutMillis) {
|
||||
Log.w(
|
||||
tag,
|
||||
"Download stalled for ${downloadItemPart.filename}, removing from download queue."
|
||||
)
|
||||
downloadItemPart.failed = true
|
||||
clientEventEmitter.onDownloadItemPartUpdate(downloadItemPart)
|
||||
currentDownloadItemParts.remove(downloadItemPart)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,11 +33,24 @@ data class DownloadItemPart(
|
||||
@JsonIgnore val finalDestinationUri: Uri,
|
||||
val finalDestinationSubfolder: String,
|
||||
var downloadId: Long?,
|
||||
var lastUpdateTime: Long?,
|
||||
var progress: Long,
|
||||
var bytesDownloaded: Long
|
||||
) {
|
||||
companion object {
|
||||
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 finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||
|
||||
@@ -47,7 +60,10 @@ data class DownloadItemPart(
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
return DownloadItemPart(
|
||||
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
||||
downloadItemId,
|
||||
@@ -70,6 +86,7 @@ data class DownloadItemPart(
|
||||
finalDestinationUri = finalDestinationUri,
|
||||
finalDestinationSubfolder = subfolder,
|
||||
downloadId = null,
|
||||
lastUpdateTime = null,
|
||||
progress = 0,
|
||||
bytesDownloaded = 0
|
||||
)
|
||||
@@ -77,10 +94,12 @@ data class DownloadItemPart(
|
||||
}
|
||||
|
||||
@get:JsonIgnore
|
||||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
||||
val isInternalStorage
|
||||
get() = localFolderId.startsWith("internal-")
|
||||
|
||||
@get:JsonIgnore
|
||||
val serverUrl get() = uri.toString()
|
||||
val serverUrl
|
||||
get() = uri.toString()
|
||||
|
||||
@JsonIgnore
|
||||
fun getDownloadRequest(): DownloadManager.Request {
|
||||
|
||||
Reference in New Issue
Block a user