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