first fully ready for trying system
This commit is contained in:
1 parent
559545438a
commit
369dcb12f5
24 files changed
+199
-13
No files matched your search
@@ -29,6 +29,8 @@ import dev.inmo.postssystem.features.content.common.ContentSerializersModuleConf
|
||||
import dev.inmo.postssystem.features.content.common.OtherContentSerializerModuleConfigurator
|
||||
import dev.inmo.postssystem.features.content.text.common.TextContentSerializerModuleConfigurator
|
||||
import dev.inmo.postssystem.features.status.client.StatusFeatureClient
|
||||
import dev.inmo.postssystem.publicators.simple.client.SimplePublicatorService
|
||||
import dev.inmo.postssystem.publicators.simple.client.SimplePublicatorServiceClient
|
||||
import dev.inmo.postssystem.services.posts.client.ClientPostsService
|
||||
import dev.inmo.postssystem.services.posts.common.*
|
||||
import io.ktor.client.HttpClient
|
||||
@@ -138,5 +140,6 @@ fun getAuthorizedFeaturesDIModule(
|
||||
ReadPostsService::class,
|
||||
WritePostsService::class
|
||||
)
|
||||
single<SimplePublicatorService> { SimplePublicatorServiceClient(get(serverUrlQualifier), get()) }
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ fun baseKoin(): Koin {
|
||||
factory { AuthUIViewModel(get()) }
|
||||
factory { AuthView(get(), get(UIScopeQualifier)) }
|
||||
|
||||
factory<PostCreateUIModel> { DefaultPostCreateUIModel(get()) }
|
||||
factory<PostCreateUIModel> { DefaultPostCreateUIModel(get(), get()) }
|
||||
factory { PostCreateUIViewModel(get()) }
|
||||
factory { PostCreateView(get(), get(UIScopeQualifier)) }
|
||||
}
|
||||
|
||||
+6
-1
@@ -5,6 +5,7 @@ import dev.inmo.postssystem.features.files.common.storage.WriteFilesStorage
|
||||
import dev.inmo.micro_utils.repos.*
|
||||
import io.ktor.utils.io.core.copyTo
|
||||
import io.ktor.utils.io.streams.asOutput
|
||||
import io.ktor.utils.io.streams.writePacket
|
||||
import kotlinx.coroutines.flow.*
|
||||
import java.io.File
|
||||
|
||||
@@ -38,7 +39,11 @@ class WriteDistFilesStorage(
|
||||
file = newId.file
|
||||
} while (file.exists())
|
||||
metasKeyValueRepo.set(newId, it.toMetaFileInfo())
|
||||
it.inputProvider().copyTo(file.outputStream().asOutput())
|
||||
it.inputProvider().use { input ->
|
||||
file.outputStream().asOutput().use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
FullFileInfoStorageWrapper(newId, it)
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package dev.inmo.postssystem.features.publication.common
|
||||
|
||||
const val publicatorsRootPath = "publicators"
|
||||
@@ -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.publicators.simple.common")
|
||||
api project(":postssystem.features.publication.client")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package dev.inmo.postssystem.publicators.simple.client
|
||||
|
||||
import dev.inmo.postssystem.features.posts.common.PostId
|
||||
|
||||
interface SimplePublicatorService {
|
||||
suspend fun publish(postId: PostId)
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package dev.inmo.postssystem.publicators.simple.client
|
||||
|
||||
import dev.inmo.micro_utils.ktor.client.UnifiedRequester
|
||||
import dev.inmo.micro_utils.ktor.common.buildStandardUrl
|
||||
import dev.inmo.postssystem.features.posts.common.PostId
|
||||
import dev.inmo.postssystem.features.publication.common.publicatorsRootPath
|
||||
import dev.inmo.postssystem.publicators.simple.common.simplePublicatorPublishPathPart
|
||||
import dev.inmo.postssystem.publicators.simple.common.simplePublicatorRootPath
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
class SimplePublicatorServiceClient(
|
||||
baseUrl: String,
|
||||
private val unifiedRequester: UnifiedRequester
|
||||
) : SimplePublicatorService {
|
||||
private val fullUrl = buildStandardUrl(
|
||||
baseUrl,
|
||||
buildStandardUrl(
|
||||
publicatorsRootPath,
|
||||
simplePublicatorRootPath
|
||||
)
|
||||
)
|
||||
|
||||
private val publishFullUrl = buildStandardUrl(
|
||||
fullUrl,
|
||||
simplePublicatorPublishPathPart
|
||||
)
|
||||
|
||||
override suspend fun publish(postId: PostId) = unifiedRequester.unipost(
|
||||
publishFullUrl,
|
||||
PostId.serializer() to postId,
|
||||
Unit.serializer()
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.postssystem.publicators.simple.client"/>
|
||||
@@ -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.publication.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package dev.inmo.postssystem.publicators.simple.common
|
||||
|
||||
const val simplePublicatorRootPath = "simple"
|
||||
const val simplePublicatorPublishPathPart = "publish"
|
||||
@@ -0,0 +1 @@
|
||||
<manifest package="dev.inmo.postssystem.publicators.simple.common"/>
|
||||
@@ -0,0 +1,17 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppJavaProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.publicators.simple.common")
|
||||
api project(":postssystem.features.publication.server")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package dev.inmo.postssystem.publicators.simple.server
|
||||
|
||||
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
|
||||
import dev.inmo.postssystem.features.common.common.singleWithRandomQualifier
|
||||
import dev.inmo.postssystem.features.common.server.sessions.ModuleLoader
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import org.koin.core.module.Module
|
||||
|
||||
class SimplePublicationTriggerLoader : ModuleLoader {
|
||||
override fun Module.load(config: JsonObject) {
|
||||
singleWithRandomQualifier<ApplicationRoutingConfigurator.Element> {
|
||||
SimplePublicatorRoutingConfigurator(
|
||||
get()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package dev.inmo.postssystem.publicators.simple.server
|
||||
|
||||
import dev.inmo.micro_utils.ktor.server.configurators.ApplicationRoutingConfigurator
|
||||
import dev.inmo.micro_utils.ktor.server.unianswer
|
||||
import dev.inmo.micro_utils.ktor.server.uniload
|
||||
import dev.inmo.postssystem.features.posts.common.PostId
|
||||
import dev.inmo.postssystem.features.publication.common.publicatorsRootPath
|
||||
import dev.inmo.postssystem.features.publication.server.PublicationManager
|
||||
import dev.inmo.postssystem.publicators.simple.common.simplePublicatorPublishPathPart
|
||||
import dev.inmo.postssystem.publicators.simple.common.simplePublicatorRootPath
|
||||
import io.ktor.application.call
|
||||
import io.ktor.routing.*
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
|
||||
class SimplePublicatorRoutingConfigurator(
|
||||
private val publicationManager: PublicationManager
|
||||
) : ApplicationRoutingConfigurator.Element {
|
||||
override fun Route.invoke() {
|
||||
route(publicatorsRootPath) {
|
||||
route(simplePublicatorRootPath) {
|
||||
post(simplePublicatorPublishPathPart) {
|
||||
val postId = call.uniload(PostId.serializer())
|
||||
|
||||
call.unianswer(
|
||||
Unit.serializer(),
|
||||
publicationManager.publish(postId)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.publicators.template.common")
|
||||
api project(":postssystem.features.common.client")
|
||||
api project(":postssystem.features.publication.client")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.features.common.common")
|
||||
api project(":postssystem.features.publication.common")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api project(":postssystem.publicators.template.common")
|
||||
api project(":postssystem.features.common.server")
|
||||
api project(":postssystem.features.publication.server")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ dependencies {
|
||||
|
||||
api project(":postssystem.services.posts.server")
|
||||
|
||||
api project(":postssystem.publicators.simple.server")
|
||||
|
||||
api project(":postssystem.targets.telegram.loader.server")
|
||||
api project(":postssystem.targets.telegram.publication.server")
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["postssystem.client"]=t():e["postssystem.client"]=t()}(this,(function(){return(()=>{var __webpack_modules__={643:function(module,exports){var __WEBPACK_AMD_DEFINE_FACTORY__,__WEBPACK_AMD_DEFINE_ARRAY__,__WEBPACK_AMD_DEFINE_RESULT__,factory;factory=function(_){"use strict";function toList(e){switch(e.length){case 0:return emptyList();case 1:return listOf_0(e[0]);default:return toMutableList(e)}}function withIndex(e){return new IndexingIterable(_no_name_provided_$factory(e))}function _get_indices_(e){return new IntRange(0,_get_lastIndex_(e))}function _get_indices__0(e){return new IntRange(0,_get_lastIndex__0(e))}function indexOf(e,t){if(null==t){var n=0,_=e.length-1|0;if(n<=_)do{var i=n;if(n=n+1|0,null==e[i])return i}while(n<=_)}else{var r=0,o=e.length-1|0;if(r<=o)do{var a=r;if(r=r+1|0,equals_1(t,e[a]))return a}while(r<=o)}return-1}function lastIndexOf(e,t){if(null==t){var n=e.length-1|0;if(0<=n)do{var _=n;if(n=n+-1|0,null==e[_])return _}while(0<=n)}else{var i=e.length-1|0;if(0<=i)do{var r=i;if(i=i+-1|0,equals_1(t,e[r]))return r}while(0<=i)}return-1}function toMutableList(e){return ArrayList_init_$Create$_1(asCollection(e))}function filterNotNull(e){return filterNotNullTo(e,ArrayList_init_$Create$())}function single(e){var t;switch(e.length){case 0:throw NoSuchElementException_init_$Create$_0("Array is empty.");case 1:t=e[0];break;default:throw IllegalArgumentException_init_$Create$_0("Array has more than one element.")}return t}function _get_lastIndex_(e){return e.length-1|0}function _get_lastIndex__0(e){return e.length-1|0}function filterNotNullTo(e,t){for(var n=e,_=0,i=n.length;_<i;){var r=n[_];_=_+1|0,null!=r&&(t.add_2bq_k$(r),Unit_getInstance())}return t}function toSet(e){switch(e.length){case 0:return emptySet();case 1:return setOf_0(e[0]);default:return toCollection(e,LinkedHashSet_init_$Create$_1(mapCapacity(e.length)))}}function toCollection(e,t){for(var n=e,_=0,i=n.length;_<i;){var r=n[_];_=_+1|0,t.add_2bq_k$(r),Unit_getInstance()}return t}function contains(e,t){return indexOf(e,t)>=0}function joinToString(e,t,n,_,i,r,o){return joinTo(e,StringBuilder_init_$Create$_0(),t,n,_,i,r,o).toString()}function joinToString$default(e,t,n,_,i,r,o,a,s){return 0!=(1&a)&&(t=", "),0!=(2&a)&&(n=""),0!=(4&a)&&(_=""),0!=(8&a)&&(i=-1),0!=(16&a)&&(r="..."),0!=(32&a)&&(o=null),joinToString(e,t,n,_,i,r,o)}function joinTo(e,t,n,_,i,r,o,a){t.append_v1o70a_k$(_),Unit_getInstance();var s=0,c=e,l=0,p=c.length;e:for(;l<p;){var d=c[l];if(l=l+1|0,(s=s+1|0)>1&&(t.append_v1o70a_k$(n),Unit_getInstance()),!(r<0||s<=r))break e;appendElement(t,d,a)}return r>=0&&s>r&&(t.append_v1o70a_k$(o),Unit_getInstance()),t.append_v1o70a_k$(i),Unit_getInstance(),t}function contains_0(e,t){return indexOf_0(e,t)>=0}function indexOf_0(e,t){var n=0,_=e.length-1|0;if(n<=_)do{var i=n;if(n=n+1|0,t.equals(e[i]))return i}while(n<=_);return-1}function zip(e,t){var n=e.length,_=t.length,i=Math.min(n,_),r=ArrayList_init_$Create$_0(i),o=0;if(o<i)do{var a,s=o;o=o+1|0,a=to(e[s],t[s]),r.add_2bq_k$(a),Unit_getInstance()}while(o<i);return r}function first(e){if(0===e.length)throw NoSuchElementException_init_$Create$_0("Array is empty.");return e[0]}function _get_lastIndex__1(e){return e.length-1|0}function asIterable(e){return 0===e.length?emptyList():new _no_name_provided__1(e)}function _no_name_provided_(e){this._$this_withIndex=e}function _no_name_provided__1(e){this._$this_asIterable=e}function _no_name_provided_$factory(e){var t=new _no_name_provided_(e);return function(){return t.invoke_0_k$()}}function toHashSet(e){return toCollection_0(e,HashSet_init_$Create$_1(mapCapacity(collectionSizeOrDefault(e,12))))}function toBooleanArray(e){for(var t=booleanArray(e._get_size__0_k$()),n=0,_=e.iterator_0_k$();_.hasNext_0_k$();){var i=_.next_0_k$(),r=n;n=r+1|0,t[r]=i}return t}function joinToString_0(e,t,n,_,i,r,o){return joinTo_0(e,StringBuilder_init_$Create$_0(),t,n,_,i,r,o).toString()}function joinToString$default_0(e,t,n,_,i,r,o,a,s){return 0!=(1&a)&&(t=", "),0!=(2&a)&&(n=""),0!=(4&a)&&(_=""),0!=(8&a)&&(i=-1),0!=(16&a)&&(r="..."),0!=(32&a)&&(o=null),joinToString_0(e,t,n,_,i,r,o)}function toList_0(e){if(isInterface(e,Collection)){var t;switch(e._get_size__0_k$()){case 0:t=emptyList();break;case 1:t=listOf_0(isInterface(e,List)?e.get_ha5a7z_k$(0):e.iterator_0_k$().next_0_k$());break;default:t=toMutableList_0(e)}return t}return optimizeReadOnlyList(toMutableList_1(e))}function reversed(e){if(isInterface(e,Collection)&&e._get_size__0_k$()<=1)return toList_0(e);var t=toMutableList_1(e);return reverse(t),t}function plus(e,t){if(isInterface(t,Collection)){var n=ArrayList_init_$Create$_0(e._get_size__0_k$()+t._get_size__0_k$()|0);return n.addAll_dxd4eo_k$(e),Unit_getInstance(),n.addAll_dxd4eo_k$(t),Unit_getInstance(),n}var _=ArrayList_init_$Create$_1(e);return addAll_0(_,t),Unit_getInstance(),_}function plus_0Line truncated
|
||||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports["postssystem.client"]=t():e["postssystem.client"]=t()}(this,(function(){return(()=>{var __webpack_modules__={643:function(module,exports){var __WEBPACK_AMD_DEFINE_FACTORY__,__WEBPACK_AMD_DEFINE_ARRAY__,__WEBPACK_AMD_DEFINE_RESULT__,factory;factory=function(_){"use strict";function toList(e){switch(e.length){case 0:return emptyList();case 1:return listOf_0(e[0]);default:return toMutableList(e)}}function withIndex(e){return new IndexingIterable(_no_name_provided_$factory(e))}function _get_indices_(e){return new IntRange(0,_get_lastIndex_(e))}function _get_indices__0(e){return new IntRange(0,_get_lastIndex__0(e))}function indexOf(e,t){if(null==t){var n=0,_=e.length-1|0;if(n<=_)do{var i=n;if(n=n+1|0,null==e[i])return i}while(n<=_)}else{var r=0,o=e.length-1|0;if(r<=o)do{var a=r;if(r=r+1|0,equals_1(t,e[a]))return a}while(r<=o)}return-1}function lastIndexOf(e,t){if(null==t){var n=e.length-1|0;if(0<=n)do{var _=n;if(n=n+-1|0,null==e[_])return _}while(0<=n)}else{var i=e.length-1|0;if(0<=i)do{var r=i;if(i=i+-1|0,equals_1(t,e[r]))return r}while(0<=i)}return-1}function toMutableList(e){return ArrayList_init_$Create$_1(asCollection(e))}function filterNotNull(e){return filterNotNullTo(e,ArrayList_init_$Create$())}function single(e){var t;switch(e.length){case 0:throw NoSuchElementException_init_$Create$_0("Array is empty.");case 1:t=e[0];break;default:throw IllegalArgumentException_init_$Create$_0("Array has more than one element.")}return t}function _get_lastIndex_(e){return e.length-1|0}function _get_lastIndex__0(e){return e.length-1|0}function filterNotNullTo(e,t){for(var n=e,_=0,i=n.length;_<i;){var r=n[_];_=_+1|0,null!=r&&(t.add_2bq_k$(r),Unit_getInstance())}return t}function toSet(e){switch(e.length){case 0:return emptySet();case 1:return setOf_0(e[0]);default:return toCollection(e,LinkedHashSet_init_$Create$_1(mapCapacity(e.length)))}}function toCollection(e,t){for(var n=e,_=0,i=n.length;_<i;){var r=n[_];_=_+1|0,t.add_2bq_k$(r),Unit_getInstance()}return t}function contains(e,t){return indexOf(e,t)>=0}function joinToString(e,t,n,_,i,r,o){return joinTo(e,StringBuilder_init_$Create$_0(),t,n,_,i,r,o).toString()}function joinToString$default(e,t,n,_,i,r,o,a,s){return 0!=(1&a)&&(t=", "),0!=(2&a)&&(n=""),0!=(4&a)&&(_=""),0!=(8&a)&&(i=-1),0!=(16&a)&&(r="..."),0!=(32&a)&&(o=null),joinToString(e,t,n,_,i,r,o)}function joinTo(e,t,n,_,i,r,o,a){t.append_v1o70a_k$(_),Unit_getInstance();var s=0,c=e,l=0,p=c.length;e:for(;l<p;){var d=c[l];if(l=l+1|0,(s=s+1|0)>1&&(t.append_v1o70a_k$(n),Unit_getInstance()),!(r<0||s<=r))break e;appendElement(t,d,a)}return r>=0&&s>r&&(t.append_v1o70a_k$(o),Unit_getInstance()),t.append_v1o70a_k$(i),Unit_getInstance(),t}function contains_0(e,t){return indexOf_0(e,t)>=0}function indexOf_0(e,t){var n=0,_=e.length-1|0;if(n<=_)do{var i=n;if(n=n+1|0,t.equals(e[i]))return i}while(n<=_);return-1}function zip(e,t){var n=e.length,_=t.length,i=Math.min(n,_),r=ArrayList_init_$Create$_0(i),o=0;if(o<i)do{var a,s=o;o=o+1|0,a=to(e[s],t[s]),r.add_2bq_k$(a),Unit_getInstance()}while(o<i);return r}function first(e){if(0===e.length)throw NoSuchElementException_init_$Create$_0("Array is empty.");return e[0]}function _get_lastIndex__1(e){return e.length-1|0}function asIterable(e){return 0===e.length?emptyList():new _no_name_provided__1(e)}function _no_name_provided_(e){this._$this_withIndex=e}function _no_name_provided__1(e){this._$this_asIterable=e}function _no_name_provided_$factory(e){var t=new _no_name_provided_(e);return function(){return t.invoke_0_k$()}}function toHashSet(e){return toCollection_0(e,HashSet_init_$Create$_1(mapCapacity(collectionSizeOrDefault(e,12))))}function toBooleanArray(e){for(var t=booleanArray(e._get_size__0_k$()),n=0,_=e.iterator_0_k$();_.hasNext_0_k$();){var i=_.next_0_k$(),r=n;n=r+1|0,t[r]=i}return t}function joinToString_0(e,t,n,_,i,r,o){return joinTo_0(e,StringBuilder_init_$Create$_0(),t,n,_,i,r,o).toString()}function joinToString$default_0(e,t,n,_,i,r,o,a,s){return 0!=(1&a)&&(t=", "),0!=(2&a)&&(n=""),0!=(4&a)&&(_=""),0!=(8&a)&&(i=-1),0!=(16&a)&&(r="..."),0!=(32&a)&&(o=null),joinToString_0(e,t,n,_,i,r,o)}function toList_0(e){if(isInterface(e,Collection)){var t;switch(e._get_size__0_k$()){case 0:t=emptyList();break;case 1:t=listOf_0(isInterface(e,List)?e.get_ha5a7z_k$(0):e.iterator_0_k$().next_0_k$());break;default:t=toMutableList_0(e)}return t}return optimizeReadOnlyList(toMutableList_1(e))}function reversed(e){if(isInterface(e,Collection)&&e._get_size__0_k$()<=1)return toList_0(e);var t=toMutableList_1(e);return reverse(t),t}function plus(e,t){if(isInterface(t,Collection)){var n=ArrayList_init_$Create$_0(e._get_size__0_k$()+t._get_size__0_k$()|0);return n.addAll_dxd4eo_k$(e),Unit_getInstance(),n.addAll_dxd4eo_k$(t),Unit_getInstance(),n}var _=ArrayList_init_$Create$_1(e);return addAll_0(_,t),Unit_getInstance(),_}function plus_0Line truncated
|
||||
//# sourceMappingURL=postssystem.client.js.map
|
||||
@@ -7,7 +7,8 @@
|
||||
"filesFolder": "/tmp/files",
|
||||
"debugMode": true,
|
||||
"modules": [
|
||||
"dev.inmo.postssystem.targets.telegram.loader.server.TelegramTargetModuleLoader"
|
||||
"dev.inmo.postssystem.targets.telegram.loader.server.TelegramTargetModuleLoader",
|
||||
"dev.inmo.postssystem.publicators.simple.server.SimplePublicationTriggerLoader"
|
||||
],
|
||||
"telegram": {
|
||||
"botToken": "YOUR BOT TOKEN",
|
||||
|
||||
@@ -13,6 +13,7 @@ kotlin {
|
||||
api project(":postssystem.features.common.client")
|
||||
api project(":postssystem.services.posts.common")
|
||||
api project(":postssystem.features.posts.client")
|
||||
api project(":postssystem.publicators.simple.client")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
-3
@@ -2,20 +2,25 @@ package dev.inmo.postssystem.services.posts.client.ui.create
|
||||
|
||||
import dev.inmo.postssystem.features.common.common.AbstractUIModel
|
||||
import dev.inmo.postssystem.features.content.common.Content
|
||||
import dev.inmo.postssystem.publicators.simple.client.SimplePublicatorService
|
||||
import dev.inmo.postssystem.services.posts.common.FullNewPost
|
||||
import dev.inmo.postssystem.services.posts.common.WritePostsService
|
||||
import kotlinx.coroutines.delay
|
||||
|
||||
class DefaultPostCreateUIModel(
|
||||
private val postCreationService: WritePostsService
|
||||
private val postCreationService: WritePostsService,
|
||||
private val publicationService: SimplePublicatorService
|
||||
) : PostCreateUIModel, AbstractUIModel<PostCreateUIState>(
|
||||
PostCreateUIState.Init
|
||||
) {
|
||||
override suspend fun create(content: List<Content>) {
|
||||
runCatching {
|
||||
_currentState.value = PostCreateUIState.Uploading
|
||||
postCreationService.create(
|
||||
val post = postCreationService.create(
|
||||
FullNewPost(content)
|
||||
)
|
||||
) ?: return@runCatching
|
||||
delay(1000L)
|
||||
publicationService.publish(post.id)
|
||||
}.onFailure {
|
||||
_currentState.value = PostCreateUIState.Fail
|
||||
}.onSuccess {
|
||||
|
||||
@@ -53,6 +53,10 @@ String[] includes = [
|
||||
":features:publication:client",
|
||||
":features:publication:server",
|
||||
|
||||
":publicators:simple:common",
|
||||
":publicators:simple:client",
|
||||
":publicators:simple:server",
|
||||
|
||||
":targets:telegram:publication:server",
|
||||
":targets:telegram:loader:common",
|
||||
":targets:telegram:loader:server",
|
||||
|
||||
+18
-3
@@ -12,6 +12,7 @@ import dev.inmo.tgbotapi.requests.send.SendTextMessage
|
||||
import dev.inmo.tgbotapi.requests.send.media.*
|
||||
import dev.inmo.tgbotapi.types.ChatId
|
||||
import dev.inmo.tgbotapi.utils.StorageFile
|
||||
import dev.inmo.tgbotapi.utils.StorageFileInfo
|
||||
import io.ktor.utils.io.ByteReadChannel
|
||||
import io.ktor.utils.io.core.readBytes
|
||||
import kotlinx.coroutines.delay
|
||||
@@ -25,7 +26,9 @@ class PublicationTargetTelegram(
|
||||
when (val content = it.content) {
|
||||
is BinaryContent -> {
|
||||
val storageFile by lazy {
|
||||
StorageFile(content.filename.name, content.inputProvider().readBytes()).asMultipartFile()
|
||||
StorageFile(StorageFileInfo(content.filename.name)) {
|
||||
content.inputProvider()
|
||||
}.asMultipartFile()
|
||||
}
|
||||
when (content.mimeType) {
|
||||
is KnownMimeTypes.Image.Jpeg,
|
||||
@@ -38,7 +41,10 @@ class PublicationTargetTelegram(
|
||||
is KnownMimeTypes.Audio.Mpeg -> {
|
||||
SendAudio(targetChatId, storageFile)
|
||||
}
|
||||
else -> null
|
||||
else -> SendDocument(
|
||||
targetChatId,
|
||||
storageFile
|
||||
)
|
||||
}
|
||||
}
|
||||
is TextContent -> {
|
||||
@@ -47,7 +53,16 @@ class PublicationTargetTelegram(
|
||||
else -> null
|
||||
}
|
||||
}.forEach { request ->
|
||||
bot.executeUnsafe(request, 3, 1000L)
|
||||
repeat(3) {
|
||||
runCatching {
|
||||
bot.execute(request)
|
||||
}.onFailure {
|
||||
it.printStackTrace()
|
||||
}.onSuccess {
|
||||
return@forEach
|
||||
}
|
||||
delay(1000L)
|
||||
}
|
||||
delay(100L)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user