1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-29 04:47:48 +00:00
tgbotapi/src/main/kotlin/com/github/insanusmokrassar/TelegramBotAPI/types/files/PathedFile.kt

33 lines
1.2 KiB
Kotlin
Raw Normal View History

2018-12-26 08:07:24 +00:00
package com.github.insanusmokrassar.TelegramBotAPI.types.files
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
2019-01-17 02:43:51 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
2019-07-25 08:25:18 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
2019-04-13 02:21:19 +00:00
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
2018-12-26 08:07:24 +00:00
@Serializable
data class PathedFile(
@SerialName(fileIdField)
override val fileId: FileId,
@SerialName(filePathField)
val filePath: String,
@SerialName(fileSizeField)
override val fileSize: Long? = null
): TelegramMediaFile
2019-07-25 08:25:18 +00:00
fun TelegramAPIUrlsKeeper.resolveFileURL(file: PathedFile): String = "$fileBaseUrl/${file.filePath}"
inline fun PathedFile.fullUrl(keeper: TelegramAPIUrlsKeeper): String = keeper.resolveFileURL(this)
@Deprecated("Deprecated due to old API", ReplaceWith("fullUrl(telegramApiUrlsKeeper)"))
2018-12-26 08:07:24 +00:00
fun PathedFile.makeFileUrl(
botToken: String,
apiHost: String = "https://api.telegram.org"
) = "${downloadingFilesBaseUrl(botToken, apiHost)}/$filePath"
2019-07-25 08:25:18 +00:00
@Deprecated("Deprecated due to old API", ReplaceWith("telegramApiUrlsKeeper.fileBaseUrl"))
2018-12-26 08:07:24 +00:00
fun downloadingFilesBaseUrl(
botToken: String,
apiHost: String
) = "$apiHost/file/bot$botToken"