1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 19:48:43 +00:00

fix ending of host url in TelegramAPIUrlsKeeper

This commit is contained in:
InsanusMokrassar 2020-11-17 13:18:11 +06:00
parent ec74111a9d
commit bc1b7c3f25
2 changed files with 22 additions and 2 deletions

View File

@ -5,6 +5,8 @@
* `Common`: * `Common`:
* `Version`: * `Version`:
* `MicroUtils`: `0.4.0` -> `0.4.1` * `MicroUtils`: `0.4.0` -> `0.4.1`
* `Core`:
* `TelegramAPIUrlsKeeper` will fix ending of host url since this version
## 0.30.6 ## 0.30.6

View File

@ -2,10 +2,28 @@ package dev.inmo.tgbotapi.utils
const val telegramBotAPIDefaultUrl = "https://api.telegram.org" const val telegramBotAPIDefaultUrl = "https://api.telegram.org"
private inline val String.withoutLastSlash: String
get() {
var correctedUrl = this
while (true) {
val withoutSuffix = correctedUrl.removeSuffix("/")
if (withoutSuffix == correctedUrl) {
return correctedUrl
}
correctedUrl = withoutSuffix
}
}
class TelegramAPIUrlsKeeper( class TelegramAPIUrlsKeeper(
token: String, token: String,
hostUrl: String = telegramBotAPIDefaultUrl hostUrl: String = telegramBotAPIDefaultUrl
) { ) {
val commonAPIUrl = "$hostUrl/bot$token" val commonAPIUrl: String
val fileBaseUrl = "$hostUrl/file/bot$token" val fileBaseUrl: String
init {
val correctedHost = hostUrl.withoutLastSlash
commonAPIUrl = "$correctedHost/bot$token"
fileBaseUrl = "$correctedHost/file/bot$token"
}
} }