1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 08:13:47 +00:00
This commit is contained in:
InsanusMokrassar 2021-08-10 16:54:15 +06:00
parent f42cf78969
commit f7d2c8bbd2
2 changed files with 25 additions and 2 deletions

View File

@ -4,6 +4,8 @@
* `Core`:
* Several new extensions `ByteReadChannel#asStorageFile` and `ByteReadChannelAllocator#asStorageFile`
* Several new extensions `ByteArray#asMultipartFile`, `ByteReadChannel#asMultipartFile` and
`ByteReadChannelAllocator#asMultipartFile`
* `API`:
* New extensions `TelegramBot#downloadFile` for writing of incoming bytes to the file
* New extensions `TelegramBot#downloadFileStream` and `TelegramBot#downloadFileStreamAllocator` for getting of input

View File

@ -1,7 +1,7 @@
package dev.inmo.tgbotapi.requests.abstracts
import dev.inmo.tgbotapi.utils.RiskFeature
import dev.inmo.tgbotapi.utils.StorageFile
import dev.inmo.tgbotapi.utils.*
import io.ktor.utils.io.ByteReadChannel
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.descriptors.*
@ -42,6 +42,8 @@ object InputFileSerializer : KSerializer<InputFile> {
// TODO:: add checks for files size
/**
* Contains info about file for sending
*
* @see asMultipartFile
*/
@Serializable(InputFileSerializer::class)
data class MultipartFile (
@ -51,3 +53,22 @@ data class MultipartFile (
) : InputFile() {
override val fileId: String = file.storageFileInfo.generateCustomName()
}
@Suppress("NOTHING_TO_INLINE", "unused")
inline fun ByteArray.asMultipartFile(
fileName: String,
mimeType: MimeType
) = MultipartFile(asStorageFile(fileName, mimeType))
@Suppress("NOTHING_TO_INLINE", "unused")
suspend inline fun ByteReadChannel.asMultipartFile(
fileName: String,
mimeType: MimeType
) = MultipartFile(asStorageFile(fileName, mimeType))
@Suppress("NOTHING_TO_INLINE", "unused")
suspend inline fun ByteReadChannelAllocator.asMultipartFile(
fileName: String,
mimeType: MimeType
) = this.invoke().asMultipartFile(fileName, mimeType)