mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-06 20:08:48 +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 =
|
val internalProgressCallback =
|
||||||
object : InternalProgressCallback {
|
object : InternalProgressCallback {
|
||||||
override fun onProgress(totalBytesWritten: Long, progress: Long) {
|
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.bytesDownloaded = totalBytesWritten
|
||||||
downloadItemPart.progress = progress
|
downloadItemPart.progress = progress
|
||||||
}
|
}
|
||||||
@@ -215,6 +220,21 @@ class DownloadItemManager(
|
|||||||
downloadItem?.let { checkDownloadItemFinished(it) }
|
downloadItem?.let { checkDownloadItemFinished(it) }
|
||||||
}
|
}
|
||||||
currentDownloadItemParts.remove(downloadItemPart)
|
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,
|
@JsonIgnore val finalDestinationUri: Uri,
|
||||||
val finalDestinationSubfolder: String,
|
val finalDestinationSubfolder: String,
|
||||||
var downloadId: Long?,
|
var downloadId: Long?,
|
||||||
|
var lastUpdateTime: Long?,
|
||||||
var progress: Long,
|
var progress: Long,
|
||||||
var bytesDownloaded: Long
|
var bytesDownloaded: Long
|
||||||
) {
|
) {
|
||||||
companion object {
|
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 destinationUri = Uri.fromFile(destinationFile)
|
||||||
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
val finalDestinationUri = Uri.fromFile(finalDestinationFile)
|
||||||
|
|
||||||
@@ -47,7 +60,10 @@ data class DownloadItemPart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
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"
|
||||||
|
)
|
||||||
return DownloadItemPart(
|
return DownloadItemPart(
|
||||||
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
id = DeviceManager.getBase64Id(finalDestinationFile.absolutePath),
|
||||||
downloadItemId,
|
downloadItemId,
|
||||||
@@ -70,6 +86,7 @@ data class DownloadItemPart(
|
|||||||
finalDestinationUri = finalDestinationUri,
|
finalDestinationUri = finalDestinationUri,
|
||||||
finalDestinationSubfolder = subfolder,
|
finalDestinationSubfolder = subfolder,
|
||||||
downloadId = null,
|
downloadId = null,
|
||||||
|
lastUpdateTime = null,
|
||||||
progress = 0,
|
progress = 0,
|
||||||
bytesDownloaded = 0
|
bytesDownloaded = 0
|
||||||
)
|
)
|
||||||
@@ -77,10 +94,12 @@ data class DownloadItemPart(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val isInternalStorage get() = localFolderId.startsWith("internal-")
|
val isInternalStorage
|
||||||
|
get() = localFolderId.startsWith("internal-")
|
||||||
|
|
||||||
@get:JsonIgnore
|
@get:JsonIgnore
|
||||||
val serverUrl get() = uri.toString()
|
val serverUrl
|
||||||
|
get() = uri.toString()
|
||||||
|
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
fun getDownloadRequest(): DownloadManager.Request {
|
fun getDownloadRequest(): DownloadManager.Request {
|
||||||
|
|||||||
Reference in New Issue
Block a user