Fixed unable to download files without extension

This commit is contained in:
tom5079
2021-12-21 19:12:37 +09:00
parent 8b2e388a81
commit 0c13ad6869

View File

@@ -68,10 +68,8 @@ class NetworkCache(context: Context) : DIAware {
private val activeFilesMutex = Mutex()
private val activeFiles = Collections.newSetFromMap(ConcurrentHashMap<String, Boolean>())
private fun urlToFilename(url: String): String {
val hash = sha256(url.toByteArray()).joinToString("") { "%02x".format(it) }
return "$hash.${url.takeLastWhile { it != '.' }}"
}
private fun urlToFilename(url: String): String =
sha256(url.toByteArray()).joinToString("") { "%02x".format(it) }
fun cleanup() = CoroutineScope(Dispatchers.IO).launch {
if (cacheDir.size() > CACHE_LIMIT)
@@ -160,6 +158,7 @@ class NetworkCache(context: Context) : DIAware {
progressFlow.emit(Float.POSITIVE_INFINITY)
}
}.onFailure {
logger.warning(it)
file.delete()
FirebaseCrashlytics.getInstance().recordException(it)
progressFlow.emit(Float.NEGATIVE_INFINITY)