diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt index ed440617ad..87cae741b3 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/bot/Ktor/base/MultipartRequestCallFactory.kt @@ -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()) } diff --git a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt index a5beeeb0ca..167f6b80b8 100644 --- a/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt +++ b/tgbotapi.core/src/commonMain/kotlin/dev/inmo/tgbotapi/utils/StorageFile.kt @@ -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)