mirror of
				https://github.com/InsanusMokrassar/MicroUtils.git
				synced 2025-11-03 21:51:59 +00:00 
			
		
		
		
	add mimetypes
This commit is contained in:
		
							
								
								
									
										6
									
								
								mime_types/build.gradle
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								mime_types/build.gradle
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
plugins {
 | 
			
		||||
    id "org.jetbrains.kotlin.multiplatform"
 | 
			
		||||
    id "org.jetbrains.kotlin.plugin.serialization"
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
apply from: "$mppProjectWithSerializationPresetPath"
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -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)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,3 @@
 | 
			
		||||
package dev.inmo.micro_utils.repos
 | 
			
		||||
 | 
			
		||||
interface Repo {
 | 
			
		||||
}
 | 
			
		||||
interface Repo
 | 
			
		||||
 
 | 
			
		||||
@@ -4,10 +4,10 @@ import kotlinx.coroutines.channels.Channel
 | 
			
		||||
 | 
			
		||||
abstract class AbstractExposedCRUDRepo<ObjectType, IdType, InputValueType>(
 | 
			
		||||
    flowsChannelsSize: Int = Channel.BUFFERED,
 | 
			
		||||
    databaseName: String = ""
 | 
			
		||||
    tableName: String = ""
 | 
			
		||||
) :
 | 
			
		||||
    AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
 | 
			
		||||
        flowsChannelsSize,
 | 
			
		||||
        databaseName
 | 
			
		||||
        tableName
 | 
			
		||||
    ),
 | 
			
		||||
    ExposedCRUDRepo<ObjectType, IdType>
 | 
			
		||||
 
 | 
			
		||||
@@ -12,9 +12,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
 | 
			
		||||
 | 
			
		||||
abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
 | 
			
		||||
    flowsChannelsSize: Int = 64,
 | 
			
		||||
    databaseName: String = ""
 | 
			
		||||
    tableName: String = ""
 | 
			
		||||
) :
 | 
			
		||||
    AbstractExposedReadCRUDRepo<ObjectType, IdType>(databaseName),
 | 
			
		||||
    AbstractExposedReadCRUDRepo<ObjectType, IdType>(tableName),
 | 
			
		||||
    ExposedCRUDRepo<ObjectType, IdType>,
 | 
			
		||||
    WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>
 | 
			
		||||
{
 | 
			
		||||
@@ -102,4 +102,4 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,8 +1,9 @@
 | 
			
		||||
package dev.inmo.micro_utils.repos.exposed
 | 
			
		||||
 | 
			
		||||
import dev.inmo.micro_utils.repos.Repo
 | 
			
		||||
import org.jetbrains.exposed.sql.*
 | 
			
		||||
 | 
			
		||||
interface ExposedCRUDRepo<ObjectType, IdType> {
 | 
			
		||||
interface ExposedCRUDRepo<ObjectType, IdType> : Repo {
 | 
			
		||||
    val database: Database
 | 
			
		||||
 | 
			
		||||
    val ResultRow.asObject: ObjectType
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,7 @@ String[] includes = [
 | 
			
		||||
    ":pagination:exposed",
 | 
			
		||||
    ":pagination:ktor:common",
 | 
			
		||||
    ":pagination:ktor:server",
 | 
			
		||||
    ":mime_types",
 | 
			
		||||
    ":repos:common",
 | 
			
		||||
    ":repos:exposed",
 | 
			
		||||
    ":repos:ktor:client",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user