diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fbeafba4..c30b921637 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,9 @@ * `replyTo` * `chat` * `createResend` (several extensions) + * Several extensions for downloading of files: + * `HttpClient#loadFile` + * `PathedFile#download` ## 0.27.0 diff --git a/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/extensions/FilesDownloading.kt b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/extensions/FilesDownloading.kt new file mode 100644 index 0000000000..d1f8208284 --- /dev/null +++ b/TelegramBotAPI-extensions-utils/src/commonMain/kotlin/com/github/insanusmokrassar/TelegramBotAPI/extensions/utils/extensions/FilesDownloading.kt @@ -0,0 +1,21 @@ +package com.github.insanusmokrassar.TelegramBotAPI.extensions.utils.extensions + +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("${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)