fix: save ZIP base media directly to gallery, avoid downloadRemoteMedia NPE
This commit is contained in:
@@ -616,31 +616,27 @@ class DownloadProcessor (
|
||||
|
||||
var shouldMergeOverlay = downloadRequest.shouldMergeOverlay
|
||||
|
||||
//if there is a zip file, extract it and replace the downloaded media with the extracted ones
|
||||
//if there is a zip file, extract it and save only the base media (discard overlay)
|
||||
downloadedMedias.values.find { FileType.fromFile(it) == FileType.ZIP }?.let { zipFile ->
|
||||
val oldDownloadedMedias = downloadedMedias.toMap()
|
||||
downloadedMedias.clear()
|
||||
|
||||
var baseMediaFile: File? = null
|
||||
zipFile.inputStream().use { zipFileInputStream ->
|
||||
MediaDownloaderHelper.getSplitElements(zipFileInputStream) { type, inputStream ->
|
||||
if (type == SplitMediaAssetType.OVERLAY) return@getSplitElements
|
||||
createMediaTempFile().apply {
|
||||
outputStream().use {
|
||||
inputStream.copyTo(it)
|
||||
}
|
||||
}.also {
|
||||
downloadedMedias[InputMedia(
|
||||
type = DownloadMediaType.LOCAL_MEDIA,
|
||||
content = it.absolutePath,
|
||||
isOverlay = false
|
||||
)] = it
|
||||
baseMediaFile = createMediaTempFile().apply {
|
||||
outputStream().use { inputStream.copyTo(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oldDownloadedMedias.forEach { (_, value) ->
|
||||
value.delete()
|
||||
oldDownloadedMedias.forEach { (_, value) -> value.delete() }
|
||||
|
||||
baseMediaFile?.let { baseMedia ->
|
||||
saveMediaToGallery(pendingTask, baseMedia, downloadMetadata)
|
||||
baseMedia.delete()
|
||||
}
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (shouldMergeOverlay) {
|
||||
|
||||
Reference in New Issue
Block a user