1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-06-03 00:15:27 +00:00
tgbotapi/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/dev/inmo/tgbotapi/extensions/utils/extensions/FilesDownloading.kt

22 lines
786 B
Kotlin
Raw Normal View History

package dev.inmo.tgbotapi.extensions.utils.extensions
2020-08-23 17:37:29 +00:00
import com.github.insanusmokrassar.TelegramBotAPI.types.files.PathedFile
import com.github.insanusmokrassar.TelegramBotAPI.utils.TelegramAPIUrlsKeeper
import io.ktor.client.HttpClient
import io.ktor.client.request.get
suspend fun HttpClient.loadFile(
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
filePath: String
) = get<ByteArray>("${telegramAPIUrlsKeeper.fileBaseUrl}/$filePath")
suspend fun HttpClient.loadFile(
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
pathedFile: PathedFile
) = loadFile(telegramAPIUrlsKeeper, pathedFile.filePath)
suspend fun PathedFile.download(
telegramAPIUrlsKeeper: TelegramAPIUrlsKeeper,
client: HttpClient = HttpClient()
) = client.loadFile(telegramAPIUrlsKeeper, this)