files downloading extensions in utils

This commit is contained in:
InsanusMokrassar 2020-08-23 23:37:29 +06:00
parent 0472e35752
commit fd022742aa
2 changed files with 24 additions and 0 deletions

View File

@ -36,6 +36,9 @@
* `replyTo`
* `chat`
* `createResend` (several extensions)
* Several extensions for downloading of files:
* `HttpClient#loadFile`
* `PathedFile#download`
## 0.27.0

View File

@ -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<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)