continue to adding workaround
This commit is contained in:
parent
a06324568e
commit
f683809f29
@ -0,0 +1,8 @@
|
|||||||
|
package dev.inmo.postssystem.features.common.server.sessions
|
||||||
|
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
|
interface ModuleLoader {
|
||||||
|
fun Module.load(config: JsonObject)
|
||||||
|
}
|
@ -25,6 +25,7 @@ dependencies {
|
|||||||
|
|
||||||
api project(":postssystem.services.posts.server")
|
api project(":postssystem.services.posts.server")
|
||||||
|
|
||||||
|
api project(":postssystem.targets.telegram.loader.server")
|
||||||
api project(":postssystem.targets.telegram.publication.server")
|
api project(":postssystem.targets.telegram.publication.server")
|
||||||
|
|
||||||
api libs.ktor.server.netty
|
api libs.ktor.server.netty
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package dev.inmo.postssystem.server
|
package dev.inmo.postssystem.server
|
||||||
|
|
||||||
|
import dev.inmo.postssystem.features.common.server.sessions.ModuleLoader
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -13,11 +14,25 @@ data class Config(
|
|||||||
@SerialName("auth")
|
@SerialName("auth")
|
||||||
val authConfig: AuthConfig = AuthConfig(),
|
val authConfig: AuthConfig = AuthConfig(),
|
||||||
val filesFolder: String,
|
val filesFolder: String,
|
||||||
|
@SerialName("modules")
|
||||||
|
val modulesClassPaths: List<String>,
|
||||||
val debugMode: Boolean = false
|
val debugMode: Boolean = false
|
||||||
) {
|
) {
|
||||||
val filesFolderFile: File
|
val filesFolderFile: File
|
||||||
get() = File(filesFolder)
|
get() = File(filesFolder)
|
||||||
|
|
||||||
|
@kotlinx.serialization.Transient
|
||||||
|
val modules by lazy {
|
||||||
|
modulesClassPaths.mapNotNull { moduleClassPath ->
|
||||||
|
runCatching {
|
||||||
|
Class.forName(moduleClassPath).constructors.firstOrNull { it.parameterCount == 0 } ?.newInstance() as ModuleLoader
|
||||||
|
}.onFailure {
|
||||||
|
println("Unable to load $moduleClassPath")
|
||||||
|
it.printStackTrace()
|
||||||
|
}.getOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val commonFilesFolder: File
|
val commonFilesFolder: File
|
||||||
get() = File(filesFolderFile, "common").also { it.mkdirs() }
|
get() = File(filesFolderFile, "common").also { it.mkdirs() }
|
||||||
val binaryFilesFolder: File
|
val binaryFilesFolder: File
|
||||||
|
@ -27,14 +27,13 @@ import dev.inmo.micro_utils.repos.exposed.onetomany.ExposedOneToManyKeyValueRepo
|
|||||||
import dev.inmo.postssystem.features.common.common.*
|
import dev.inmo.postssystem.features.common.common.*
|
||||||
import dev.inmo.postssystem.features.content.binary.server.BinaryServerContentStorage
|
import dev.inmo.postssystem.features.content.binary.server.BinaryServerContentStorage
|
||||||
import dev.inmo.postssystem.features.content.common.*
|
import dev.inmo.postssystem.features.content.common.*
|
||||||
import dev.inmo.postssystem.features.content.server.storage.ServerContentStorage
|
|
||||||
import dev.inmo.postssystem.features.content.server.ServerContentStorageAggregator
|
import dev.inmo.postssystem.features.content.server.ServerContentStorageAggregator
|
||||||
import dev.inmo.postssystem.features.content.server.ServerContentStorageWrapper
|
import dev.inmo.postssystem.features.content.server.ServerContentStorageWrapper
|
||||||
|
import dev.inmo.postssystem.features.content.server.storage.*
|
||||||
import dev.inmo.postssystem.features.content.text.common.TextContent
|
import dev.inmo.postssystem.features.content.text.common.TextContent
|
||||||
import dev.inmo.postssystem.features.content.text.common.TextContentSerializerModuleConfigurator
|
import dev.inmo.postssystem.features.content.text.common.TextContentSerializerModuleConfigurator
|
||||||
import dev.inmo.postssystem.features.content.text.server.TextServerContentStorage
|
import dev.inmo.postssystem.features.content.text.server.TextServerContentStorage
|
||||||
import dev.inmo.postssystem.features.posts.server.ExposedServerPostsStorage
|
import dev.inmo.postssystem.features.posts.server.*
|
||||||
import dev.inmo.postssystem.features.posts.server.ServerPostsStorage
|
|
||||||
import dev.inmo.postssystem.features.publication.server.PublicationManager
|
import dev.inmo.postssystem.features.publication.server.PublicationManager
|
||||||
import dev.inmo.postssystem.features.publication.server.PublicationTarget
|
import dev.inmo.postssystem.features.publication.server.PublicationTarget
|
||||||
import dev.inmo.postssystem.services.posts.server.*
|
import dev.inmo.postssystem.services.posts.server.*
|
||||||
@ -50,7 +49,7 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.serialization.BinaryFormat
|
import kotlinx.serialization.BinaryFormat
|
||||||
import kotlinx.serialization.StringFormat
|
import kotlinx.serialization.StringFormat
|
||||||
import kotlinx.serialization.cbor.Cbor
|
import kotlinx.serialization.cbor.Cbor
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.*
|
||||||
import kotlinx.serialization.modules.SerializersModule
|
import kotlinx.serialization.modules.SerializersModule
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.koin.core.module.Module
|
import org.koin.core.module.Module
|
||||||
@ -75,7 +74,8 @@ fun getDIModule(
|
|||||||
val configJson = Json {
|
val configJson = Json {
|
||||||
ignoreUnknownKeys = true
|
ignoreUnknownKeys = true
|
||||||
}
|
}
|
||||||
val config = configJson.decodeFromString(Config.serializer(), File(args.first()).readText())
|
val configJsonElement = configJson.decodeFromString(JsonObject.serializer(), File(args.first()).readText())
|
||||||
|
val config = configJson.decodeFromJsonElement(Config.serializer(), configJsonElement)
|
||||||
|
|
||||||
val originalFilesMetasKeyValueRepoQualifier = StringQualifier("OriginalFilesMetaKV")
|
val originalFilesMetasKeyValueRepoQualifier = StringQualifier("OriginalFilesMetaKV")
|
||||||
val binaryOriginalFilesMetasKeyValueRepoQualifier = StringQualifier("BinaryOriginalFilesMetaKV")
|
val binaryOriginalFilesMetasKeyValueRepoQualifier = StringQualifier("BinaryOriginalFilesMetaKV")
|
||||||
@ -148,10 +148,7 @@ fun getDIModule(
|
|||||||
}
|
}
|
||||||
singleWithBinds<RolesStorage<Role>> { RolesAggregator(getAll()) }
|
singleWithBinds<RolesStorage<Role>> { RolesAggregator(getAll()) }
|
||||||
|
|
||||||
// Publication targets
|
single(createdAtStart = true) { PublicationManager(getAll(), get(), get(), get()) }
|
||||||
singleWithRandomQualifier<PublicationTarget> { PublicationTargetTelegram(get(), get()) }
|
|
||||||
|
|
||||||
single { PublicationManager(getAll(), get(), get(), get()) }
|
|
||||||
|
|
||||||
// Roles checkers
|
// Roles checkers
|
||||||
single<RolesChecker<Role>>(StringQualifier(RolesManagerRolesChecker.key)) { RolesManagerRolesChecker }
|
single<RolesChecker<Role>>(StringQualifier(RolesManagerRolesChecker.key)) { RolesManagerRolesChecker }
|
||||||
@ -185,10 +182,16 @@ fun getDIModule(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
single<ServerContentStorage<Content>> { ServerContentStorageAggregator(getAll(), get()) }
|
single<ServerContentStorage<Content>> { ServerContentStorageAggregator(getAll(), get()) } binds arrayOf(
|
||||||
|
ServerReadContentStorage::class,
|
||||||
|
ServerWriteContentStorage::class
|
||||||
|
)
|
||||||
|
|
||||||
// Posts storage
|
// Posts storage
|
||||||
single<ServerPostsStorage> { ExposedServerPostsStorage(get()) }
|
single<ServerPostsStorage> { ExposedServerPostsStorage(get()) } binds arrayOf(
|
||||||
|
ServerReadPostsStorage::class,
|
||||||
|
ServerWritePostsStorage::class
|
||||||
|
)
|
||||||
|
|
||||||
singleWithBinds {
|
singleWithBinds {
|
||||||
ServerPostsService(
|
ServerPostsService(
|
||||||
@ -254,5 +257,9 @@ fun getDIModule(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config.modules.forEach {
|
||||||
|
it.apply { load(configJsonElement) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,12 @@
|
|||||||
"password": "test"
|
"password": "test"
|
||||||
},
|
},
|
||||||
"filesFolder": "/tmp/files",
|
"filesFolder": "/tmp/files",
|
||||||
"debugMode": true
|
"debugMode": true,
|
||||||
|
"modules": [
|
||||||
|
"dev.inmo.postssystem.targets.telegram.loader.server.TelegramTargetModuleLoader"
|
||||||
|
],
|
||||||
|
"telegram": {
|
||||||
|
"botToken": "YOUR BOT TOKEN",
|
||||||
|
"targetChatId": "YOUR CHAT ID"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ String[] includes = [
|
|||||||
":features:publication:server",
|
":features:publication:server",
|
||||||
|
|
||||||
":targets:telegram:publication:server",
|
":targets:telegram:publication:server",
|
||||||
|
":targets:telegram:loader:common",
|
||||||
|
":targets:telegram:loader:server",
|
||||||
|
|
||||||
":server",
|
":server",
|
||||||
":client",
|
":client",
|
||||||
|
18
targets/telegram/loader/client/build.gradle
Normal file
18
targets/telegram/loader/client/build.gradle
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppProjectWithSerializationPresetPath"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api project(":postssystem.targets.telegram.loader.common")
|
||||||
|
api project(":postssystem.features.common.client")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
<manifest package="dev.inmo.postssystem.targets.telegram.loader.client"/>
|
17
targets/telegram/loader/common/build.gradle
Normal file
17
targets/telegram/loader/common/build.gradle
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
id "com.android.library"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppProjectWithSerializationPresetPath"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api project(":postssystem.features.common.common")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
<manifest package="dev.inmo.postssystem.targets.telegram.loader.common"/>
|
18
targets/telegram/loader/server/build.gradle
Normal file
18
targets/telegram/loader/server/build.gradle
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
plugins {
|
||||||
|
id "org.jetbrains.kotlin.multiplatform"
|
||||||
|
id "org.jetbrains.kotlin.plugin.serialization"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$mppJavaProjectPresetPath"
|
||||||
|
|
||||||
|
kotlin {
|
||||||
|
sourceSets {
|
||||||
|
commonMain {
|
||||||
|
dependencies {
|
||||||
|
api project(":postssystem.targets.telegram.loader.common")
|
||||||
|
api project(":postssystem.targets.telegram.publication.server")
|
||||||
|
api project(":postssystem.features.common.server")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package dev.inmo.postssystem.targets.telegram.loader.server
|
||||||
|
|
||||||
|
import dev.inmo.tgbotapi.bot.Ktor.telegramBot
|
||||||
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import dev.inmo.tgbotapi.utils.TelegramAPIUrlsKeeper
|
||||||
|
import dev.inmo.tgbotapi.utils.telegramBotAPIDefaultUrl
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class SubConfig(
|
||||||
|
private val botToken: String,
|
||||||
|
val targetChatId: ChatId,
|
||||||
|
private val hostUrl: String = telegramBotAPIDefaultUrl
|
||||||
|
) {
|
||||||
|
val telegramInfo by lazy {
|
||||||
|
TelegramAPIUrlsKeeper(botToken, hostUrl)
|
||||||
|
}
|
||||||
|
val bot by lazy {
|
||||||
|
telegramBot(telegramInfo)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package dev.inmo.postssystem.targets.telegram.loader.server
|
||||||
|
|
||||||
|
import dev.inmo.postssystem.features.common.common.singleWithRandomQualifier
|
||||||
|
import dev.inmo.postssystem.features.common.server.sessions.ModuleLoader
|
||||||
|
import dev.inmo.postssystem.features.publication.server.PublicationTarget
|
||||||
|
import dev.inmo.postssystem.targets.telegram.publication.server.PublicationTargetTelegram
|
||||||
|
import dev.inmo.tgbotapi.bot.TelegramBot
|
||||||
|
import dev.inmo.tgbotapi.types.ChatId
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlinx.serialization.json.JsonObject
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
import org.koin.core.qualifier.StringQualifier
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expects to get a config from a field "telegram" of your config
|
||||||
|
*/
|
||||||
|
class TelegramTargetModuleLoader : ModuleLoader {
|
||||||
|
override fun Module.load(config: JsonObject) {
|
||||||
|
val configJson = config["telegram"]
|
||||||
|
|
||||||
|
val postingChatIdQualifier = StringQualifier("telegram_postingChatId")
|
||||||
|
|
||||||
|
configJson ?.let {
|
||||||
|
single<SubConfig> { get<Json>().decodeFromJsonElement(SubConfig.serializer(), configJson) }
|
||||||
|
single<TelegramBot> { get<SubConfig>().bot }
|
||||||
|
single<ChatId>(postingChatIdQualifier) { get<SubConfig>().targetChatId }
|
||||||
|
|
||||||
|
singleWithRandomQualifier<PublicationTarget> {
|
||||||
|
PublicationTargetTelegram(get(), get(postingChatIdQualifier))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user