From db362fb48b28a73e799859c613446f46e1abfd15 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sat, 1 Apr 2023 21:23:09 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20ActivityPub=E3=81=AE=E3=83=AB?= =?UTF-8?q?=E3=83=BC=E3=83=86=E3=82=A3=E3=83=B3=E3=82=B0=E5=AE=9A=E7=BE=A9?= =?UTF-8?q?=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../routing/activitypub/InboxRouting.kt | 25 +++++++++++++++++++ .../routing/activitypub/OutboxRouting.kt | 25 +++++++++++++++++++ .../routing/activitypub/UserRouting.kt | 25 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/routing/activitypub/OutboxRouting.kt create mode 100644 src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt new file mode 100644 index 00000000..d82ea289 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/InboxRouting.kt @@ -0,0 +1,25 @@ +package dev.usbharu.hideout.routing.activitypub + +import io.ktor.server.application.* +import io.ktor.server.routing.* + +fun Routing.inbox(){ + + route("/inbox") { + get { + + } + post { + + } + } + route("/users/{name}/inbox"){ + get { + + } + post { + + } + } + +} diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/OutboxRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/OutboxRouting.kt new file mode 100644 index 00000000..cc8b133d --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/OutboxRouting.kt @@ -0,0 +1,25 @@ +package dev.usbharu.hideout.routing.activitypub + +import io.ktor.server.application.* +import io.ktor.server.routing.* + +fun Routing.outbox() { + + route("/outbox") { + get { + + } + post { + + } + } + route("/users/{name}/outbox"){ + get { + + } + post { + + } + } + +} diff --git a/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt new file mode 100644 index 00000000..a071c5f7 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/routing/activitypub/UserRouting.kt @@ -0,0 +1,25 @@ +package dev.usbharu.hideout.routing.activitypub + +import dev.usbharu.hideout.util.HttpUtil.Activity +import io.ktor.http.* +import io.ktor.server.application.* +import io.ktor.server.request.* +import io.ktor.server.routing.* + +fun Routing.users(){ + route("/users/{name}"){ + createChild(ContentTypeRouteSelector(ContentType.Application.Activity)).handle { + } + } +} + +class ContentTypeRouteSelector(private val contentType: ContentType) : RouteSelector() { + override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation { + return if (context.call.request.contentType() == contentType) { + RouteSelectorEvaluation.Constant + } else { + RouteSelectorEvaluation.Failed + } + } + +}