mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
fix ending of host url in TelegramAPIUrlsKeeper
This commit is contained in:
parent
ec74111a9d
commit
bc1b7c3f25
@ -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
|
||||||
|
|
||||||
|
@ -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"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user