mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-12-22 16:47:13 +00:00
fix ending of host url in TelegramAPIUrlsKeeper
This commit is contained in:
parent
ec74111a9d
commit
bc1b7c3f25
@ -5,6 +5,8 @@
|
||||
* `Common`:
|
||||
* `Version`:
|
||||
* `MicroUtils`: `0.4.0` -> `0.4.1`
|
||||
* `Core`:
|
||||
* `TelegramAPIUrlsKeeper` will fix ending of host url since this version
|
||||
|
||||
## 0.30.6
|
||||
|
||||
|
@ -2,10 +2,28 @@ package dev.inmo.tgbotapi.utils
|
||||
|
||||
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(
|
||||
token: String,
|
||||
hostUrl: String = telegramBotAPIDefaultUrl
|
||||
) {
|
||||
val commonAPIUrl = "$hostUrl/bot$token"
|
||||
val fileBaseUrl = "$hostUrl/file/bot$token"
|
||||
val commonAPIUrl: String
|
||||
val fileBaseUrl: String
|
||||
|
||||
init {
|
||||
val correctedHost = hostUrl.withoutLastSlash
|
||||
commonAPIUrl = "$correctedHost/bot$token"
|
||||
fileBaseUrl = "$correctedHost/file/bot$token"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user