mirror of https://github.com/usbharu/Hideout.git
feat: ActivityPubのusersのルーティングを追加
This commit is contained in:
parent
f02ca9e5b0
commit
469b886caf
|
@ -73,6 +73,10 @@ dependencies {
|
|||
testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
|
||||
|
||||
implementation("org.drewcarlson:kjob-core:0.6.0")
|
||||
testImplementation("io.ktor:ktor-server-test-host-jvm:2.2.4")
|
||||
|
||||
testImplementation("org.slf4j:slf4j-simple:2.0.7")
|
||||
|
||||
}
|
||||
|
||||
jib {
|
||||
|
|
|
@ -11,9 +11,6 @@ import io.ktor.server.routing.*
|
|||
fun Routing.usersAP(activityPubService: ActivityPubService){
|
||||
route("/users/{name}"){
|
||||
createChild(ContentTypeRouteSelector(ContentType.Application.Activity)).handle {
|
||||
val json = call.receiveText()
|
||||
val activityTypes = activityPubService.parseActivity(json)
|
||||
activityPubService.processActivity(json,activityTypes)
|
||||
call.respond(HttpStatusCode.NotImplemented)
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +18,10 @@ fun Routing.usersAP(activityPubService: ActivityPubService){
|
|||
|
||||
class ContentTypeRouteSelector(private val contentType: ContentType) : RouteSelector() {
|
||||
override fun evaluate(context: RoutingResolveContext, segmentIndex: Int): RouteSelectorEvaluation {
|
||||
return if (context.call.request.contentType() == contentType) {
|
||||
return if (ContentType.parse(context.call.request.accept() ?: return RouteSelectorEvaluation.FailedParameter) == contentType) {
|
||||
RouteSelectorEvaluation.Constant
|
||||
} else {
|
||||
RouteSelectorEvaluation.Failed
|
||||
RouteSelectorEvaluation.FailedParameter
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package dev.usbharu.hideout
|
||||
|
||||
import io.ktor.server.application.*
|
||||
|
||||
fun Application.empty(){
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package dev.usbharu.hideout.routing.activitypub
|
||||
|
||||
import dev.usbharu.hideout.plugins.configureRouting
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityPubService
|
||||
import dev.usbharu.hideout.service.activitypub.ActivityType
|
||||
import dev.usbharu.hideout.service.signature.HttpSignatureVerifyService
|
||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.config.*
|
||||
import io.ktor.server.testing.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
|
||||
class UsersAPTest {
|
||||
|
||||
@Test
|
||||
fun testHandleUsersName() = testApplication {
|
||||
environment {
|
||||
config = ApplicationConfig("empty.conf")
|
||||
}
|
||||
application {
|
||||
configureRouting(object : HttpSignatureVerifyService {
|
||||
override fun verify(headers: Headers): Boolean {
|
||||
return true
|
||||
}
|
||||
}, object : ActivityPubService {
|
||||
override fun parseActivity(json: String): ActivityType {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun processActivity(json: String, type: ActivityType) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
})
|
||||
}
|
||||
client.get("/users/test"){
|
||||
accept(ContentType.Application.Activity)
|
||||
}.let {
|
||||
assertEquals(HttpStatusCode.NotImplemented, it.status)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
ktor {
|
||||
development = true
|
||||
deployment {
|
||||
port = 8080
|
||||
port = ${?PORT}
|
||||
watch = [classes, resources]
|
||||
}
|
||||
application {
|
||||
modules = [dev.usbharu.hideout.EmptyKt.empty]
|
||||
}
|
||||
}
|
||||
|
||||
hideout {
|
||||
hostname = "https://localhost:8080"
|
||||
hostname = ${?HOSTNAME}
|
||||
database {
|
||||
url = "jdbc:h2:./test;MODE=POSTGRESQL"
|
||||
driver = "org.h2.Driver"
|
||||
username = ""
|
||||
password = ""
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue