mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2025-09-15 21:29:25 +00:00
remove mime types from requests
This commit is contained in:
@@ -24,7 +24,6 @@ class MultipartRequestCallFactory : AbstractRequestCallFactory() {
|
||||
is MultipartFile -> appendInput(
|
||||
key,
|
||||
Headers.build {
|
||||
append(HttpHeaders.ContentType, value.mimeType)
|
||||
append(HttpHeaders.ContentDisposition, "filename=${value.fileId}")
|
||||
},
|
||||
block = value.file::input
|
||||
|
@@ -48,29 +48,30 @@ object InputFileSerializer : KSerializer<InputFile> {
|
||||
@Serializable(InputFileSerializer::class)
|
||||
data class MultipartFile (
|
||||
val file: StorageFile,
|
||||
val mimeType: String = file.storageFileInfo.contentType,
|
||||
val filename: String = file.storageFileInfo.fileName
|
||||
) : InputFile() {
|
||||
override val fileId: String = file.storageFileInfo.generateCustomName()
|
||||
|
||||
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||
constructor(file: StorageFile, mimeType: String, filename: String): this(file, filename)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
inline fun StorageFile.asMultipartFile() = MultipartFile(this)
|
||||
|
||||
@Deprecated("This method is redundant. Use asMultipartFile without mime type")
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
inline fun ByteArray.asMultipartFile(
|
||||
fileName: String,
|
||||
mimeType: MimeType
|
||||
) = MultipartFile(asStorageFile(fileName, mimeType))
|
||||
) = MultipartFile(asStorageFile(fileName))
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
suspend inline fun ByteReadChannel.asMultipartFile(
|
||||
fileName: String,
|
||||
mimeType: MimeType
|
||||
) = MultipartFile(asStorageFile(fileName, mimeType))
|
||||
fileName: String
|
||||
) = MultipartFile(asStorageFile(fileName))
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
suspend inline fun ByteReadChannelAllocator.asMultipartFile(
|
||||
fileName: String,
|
||||
mimeType: MimeType
|
||||
) = this.invoke().asMultipartFile(fileName, mimeType)
|
||||
fileName: String
|
||||
) = this.invoke().asMultipartFile(fileName)
|
||||
|
@@ -14,9 +14,14 @@ import kotlinx.serialization.Serializable
|
||||
*/
|
||||
@Serializable
|
||||
data class StorageFileInfo(
|
||||
val contentType: String,
|
||||
val fileName: String
|
||||
) {
|
||||
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||
constructor(
|
||||
contentType: String,
|
||||
fileName: String
|
||||
): this(fileName)
|
||||
|
||||
/**
|
||||
* This methods is required for random generation of name for keeping warranties about unique file name
|
||||
*/
|
||||
@@ -40,13 +45,24 @@ data class StorageFile(
|
||||
get() = inputSource()
|
||||
}
|
||||
|
||||
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun StorageFile(
|
||||
fileName: String,
|
||||
bytes: ByteArray,
|
||||
mimeType: MimeType
|
||||
) = StorageFile(
|
||||
StorageFileInfo(mimeType.raw, fileName)
|
||||
StorageFileInfo(fileName)
|
||||
) {
|
||||
ByteReadPacket(bytes)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
inline fun StorageFile(
|
||||
fileName: String,
|
||||
bytes: ByteArray
|
||||
) = StorageFile(
|
||||
StorageFileInfo(fileName)
|
||||
) {
|
||||
ByteReadPacket(bytes)
|
||||
}
|
||||
@@ -54,27 +70,30 @@ inline fun StorageFile(
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
suspend inline fun StorageFile(
|
||||
fileName: String,
|
||||
byteReadChannel: ByteReadChannel,
|
||||
mimeType: MimeType
|
||||
byteReadChannel: ByteReadChannel
|
||||
) = StorageFile(
|
||||
StorageFileInfo(mimeType.raw, fileName),
|
||||
StorageFileInfo(fileName),
|
||||
byteReadChannel.asInput().let { { it } }
|
||||
)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
inline fun ByteArray.asStorageFile(
|
||||
fileName: String
|
||||
) = StorageFile(fileName, this)
|
||||
|
||||
@Deprecated("This constructor is redundant. Use constructor without mime type")
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
inline fun ByteArray.asStorageFile(
|
||||
fileName: String,
|
||||
mimeType: MimeType
|
||||
) = StorageFile(fileName, this, mimeType)
|
||||
) = asStorageFile(fileName)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
suspend inline fun ByteReadChannel.asStorageFile(
|
||||
fileName: String,
|
||||
mimeType: MimeType
|
||||
) = StorageFile(fileName, this, mimeType)
|
||||
fileName: String
|
||||
) = StorageFile(fileName, this)
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE", "unused")
|
||||
suspend inline fun ByteReadChannelAllocator.asStorageFile(
|
||||
fileName: String,
|
||||
mimeType: MimeType
|
||||
) = this.invoke().asStorageFile(fileName, mimeType)
|
||||
fileName: String
|
||||
) = this.invoke().asStorageFile(fileName)
|
||||
|
@@ -7,10 +7,7 @@ import java.nio.file.Files
|
||||
fun StorageFile(
|
||||
file: File
|
||||
) = StorageFile(
|
||||
StorageFileInfo(
|
||||
Files.probeContentType(file.toPath()),
|
||||
file.name
|
||||
)
|
||||
StorageFileInfo(file.name)
|
||||
) {
|
||||
file.inputStream().asInput()
|
||||
}
|
||||
|
Reference in New Issue
Block a user