mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-29 10:02:42 +02:00
BugFix for invalid nip05 domain names crashing the app.
This commit is contained in:
@@ -18,7 +18,7 @@ class Nip05Verifier {
|
|||||||
val client = OkHttpClient.Builder().build()
|
val client = OkHttpClient.Builder().build()
|
||||||
|
|
||||||
fun assembleUrl(nip05address: String): String? {
|
fun assembleUrl(nip05address: String): String? {
|
||||||
val parts = nip05address.split("@")
|
val parts = nip05address.trim().split("@")
|
||||||
|
|
||||||
if (parts.size == 2) {
|
if (parts.size == 2) {
|
||||||
return "https://${parts[1]}/.well-known/nostr.json?name=${parts[0]}"
|
return "https://${parts[1]}/.well-known/nostr.json?name=${parts[0]}"
|
||||||
@@ -43,23 +43,27 @@ class Nip05Verifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
val request: Request = Request.Builder().url(url).build()
|
try {
|
||||||
|
val request: Request = Request.Builder().url(url).build()
|
||||||
|
|
||||||
client.newCall(request).enqueue(object : Callback {
|
client.newCall(request).enqueue(object : Callback {
|
||||||
override fun onResponse(call: Call, response: Response) {
|
override fun onResponse(call: Call, response: Response) {
|
||||||
response.use {
|
response.use {
|
||||||
if (it.isSuccessful)
|
if (it.isSuccessful)
|
||||||
onSuccess(it.body.string())
|
onSuccess(it.body.string())
|
||||||
else
|
else
|
||||||
onError("Could not resolve ${nip05}. Error: ${it.code}. Check if the server up and if the address ${nip05} is correct")
|
onError("Could not resolve ${nip05}. Error: ${it.code}. Check if the server up and if the address ${nip05} is correct")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onFailure(call: Call, e: java.io.IOException) {
|
override fun onFailure(call: Call, e: java.io.IOException) {
|
||||||
onError("Could not resolve ${url}. Check if the server up and if the address ${nip05} is correct")
|
onError("Could not resolve ${url}. Check if the server up and if the address ${nip05} is correct")
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
} catch (e: java.lang.Exception) {
|
||||||
|
onError("Could not resolve '${url}': ${e.message}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user