mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
add MimeType
This commit is contained in:
parent
9747c8bff1
commit
9b16d5d82b
@ -55,6 +55,9 @@
|
|||||||
* Versions:
|
* Versions:
|
||||||
* Coroutines: `1.3.5` -> `1.3.6`
|
* Coroutines: `1.3.5` -> `1.3.6`
|
||||||
* Klock: `1.10.5` -> `1.11.1`
|
* Klock: `1.10.5` -> `1.11.1`
|
||||||
|
* `TelegramBotAPI`:
|
||||||
|
* Expected class `MimeType` was added
|
||||||
|
* Field `MimeTyped#mimeType` now typed by `MimeType` instead of `String`
|
||||||
|
|
||||||
### 0.27.1
|
### 0.27.1
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
package com.github.insanusmokrassar.TelegramBotAPI.CommonAbstracts
|
||||||
|
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
|
|
||||||
interface MimeTyped {
|
interface MimeTyped {
|
||||||
val mimeType: String? // TODO::replace by something like enum or interface
|
val mimeType: MimeType?
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.mimeTypeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.mimeTypeField
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ data class InlineQueryResultDocumentImpl(
|
|||||||
@SerialName(titleField)
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String,
|
override val mimeType: MimeType,
|
||||||
@SerialName(thumbUrlField)
|
@SerialName(thumbUrlField)
|
||||||
override val thumbUrl: String? = null,
|
override val thumbUrl: String? = null,
|
||||||
@SerialName(thumbWidthField)
|
@SerialName(thumbWidthField)
|
||||||
|
@ -8,6 +8,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.ParseMode
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.ParseMode.parseModeField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
import com.github.insanusmokrassar.TelegramBotAPI.types.buttons.InlineKeyboardMarkup
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.mimeTypeField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.mimeTypeField
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ data class InlineQueryResultVideoImpl(
|
|||||||
@SerialName(thumbUrlField)
|
@SerialName(thumbUrlField)
|
||||||
override val thumbUrl: String,
|
override val thumbUrl: String,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String,
|
override val mimeType: MimeType,
|
||||||
@SerialName(titleField)
|
@SerialName(titleField)
|
||||||
override val title: String,
|
override val title: String,
|
||||||
@SerialName(videoWidthField)
|
@SerialName(videoWidthField)
|
||||||
|
@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -20,7 +21,7 @@ data class AnimationFile(
|
|||||||
@SerialName(fileNameField)
|
@SerialName(fileNameField)
|
||||||
override val fileName: String? = null,
|
override val fileName: String? = null,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String? = null,
|
override val mimeType: MimeType? = null,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null
|
override val fileSize: Long? = null
|
||||||
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, CustomNamedMediaFile, SizedMediaFile
|
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, CustomNamedMediaFile, SizedMediaFile
|
||||||
|
@ -5,6 +5,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ data class AudioFile(
|
|||||||
override val performer: String? = null,
|
override val performer: String? = null,
|
||||||
override val title: String? = null,
|
override val title: String? = null,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String? = null,
|
override val mimeType: MimeType? = null,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null,
|
override val fileSize: Long? = null,
|
||||||
override val thumb: PhotoSize? = null
|
override val thumb: PhotoSize? = null
|
||||||
|
@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -17,7 +18,7 @@ data class DocumentFile(
|
|||||||
override val fileSize: Long? = null,
|
override val fileSize: Long? = null,
|
||||||
override val thumb: PhotoSize? = null,
|
override val thumb: PhotoSize? = null,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String? = null,
|
override val mimeType: MimeType? = null,
|
||||||
@SerialName(fileNameField)
|
@SerialName(fileNameField)
|
||||||
override val fileName: String? = null
|
override val fileName: String? = null
|
||||||
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile
|
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, CustomNamedMediaFile
|
||||||
|
@ -4,6 +4,7 @@ import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
|||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ data class VideoFile(
|
|||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
override val thumb: PhotoSize? = null,
|
override val thumb: PhotoSize? = null,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String? = null,
|
override val mimeType: MimeType? = null,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null
|
override val fileSize: Long? = null
|
||||||
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile
|
) : TelegramMediaFile, MimedMediaFile, ThumbedMediaFile, PlayableMediaFile, SizedMediaFile
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
package com.github.insanusmokrassar.TelegramBotAPI.types.files
|
||||||
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
import com.github.insanusmokrassar.TelegramBotAPI.requests.abstracts.FileId
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.FileUniqueId
|
import com.github.insanusmokrassar.TelegramBotAPI.types.*
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.fileUniqueIdField
|
|
||||||
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
import com.github.insanusmokrassar.TelegramBotAPI.types.files.abstracts.*
|
||||||
|
import com.github.insanusmokrassar.TelegramBotAPI.utils.MimeType
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
@ -13,9 +13,10 @@ data class VoiceFile(
|
|||||||
override val fileId: FileId,
|
override val fileId: FileId,
|
||||||
@SerialName(fileUniqueIdField)
|
@SerialName(fileUniqueIdField)
|
||||||
override val fileUniqueId: FileUniqueId,
|
override val fileUniqueId: FileUniqueId,
|
||||||
|
@SerialName(durationField)
|
||||||
override val duration: Long? = null,
|
override val duration: Long? = null,
|
||||||
@SerialName(mimeTypeField)
|
@SerialName(mimeTypeField)
|
||||||
override val mimeType: String? = null,
|
override val mimeType: MimeType? = null,
|
||||||
@SerialName(fileSizeField)
|
@SerialName(fileSizeField)
|
||||||
override val fileSize: Long? = null
|
override val fileSize: Long? = null
|
||||||
) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile
|
) : TelegramMediaFile, MimedMediaFile, PlayableMediaFile
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
|
@Serializable(MimeTypeSerializer::class)
|
||||||
|
expect class MimeType {
|
||||||
|
val raw: String
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializer(MimeType::class)
|
||||||
|
internal expect object MimeTypeSerializer : KSerializer<MimeType>
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
import org.w3c.dom.get
|
||||||
|
import kotlin.browser.window
|
||||||
|
|
||||||
|
private val mimesCache = mutableMapOf<String, MimeType>()
|
||||||
|
|
||||||
|
@Serializable(MimeTypeSerializer::class)
|
||||||
|
actual class MimeType(
|
||||||
|
actual val raw: String
|
||||||
|
) {
|
||||||
|
@Transient
|
||||||
|
val jsMimeType = window.navigator.mimeTypes[raw]
|
||||||
|
|
||||||
|
override fun toString(): String = raw
|
||||||
|
}
|
||||||
|
|
||||||
|
@Serializer(MimeType::class)
|
||||||
|
internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||||
|
override val descriptor: SerialDescriptor = PrimitiveDescriptor("mimeType", PrimitiveKind.STRING)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): MimeType {
|
||||||
|
val mimeType = decoder.decodeString()
|
||||||
|
return mimesCache.getOrPut(mimeType) {
|
||||||
|
MimeType(mimeType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: MimeType) {
|
||||||
|
encoder.encodeString(value.raw)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.github.insanusmokrassar.TelegramBotAPI.utils
|
||||||
|
|
||||||
|
import kotlinx.serialization.*
|
||||||
|
|
||||||
|
private val mimesCache = mutableMapOf<String, MimeType>()
|
||||||
|
|
||||||
|
@Serializable(MimeTypeSerializer::class)
|
||||||
|
actual class MimeType(
|
||||||
|
actual val raw: String
|
||||||
|
) : javax.activation.MimeType(raw)
|
||||||
|
|
||||||
|
@Serializer(MimeType::class)
|
||||||
|
internal actual object MimeTypeSerializer : KSerializer<MimeType> {
|
||||||
|
override val descriptor: SerialDescriptor = PrimitiveDescriptor("mimeType", PrimitiveKind.STRING)
|
||||||
|
|
||||||
|
override fun deserialize(decoder: Decoder): MimeType {
|
||||||
|
val mimeType = decoder.decodeString()
|
||||||
|
return mimesCache.getOrPut(mimeType) {
|
||||||
|
MimeType(mimeType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(encoder: Encoder, value: MimeType) {
|
||||||
|
encoder.encodeString(value.raw)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user