diff options
author | Allan Wang <me@allanwang.ca> | 2019-01-03 23:58:46 -0500 |
---|---|---|
committer | Allan Wang <me@allanwang.ca> | 2019-01-03 23:58:46 -0500 |
commit | 04ef20177ca24b77ca207e14397766196425cb4e (patch) | |
tree | 6523039e02657daadb4e0f2a20f5f9cd3ad3344c /app/src/main | |
parent | a8c734070c67d84e10f617602467339f113521b4 (diff) | |
download | frost-04ef20177ca24b77ca207e14397766196425cb4e.tar.gz frost-04ef20177ca24b77ca207e14397766196425cb4e.tar.bz2 frost-04ef20177ca24b77ca207e14397766196425cb4e.zip |
Wrap full image url in try catch, resolves #1307
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt | 2 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt | 22 |
2 files changed, 16 insertions, 8 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt index 7735c034..f7dcf845 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/activities/ImageActivity.kt @@ -150,7 +150,7 @@ class ImageActivity : KauBaseActivity() { L.i { "Displaying image" } trueImageUrl = async(Dispatchers.IO) { val result = if (!imageUrl.isIndirectImageUrl) imageUrl - else cookie?.getFullSizedImageUrl(imageUrl)?.blockingGet() ?: imageUrl + else cookie?.getFullSizedImageUrl(imageUrl) ?: imageUrl if (result != imageUrl) L.v { "Launching with true url $result" } result diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt index 9e92c939..ee18e15e 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt @@ -32,8 +32,10 @@ import com.pitchedapps.frost.facebook.FB_REDIRECT_URL_MATCHER import com.pitchedapps.frost.facebook.FB_URL_BASE import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.facebook.get -import io.reactivex.Maybe +import com.pitchedapps.frost.utils.L +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import kotlinx.coroutines.withTimeout import okhttp3.Call import java.io.IOException @@ -50,12 +52,18 @@ fun RequestAuth.getFullSizedImage(fbid: Long) = frostRequest(::getJsonUrl) { /** * Attempts to get the fbcdn url of the supplied image redirect url */ -fun String.getFullSizedImageUrl(url: String): Maybe<String?> = Maybe.fromCallable { - val redirect = requestBuilder().url(url).get().call() - .execute().body()?.string() ?: return@fromCallable null - return@fromCallable FB_REDIRECT_URL_MATCHER.find(redirect)[1]?.formattedFbUrl - ?: return@fromCallable null -}.onErrorComplete() +suspend fun String.getFullSizedImageUrl(url: String, timeout: Long = 3000): String? = withContext(Dispatchers.IO) { + try { + withTimeout(timeout) { + val redirect = requestBuilder().url(url).get().call() + .execute().body()?.string() ?: return@withTimeout null + FB_REDIRECT_URL_MATCHER.find(redirect)[1]?.formattedFbUrl + } + } catch (e: Exception) { + L.e(e) { "Failed to load full size image url" } + null + } +} /** * Request loader for a potentially hd version of a url |