add mimetypes

This commit is contained in:
InsanusMokrassar 2020-09-26 21:57:55 +06:00
parent 6f46413a90
commit 56fd480542
8 changed files with 2198 additions and 8 deletions

6
mime_types/build.gradle Normal file
View File

@ -0,0 +1,6 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
apply from: "$mppProjectWithSerializationPresetPath"

View File

@ -0,0 +1,31 @@
package dev.inmo.micro_utils.mime_types
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializer
import kotlinx.serialization.descriptors.*
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
private val mimesCache = mutableMapOf<String, MimeType>().also {
knownMimeTypes.forEach { mimeType -> it[mimeType.raw] = mimeType }
}
fun mimeType(raw: String) = mimesCache.getOrPut(raw) {
parseMimeType(raw)
}
internal fun parseMimeType(raw: String): MimeType = CustomMimeType(raw)
@Serializer(MimeType::class)
object MimeTypeSerializer : KSerializer<MimeType> {
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("mimeType", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): MimeType {
val mimeType = decoder.decodeString()
return mimeType(mimeType)
}
override fun serialize(encoder: Encoder, value: MimeType) {
encoder.encodeString(value.raw)
}
}

View File

@ -1,4 +1,3 @@
package dev.inmo.micro_utils.repos package dev.inmo.micro_utils.repos
interface Repo { interface Repo
}

View File

@ -4,10 +4,10 @@ import kotlinx.coroutines.channels.Channel
abstract class AbstractExposedCRUDRepo<ObjectType, IdType, InputValueType>( abstract class AbstractExposedCRUDRepo<ObjectType, IdType, InputValueType>(
flowsChannelsSize: Int = Channel.BUFFERED, flowsChannelsSize: Int = Channel.BUFFERED,
databaseName: String = "" tableName: String = ""
) : ) :
AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>( AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
flowsChannelsSize, flowsChannelsSize,
databaseName tableName
), ),
ExposedCRUDRepo<ObjectType, IdType> ExposedCRUDRepo<ObjectType, IdType>

View File

@ -12,9 +12,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>( abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
flowsChannelsSize: Int = 64, flowsChannelsSize: Int = 64,
databaseName: String = "" tableName: String = ""
) : ) :
AbstractExposedReadCRUDRepo<ObjectType, IdType>(databaseName), AbstractExposedReadCRUDRepo<ObjectType, IdType>(tableName),
ExposedCRUDRepo<ObjectType, IdType>, ExposedCRUDRepo<ObjectType, IdType>,
WriteStandardCRUDRepo<ObjectType, IdType, InputValueType> WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>
{ {
@ -102,4 +102,4 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
} }
} }
} }
} }

View File

@ -1,8 +1,9 @@
package dev.inmo.micro_utils.repos.exposed package dev.inmo.micro_utils.repos.exposed
import dev.inmo.micro_utils.repos.Repo
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
interface ExposedCRUDRepo<ObjectType, IdType> { interface ExposedCRUDRepo<ObjectType, IdType> : Repo {
val database: Database val database: Database
val ResultRow.asObject: ObjectType val ResultRow.asObject: ObjectType

View File

@ -5,6 +5,7 @@ String[] includes = [
":pagination:exposed", ":pagination:exposed",
":pagination:ktor:common", ":pagination:ktor:common",
":pagination:ktor:server", ":pagination:ktor:server",
":mime_types",
":repos:common", ":repos:common",
":repos:exposed", ":repos:exposed",
":repos:ktor:client", ":repos:ktor:client",