diff options
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/facebook/requests')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt | 19 | ||||
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/Images.kt | 17 |
2 files changed, 27 insertions, 9 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt index b5c2e4e9..692312a1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/requests/FbRequest.kt @@ -6,7 +6,10 @@ import com.pitchedapps.frost.rx.RxFlyweight import com.pitchedapps.frost.utils.L import io.reactivex.Single import io.reactivex.schedulers.Schedulers -import okhttp3.* +import okhttp3.Call +import okhttp3.FormBody +import okhttp3.OkHttpClient +import okhttp3.Request import okhttp3.logging.HttpLoggingInterceptor import org.apache.commons.text.StringEscapeUtils @@ -92,12 +95,16 @@ internal fun List<Pair<String, Any?>>.withEmptyData(vararg key: String): List<Pa return newList } -private fun String.requestBuilder() = Request.Builder() - .header("Cookie", this) - .header("User-Agent", USER_AGENT_BASIC) - .cacheControl(CacheControl.FORCE_NETWORK) +internal fun String?.requestBuilder(): Request.Builder { + val builder = Request.Builder() + .header("User-Agent", USER_AGENT_BASIC) + if (this != null) + builder.header("Cookie", this) +// .cacheControl(CacheControl.FORCE_NETWORK) + return builder +} -fun Request.Builder.call() = httpClient.newCall(build())!! +fun Request.Builder.call(): Call = httpClient.newCall(build()) fun String.getAuth(): RequestAuth { L.v { "Getting auth for ${hashCode()}" } 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 453400d3..8eeef08d 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 @@ -11,9 +11,8 @@ import com.bumptech.glide.load.model.MultiModelLoaderFactory import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target import com.bumptech.glide.signature.ObjectKey -import com.pitchedapps.frost.facebook.FB_IMAGE_ID_MATCHER -import com.pitchedapps.frost.facebook.FB_URL_BASE -import com.pitchedapps.frost.facebook.get +import com.pitchedapps.frost.facebook.* +import io.reactivex.Maybe import okhttp3.Call import okhttp3.Request import java.io.IOException @@ -27,6 +26,18 @@ fun RequestAuth.getFullSizedImage(fbid: Long) = frostRequest(::getJsonUrl) { get() } +val test: () -> InputStream? = { null } + +/** + * 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() + /** * Request loader for a potentially hd version of a url * In this case, each url may potentially return an id, |