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 {
|
Headers.build {
|
||||||
append(HttpHeaders.ContentType, value.mimeType)
|
append(HttpHeaders.ContentType, value.mimeType)
|
||||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||||
}
|
},
|
||||||
) {
|
block = value.file::input
|
||||||
value.file.asInput()
|
)
|
||||||
}
|
|
||||||
is FileId -> append(key, value.fileId)
|
is FileId -> append(key, value.fileId)
|
||||||
else -> append(key, value.toString())
|
else -> append(key, value.toString())
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,40 @@ 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
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Serializable
|
||||||
data class StorageFileInfo(
|
data class StorageFileInfo(
|
||||||
val contentType: String,
|
val contentType: String,
|
||||||
val fileName: 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}"
|
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(
|
data class StorageFile(
|
||||||
val storageFileInfo: StorageFileInfo,
|
val storageFileInfo: StorageFileInfo,
|
||||||
private val inputSource: () -> Input
|
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")
|
@Suppress("NOTHING_TO_INLINE")
|
||||||
@ -31,5 +52,8 @@ inline fun StorageFile(
|
|||||||
ByteReadPacket(bytes)
|
ByteReadPacket(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||||
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)
|
inline fun ByteArray.asStorageFile(fileName: String, mimeType: MimeType) = StorageFile(fileName, this, mimeType)
|
||||||
|
Loading…
Reference in New Issue
Block a user