mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-11-10 18:56:55 +01:00
Adds a check for the main thread when pulling opengraph tags.
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
package com.vitorpamplona.amethyst.service.previews
|
package com.vitorpamplona.amethyst.service.previews
|
||||||
|
|
||||||
import com.vitorpamplona.amethyst.service.HttpClientManager
|
import com.vitorpamplona.amethyst.service.HttpClientManager
|
||||||
|
import com.vitorpamplona.amethyst.service.checkNotInMainThread
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import okhttp3.MediaType
|
import okhttp3.MediaType
|
||||||
@@ -91,6 +92,7 @@ suspend fun getDocument(
|
|||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val request: Request = Request.Builder().url(url).get().build()
|
val request: Request = Request.Builder().url(url).get().build()
|
||||||
HttpClientManager.getHttpClient().newCall(request).execute().use {
|
HttpClientManager.getHttpClient().newCall(request).execute().use {
|
||||||
|
checkNotInMainThread()
|
||||||
if (it.isSuccessful) {
|
if (it.isSuccessful) {
|
||||||
val mimeType =
|
val mimeType =
|
||||||
it.headers.get("Content-Type")?.toMediaType()
|
it.headers.get("Content-Type")?.toMediaType()
|
||||||
|
|||||||
Reference in New Issue
Block a user