mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-11-16 03:50:24 +00:00
add fileLinkUrlMapper to all callers of TelegramAPIUrlsKeeper constructors
This commit is contained in:
@@ -53,11 +53,19 @@ inline fun telegramBot(
|
||||
/**
|
||||
* Shortcut for [telegramBot]
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun telegramBot(
|
||||
fun telegramBot(
|
||||
token: String,
|
||||
apiUrl: String = telegramBotAPIDefaultUrl,
|
||||
testServer: Boolean = false,
|
||||
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" },
|
||||
builder: KtorRequestsExecutorBuilder.() -> Unit = {}
|
||||
): TelegramBot = telegramBot(TelegramAPIUrlsKeeper(token, testServer, apiUrl), builder)
|
||||
): TelegramBot = telegramBot(
|
||||
telegramAPIUrlsKeeper = TelegramAPIUrlsKeeper(
|
||||
token = token,
|
||||
testServer = testServer,
|
||||
hostUrl = apiUrl,
|
||||
fileLinkUrlMapper = fileLinkUrlMapper
|
||||
),
|
||||
builder = builder
|
||||
)
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ import korlibs.crypto.*
|
||||
import io.ktor.http.decodeURLQueryComponent
|
||||
import io.ktor.utils.io.core.toByteArray
|
||||
|
||||
const val telegramBotAPIDefaultUrl = "https://api.telegram.org"
|
||||
|
||||
private inline val String.withoutLastSlash: String
|
||||
get() {
|
||||
var correctedUrl = this
|
||||
@@ -33,10 +31,16 @@ class TelegramAPIUrlsKeeper(
|
||||
val commonAPIUrl: String
|
||||
val fileBaseUrl: String
|
||||
|
||||
constructor(token: String, testServer: Boolean, hostUrl: String = telegramBotAPIDefaultUrl) : this(
|
||||
token,
|
||||
hostUrl,
|
||||
"/test".takeIf { testServer } ?: ""
|
||||
constructor(
|
||||
token: String,
|
||||
testServer: Boolean,
|
||||
hostUrl: String = telegramBotAPIDefaultUrl,
|
||||
fileLinkUrlMapper: TelegramAPIUrlsKeeper.(String) -> String = { "${fileBaseUrl}/$it" }
|
||||
) : this(
|
||||
token = token,
|
||||
hostUrl = hostUrl,
|
||||
urlsSuffixes = "/test".takeIf { testServer } ?: "",
|
||||
fileLinkUrlMapper = fileLinkUrlMapper
|
||||
)
|
||||
|
||||
init {
|
||||
@@ -61,4 +65,10 @@ class TelegramAPIUrlsKeeper(
|
||||
|
||||
return HMAC.hmacSHA256(webAppDataSecretKeyHash.bytes, preparedData.toByteArray()).hexLower == hash.lowercase()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val DEFAULT_URL = "https://api.telegram.org"
|
||||
}
|
||||
}
|
||||
|
||||
const val telegramBotAPIDefaultUrl = TelegramAPIUrlsKeeper.DEFAULT_URL
|
||||
|
||||
Reference in New Issue
Block a user