From 9171e3a063f802efa4a61f59831acfce85f30e3a Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 26 Nov 2023 15:36:43 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Inbox=E3=81=AE=E3=82=B8=E3=83=A7?= =?UTF-8?q?=E3=83=96=E3=82=AD=E3=83=A5=E3=83=BC=E3=82=92=E5=9E=8B=E5=AE=89?= =?UTF-8?q?=E5=85=A8=E3=82=B8=E3=83=A7=E3=83=96=E3=82=AD=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E5=AE=9F=E8=A3=85=E3=81=AB=E5=88=87=E3=82=8A=E6=9B=BF=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/tmp/InboxJobProcessor.kt | 32 +++++++++++++++++-- .../hideout/core/external/job/HideoutJob.kt | 7 ++-- 2 files changed, 34 insertions(+), 5 deletions(-) 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] )