mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 16:23:48 +00:00
StorageFile factories
This commit is contained in:
parent
1cf7ae7438
commit
1e6b0381ee
@ -79,6 +79,7 @@
|
||||
`textSources` list
|
||||
* New dsl for creating of `TextSource` lists
|
||||
* Built-in `handleSafely` and `ExceptionHandler` is deprecated
|
||||
* New common factories for `StorageFile`
|
||||
* `API`:
|
||||
* Extensions `TelegramBot#pinChatMessage` now support any `Chat` and `Message`s from any `Chat`
|
||||
* New extensions `TelegramBot#unpinAllChatMessages`
|
||||
|
@ -1,6 +1,7 @@
|
||||
package dev.inmo.tgbotapi.utils
|
||||
|
||||
import com.benasher44.uuid.uuid4
|
||||
import io.ktor.utils.io.core.ByteReadPacket
|
||||
import io.ktor.utils.io.core.Input
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@ -18,3 +19,17 @@ data class StorageFile(
|
||||
) {
|
||||
fun asInput() = inputSource()
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun StorageFile(
|
||||
fileName: String,
|
||||
bytes: ByteArray,
|
||||
mimeType: MimeType
|
||||
) = StorageFile(
|
||||
StorageFileInfo(mimeType.raw, fileName)
|
||||
) {
|
||||
ByteReadPacket(bytes)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)
|
||||
|
@ -1,7 +1,9 @@
|
||||
package dev.inmo.tgbotapi.requests.abstracts
|
||||
|
||||
import dev.inmo.tgbotapi.utils.MimeType
|
||||
import dev.inmo.tgbotapi.utils.StorageFile
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
|
||||
fun File.toInputFile() = if (exists()) {
|
||||
MultipartFile(
|
||||
|
@ -2,6 +2,7 @@ package dev.inmo.tgbotapi.utils
|
||||
|
||||
import io.ktor.utils.io.streams.asInput
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.nio.file.Files
|
||||
|
||||
fun StorageFile(
|
||||
|
Loading…
Reference in New Issue
Block a user