mirror of https://github.com/usbharu/Hideout.git
feat: とりあえずacceptを返すように
This commit is contained in:
parent
61ddbb5743
commit
9dcaddc108
|
@ -1,13 +1,13 @@
|
|||
package dev.usbharu.hideout.ap
|
||||
|
||||
open class Follow : Object{
|
||||
public var `object`:Object? = null
|
||||
public var `object`:String? = null
|
||||
public var actor:String? = null
|
||||
protected constructor() : super()
|
||||
constructor(
|
||||
type: List<String> = emptyList(),
|
||||
name: String,
|
||||
`object`: Object?,
|
||||
`object`: String?,
|
||||
actor: String?
|
||||
) : super(add(type,"Follow"), name) {
|
||||
this.`object` = `object`
|
||||
|
|
|
@ -4,7 +4,7 @@ open class Person : Object {
|
|||
private var id:String? = null
|
||||
var preferredUsername:String? = null
|
||||
var summary:String? = null
|
||||
private var inbox:String? = null
|
||||
var inbox:String? = null
|
||||
private var outbox:String? = null
|
||||
private var url:String? = null
|
||||
private var icon:Image? = null
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package dev.usbharu.hideout.routing
|
||||
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import dev.usbharu.hideout.ap.Follow
|
||||
import dev.usbharu.hideout.config.Config
|
||||
import dev.usbharu.hideout.service.ActivityPubService
|
||||
import dev.usbharu.hideout.service.ActivityPubUserService
|
||||
import dev.usbharu.hideout.util.HttpUtil
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
|
@ -8,7 +12,7 @@ import io.ktor.server.request.*
|
|||
import io.ktor.server.response.*
|
||||
import io.ktor.server.routing.*
|
||||
|
||||
fun Application.userActivityPubRouting(activityPubService: ActivityPubService) {
|
||||
fun Application.userActivityPubRouting(activityPubService: ActivityPubService, activityPubUserService: ActivityPubUserService) {
|
||||
routing {
|
||||
route("/users/{name}") {
|
||||
route("/inbox") {
|
||||
|
@ -21,7 +25,17 @@ fun Application.userActivityPubRouting(activityPubService: ActivityPubService) {
|
|||
}
|
||||
val bodyText = call.receiveText()
|
||||
println(bodyText)
|
||||
activityPubService.switchApType(bodyText)
|
||||
when (activityPubService.switchApType(bodyText)) {
|
||||
ActivityPubService.ActivityType.Follow -> {
|
||||
val readValue = Config.configData.objectMapper.readValue<Follow>(bodyText)
|
||||
activityPubUserService.receiveFollow(readValue)
|
||||
|
||||
}
|
||||
|
||||
ActivityPubService.ActivityType.Undo -> {
|
||||
TODO()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package dev.usbharu.hideout.service
|
||||
|
||||
import dev.usbharu.hideout.ap.Image
|
||||
import dev.usbharu.hideout.ap.Key
|
||||
import dev.usbharu.hideout.ap.Person
|
||||
import dev.usbharu.hideout.ap.*
|
||||
import dev.usbharu.hideout.config.Config
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
|
@ -13,7 +11,8 @@ import io.ktor.http.*
|
|||
class ActivityPubUserService(
|
||||
private val httpClient: HttpClient,
|
||||
private val userService: UserService,
|
||||
private val userAuthService: IUserAuthService
|
||||
private val userAuthService: IUserAuthService,
|
||||
private val webFingerService: WebFingerService
|
||||
) {
|
||||
suspend fun generateUserModel(name: String): Person {
|
||||
val userEntity = userService.findByName(name)
|
||||
|
@ -55,7 +54,16 @@ class ActivityPubUserService(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun receiveFollow(){
|
||||
|
||||
suspend fun receiveFollow(follow: Follow) {
|
||||
val actor = follow.actor ?: throw IllegalArgumentException("actor is null")
|
||||
val person = fetchUserModel(actor) ?: throw IllegalArgumentException("actor is not found")
|
||||
val inboxUrl = person.inbox ?: throw IllegalArgumentException("inbox is not found")
|
||||
httpClient.post(inboxUrl) {
|
||||
setBody(Accept(
|
||||
name = "Follow",
|
||||
`object` = follow,
|
||||
actor = follow.`object`.orEmpty()
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue