2025-02-21 14:44:48 +03:00
|
|
|
/*
|
2025-02-22 18:45:55 +03:00
|
|
|
* Created by sweetbread on 22.02.2025, 17:28
|
2025-02-21 14:44:48 +03:00
|
|
|
* Copyright (c) 2025. All rights reserved.
|
2025-02-22 18:45:55 +03:00
|
|
|
* Last modified 22.02.2025, 17:28
|
2025-02-21 14:44:48 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package ru.risdeveau.pixeldragon.api
|
|
|
|
|
|
|
|
|
|
import io.ktor.client.request.get
|
|
|
|
|
import io.ktor.client.statement.bodyAsText
|
|
|
|
|
import org.json.JSONException
|
|
|
|
|
import org.json.JSONObject
|
|
|
|
|
import ru.risdeveau.pixeldragon.client
|
2025-02-22 18:45:55 +03:00
|
|
|
import ru.risdeveau.pixeldragon.homeserver
|
2025-02-21 14:44:48 +03:00
|
|
|
|
|
|
|
|
suspend fun isMatrixServer(url: String): Boolean {
|
|
|
|
|
val r = try { client.get("https://$url/.well-known/matrix/client") }
|
|
|
|
|
catch (_: Exception) { return false }
|
|
|
|
|
|
|
|
|
|
try { JSONObject(r.bodyAsText()) }
|
|
|
|
|
catch (_: JSONException) { return false }
|
|
|
|
|
|
|
|
|
|
return true
|
2025-02-22 18:45:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun mxcToUrl(mxc: String): String {
|
|
|
|
|
val pattern = Regex("mxc://([-a-zA-Z0-9@:%._+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6})/([a-zA-Z]+)")
|
|
|
|
|
val match = pattern.find(mxc)
|
|
|
|
|
|
|
|
|
|
return "https://$homeserver/_matrix/client/v1/media/download/${match?.groupValues[1]}/${match?.groupValues[2]}"
|
2025-02-21 14:44:48 +03:00
|
|
|
}
|