mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-05-31 05:50:18 +02:00
fix(cdndownloader): coroutines
This commit is contained in:
parent
e56c5250bb
commit
f9611bde76
@ -369,7 +369,7 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
|
|||||||
|
|
||||||
//download the message content
|
//download the message content
|
||||||
try {
|
try {
|
||||||
var inputStream: InputStream = CdnDownloader.downloadWithDefaultEndpoints(urlKey) ?: return
|
var inputStream: InputStream = CdnDownloader.downloadWithDefaultEndpoints(urlKey) ?: throw FileNotFoundException("Unable to get $urlKey from cdn list. Check the logs for more info")
|
||||||
inputStream = EncryptionUtils.decryptInputStreamFromArroyo(
|
inputStream = EncryptionUtils.decryptInputStreamFromArroyo(
|
||||||
inputStream,
|
inputStream,
|
||||||
contentType,
|
contentType,
|
||||||
@ -436,8 +436,6 @@ class MediaDownloader : Feature("MediaDownloader", loadParams = FeatureLoadParam
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
downloadMediaContent(mediaData, mediaData.contentHashCode(), messageAuthor, fileType)
|
downloadMediaContent(mediaData, mediaData.contentHashCode(), messageAuthor, fileType)
|
||||||
} catch (e: FileNotFoundException) {
|
|
||||||
context.shortToast("Unable to get $urlKey from cdn list. Check the logs for more info")
|
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
context.shortToast("Failed to download " + e.message)
|
context.shortToast("Failed to download " + e.message)
|
||||||
xposedLog(e)
|
xposedLog(e)
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package me.rhunk.snapenhance.util.download
|
package me.rhunk.snapenhance.util.download
|
||||||
|
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.joinAll
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import me.rhunk.snapenhance.Constants
|
import me.rhunk.snapenhance.Constants
|
||||||
@ -19,6 +21,7 @@ object CdnDownloader {
|
|||||||
const val CF_ST_CDN_I = "https://cf-st.sc-cdn.net/i/"
|
const val CF_ST_CDN_I = "https://cf-st.sc-cdn.net/i/"
|
||||||
const val CF_ST_CDN_J = "https://cf-st.sc-cdn.net/j/"
|
const val CF_ST_CDN_J = "https://cf-st.sc-cdn.net/j/"
|
||||||
const val CF_ST_CDN_C = "https://cf-st.sc-cdn.net/c/"
|
const val CF_ST_CDN_C = "https://cf-st.sc-cdn.net/c/"
|
||||||
|
const val CF_ST_CDN_A = "https://cf-st.sc-cdn.net/a/"
|
||||||
const val CF_ST_CDN_AA = "https://cf-st.sc-cdn.net/aa/"
|
const val CF_ST_CDN_AA = "https://cf-st.sc-cdn.net/aa/"
|
||||||
|
|
||||||
private val keyCache: MutableMap<String, String> = mutableMapOf()
|
private val keyCache: MutableMap<String, String> = mutableMapOf()
|
||||||
@ -36,17 +39,16 @@ object CdnDownloader {
|
|||||||
var inputStream: InputStream? = null
|
var inputStream: InputStream? = null
|
||||||
|
|
||||||
endpoints.forEach {
|
endpoints.forEach {
|
||||||
launch {
|
launch(Dispatchers.IO) {
|
||||||
val url = it + key
|
val url = it + key
|
||||||
val result = queryRemoteContent(url)
|
queryRemoteContent(url)?.let { result ->
|
||||||
if (result != null) {
|
|
||||||
keyCache[key] = url
|
keyCache[key] = url
|
||||||
inputStream = result
|
inputStream = result
|
||||||
jobs.forEach { it.cancel() }
|
jobs.forEach { it.cancel() }
|
||||||
}
|
}
|
||||||
}.also { jobs.add(it) }
|
}.also { jobs.add(it) }
|
||||||
}
|
}
|
||||||
jobs.forEach { it.join() }
|
jobs.joinAll()
|
||||||
inputStream
|
inputStream
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,6 +77,7 @@ object CdnDownloader {
|
|||||||
CF_ST_CDN_I,
|
CF_ST_CDN_I,
|
||||||
CF_ST_CDN_C,
|
CF_ST_CDN_C,
|
||||||
CF_ST_CDN_J,
|
CF_ST_CDN_J,
|
||||||
|
CF_ST_CDN_A,
|
||||||
CF_ST_CDN_AA,
|
CF_ST_CDN_AA,
|
||||||
CF_ST_CDN_G,
|
CF_ST_CDN_G,
|
||||||
CF_ST_CDN_D
|
CF_ST_CDN_D
|
||||||
|
Loading…
x
Reference in New Issue
Block a user