aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-08-06 00:49:58 -0700
committerAllan Wang <me@allanwang.ca>2019-08-06 00:49:58 -0700
commit55bf3e4b5b4af5baa3c230ca82f74988608971a3 (patch)
tree3db856e037b70257aaef19e34db6b0856bda6412 /app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt
parent99953f087f2c363dad05ae3f86b5bcba22484e43 (diff)
downloadfrost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.tar.gz
frost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.tar.bz2
frost-55bf3e4b5b4af5baa3c230ca82f74988608971a3.zip
Format kotlin
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt28
1 files changed, 16 insertions, 12 deletions
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 36dff6ff..1b5e8b99 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
@@ -52,18 +52,19 @@ fun RequestAuth.getFullSizedImage(fbid: Long) = frostRequest(::getJsonUrl) {
/**
* Attempts to get the fbcdn url of the supplied image redirect url
*/
-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
+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
}
- } catch (e: Exception) {
- L.e(e) { "Failed to load full size image url" }
- null
}
-}
/**
* Request loader for a potentially hd version of a url
@@ -135,7 +136,8 @@ class HdImageFetcher(private val model: HdImageMaybe) : DataFetcher<InputStream>
withTimeout(20000L) {
val auth = fbAuth.fetch(model.cookie).await()
if (cancelled) throw RuntimeException("Cancelled")
- val url = auth.getFullSizedImage(model.id).invoke() ?: throw RuntimeException("Null url")
+ val url = auth.getFullSizedImage(model.id).invoke()
+ ?: throw RuntimeException("Null url")
if (cancelled) throw RuntimeException("Cancelled")
if (!url.contains("png") && !url.contains("jpg")) throw RuntimeException("Invalid format")
urlCall?.execute()?.body()?.byteStream()
@@ -145,7 +147,9 @@ class HdImageFetcher(private val model: HdImageMaybe) : DataFetcher<InputStream>
if (result.isSuccess)
callback.onDataReady(result.getOrNull())
else
- callback.onLoadFailed(result.exceptionOrNull() as? Exception ?: RuntimeException("Failed"))
+ callback.onLoadFailed(
+ result.exceptionOrNull() as? Exception ?: RuntimeException("Failed")
+ )
}
override fun cleanup() {