Removing more warnings

This commit is contained in:
Vitor Pamplona
2026-03-28 16:30:00 -04:00
parent 3c01c17d59
commit 20eb95ae57
11 changed files with 33 additions and 12 deletions
@@ -21,7 +21,7 @@
package com.vitorpamplona.amethyst.commons.preview
import androidx.compose.runtime.Immutable
import java.net.URL
import java.net.URI
@Immutable
class UrlInfoItem(
@@ -31,10 +31,16 @@ class UrlInfoItem(
val image: String = "",
val mimeType: String,
) {
val verifiedUrl = runCatching { URL(url) }.getOrNull()
val verifiedUrl = runCatching { URI(url).toURL() }.getOrNull()
val imageUrlFullPath =
if (image.startsWith("/")) {
URL(verifiedUrl, image).toString()
runCatching {
verifiedUrl
?.toURI()
?.resolve(image)
?.toURL()
?.toString()
}.getOrNull() ?: image
} else {
image
}
@@ -40,8 +40,8 @@ import kotlinx.collections.immutable.toImmutableList
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.collections.immutable.toPersistentList
import java.net.MalformedURLException
import java.net.URI
import java.net.URISyntaxException
import java.net.URL
import kotlin.coroutines.cancellation.CancellationException
class RichTextParser {
@@ -424,12 +424,18 @@ class RichTextParser {
fun isValidURL(url: String?): Boolean =
try {
URL(url).toURI()
true
if (url != null) {
URI(url).toURL()
true
} else {
false
}
} catch (e: MalformedURLException) {
false
} catch (e: URISyntaxException) {
false
} catch (e: IllegalArgumentException) {
false
}
fun parseImageOrVideo(fullUrl: String): BaseMediaContent {