diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/InboxJobProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/InboxJobProcessor.kt index e33da23b..3cc5d0fc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/InboxJobProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/service/tmp/InboxJobProcessor.kt @@ -93,8 +93,36 @@ class InboxJobProcessor( } override suspend fun process(param: InboxJobParam) { - println(param) - System.err.println("aaaaaaaaaaaaaaaaaaaaaaaaaaa") + val jsonNode = objectMapper.readTree(param.json) + + logger.info("START Process inbox. type: {}", param.type) + logger.trace("type: {}\njson: \n{}", param.type, jsonNode.toPrettyString()) + + val map = objectMapper.readValue>>(param.headers) + + val httpRequest = objectMapper.readValue(param.httpRequest).copy(headers = HttpHeaders(map)) + + logger.trace("Request: {}\nheaders: {}", httpRequest, map) + + val signature = parseSignatureHeader(httpRequest.headers) + + logger.debug("Has signature? {}", signature != null) + + val verify = signature?.let { verifyHttpSignature(httpRequest, it) } ?: false + + logger.debug("Is verifying success? {}", verify) + + val activityPubProcessor = activityPubProcessorList.firstOrNull { it.isSupported(param.type) } + + if (activityPubProcessor == null) { + logger.warn("ActivityType {} is not support.", param.type) + throw IllegalStateException("ActivityPubProcessor not found.") + } + + val value = objectMapper.treeToValue(jsonNode, activityPubProcessor.type()) + activityPubProcessor.process(ActivityPubProcessContext(value, jsonNode, httpRequest, signature, verify)) + + logger.info("SUCCESS Process inbox. type: {}", param.type) } override fun job(): InboxJob = InboxJob diff --git a/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt b/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt index 72878f6e..7ca2a630 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/external/job/HideoutJob.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.core.external.job +import dev.usbharu.hideout.activitypub.service.common.ActivityType import kjob.core.Job import kjob.core.Prop import kjob.core.dsl.ScheduleContext @@ -129,7 +130,7 @@ object DeliverRemoveReactionJob : data class InboxJobParam( val json: String, - val type: String, + val type: ActivityType, val httpRequest: String, val headers: String ) @@ -143,14 +144,14 @@ object InboxJob : HideoutJob("InboxJob") { override fun convert(value: InboxJobParam): ScheduleContext.(InboxJob) -> Unit = { props[json] = value.json - props[type] = value.type + props[type] = value.type.name props[httpRequest] = value.httpRequest props[headers] = value.headers } override fun convert(props: JobProps): InboxJobParam = InboxJobParam( props[json], - props[type], + ActivityType.valueOf(props[type]), props[httpRequest], props[headers] )