mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 03:28:44 +00:00
files downloading extensions in utils
This commit is contained in:
parent
0472e35752
commit
fd022742aa
@ -36,6 +36,9 @@
|
||||
* `replyTo`
|
||||
* `chat`
|
||||
* `createResend` (several extensions)
|
||||
* Several extensions for downloading of files:
|
||||
* `HttpClient#loadFile`
|
||||
* `PathedFile#download`
|
||||
|
||||
## 0.27.0
|
||||
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user