refactor: Inboxを改善

This commit is contained in:
usbharu 2023-04-10 15:11:26 +09:00
parent 2a3db9dddc
commit a9200eaeef
1 changed files with 16 additions and 7 deletions

View File

@ -30,9 +30,13 @@ fun Routing.inbox(
call.application.log.debug("ActivityTypes: ${activityTypes.name}") call.application.log.debug("ActivityTypes: ${activityTypes.name}")
val response = activityPubService.processActivity(json, activityTypes) val response = activityPubService.processActivity(json, activityTypes)
when (response) { when (response) {
is ActivityPubObjectResponse -> call.respond(response.httpStatusCode, Config.configData.objectMapper.writeValueAsString(response.message.apply { context = is ActivityPubObjectResponse -> call.respond(
response.httpStatusCode,
Config.configData.objectMapper.writeValueAsString(response.message.apply {
context =
listOf("https://www.w3.org/ns/activitystreams") listOf("https://www.w3.org/ns/activitystreams")
})) })
)
is ActivityPubStringResponse -> call.respond(response.httpStatusCode, response.message) is ActivityPubStringResponse -> call.respond(response.httpStatusCode, response.message)
null -> call.respond(HttpStatusCode.NotImplemented) null -> call.respond(HttpStatusCode.NotImplemented)
} }
@ -47,13 +51,18 @@ fun Routing.inbox(
throw HttpSignatureVerifyException() throw HttpSignatureVerifyException()
} }
val json = call.receiveText() val json = call.receiveText()
call.application.log.trace("Received: $json")
val activityTypes = activityPubService.parseActivity(json) val activityTypes = activityPubService.parseActivity(json)
println(activityTypes) call.application.log.debug("ActivityTypes: ${activityTypes.name}")
val response = activityPubService.processActivity(json, activityTypes) val response = activityPubService.processActivity(json, activityTypes)
when (response) { when (response) {
is ActivityPubObjectResponse -> call.respond(response.httpStatusCode, Config.configData.objectMapper.writeValueAsString(response.message.apply { context = is ActivityPubObjectResponse -> call.respond(
response.httpStatusCode,
Config.configData.objectMapper.writeValueAsString(response.message.apply {
context =
listOf("https://www.w3.org/ns/activitystreams") listOf("https://www.w3.org/ns/activitystreams")
})) })
)
is ActivityPubStringResponse -> call.respond(response.httpStatusCode, response.message) is ActivityPubStringResponse -> call.respond(response.httpStatusCode, response.message)
null -> call.respond(HttpStatusCode.NotImplemented) null -> call.respond(HttpStatusCode.NotImplemented)
} }