mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
several refactoring things and docs appending
This commit is contained in:
parent
a882a212c2
commit
7aa3ff180e
@ -25,10 +25,9 @@ object MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
}
|
||||
) {
|
||||
value.file.asInput()
|
||||
}
|
||||
},
|
||||
block = value.file::input
|
||||
)
|
||||
is FileId -> append(key, value.fileId)
|
||||
else -> append(key, value.toString())
|
||||
}
|
||||
|
@ -5,19 +5,40 @@ import io.ktor.utils.io.core.ByteReadPacket
|
||||
import io.ktor.utils.io.core.Input
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* Information about file for [StorageFile]
|
||||
*
|
||||
* @param contentType Raw type like "application/json"
|
||||
* @param fileName This filename will be used in telegram system as name of file
|
||||
*/
|
||||
@Serializable
|
||||
data class StorageFileInfo(
|
||||
val contentType: String,
|
||||
val fileName: String
|
||||
) {
|
||||
/**
|
||||
* This methods is required for random generation of name for keeping warranties about unique file name
|
||||
*/
|
||||
fun generateCustomName() = "${uuid4()}.${fileName.fileExtension}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains info about file, which potentially can be sent to telegram system.
|
||||
*
|
||||
* @param storageFileInfo Information about this file
|
||||
* @param inputSource Lambda which able to allocate [Input] for uploading/manipulating data
|
||||
*
|
||||
* @see StorageFileInfo
|
||||
* @see asStorageFile
|
||||
*/
|
||||
data class StorageFile(
|
||||
val storageFileInfo: StorageFileInfo,
|
||||
private val inputSource: () -> Input
|
||||
) {
|
||||
fun asInput() = inputSource()
|
||||
val input: Input
|
||||
get() = inputSource()
|
||||
@Deprecated("This method will be fully replaced with input property", ReplaceWith("input"))
|
||||
fun asInput() = input
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
@ -31,5 +52,8 @@ inline fun StorageFile(
|
||||
ByteReadPacket(bytes)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)
|
||||
|
Loading…
Reference in New Issue
Block a user