mirror of https://github.com/usbharu/Hideout.git
feat: 予めJsonに変換してからpostするように
This commit is contained in:
parent
91f3edce3b
commit
53daf87ecf
|
@ -6,8 +6,10 @@ import dev.usbharu.hideout.repository.IUserAuthRepository
|
|||
import dev.usbharu.hideout.service.IUserAuthService
|
||||
import dev.usbharu.hideout.service.UserAuthService
|
||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.plugins.api.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.client.statement.*
|
||||
import io.ktor.http.*
|
||||
import io.ktor.server.application.*
|
||||
import io.ktor.server.response.*
|
||||
|
@ -38,6 +40,16 @@ suspend fun <T : JsonLd> ApplicationCall.respondAp(message: T, status: HttpStatu
|
|||
respondText(activityJson, ContentType.Application.Activity, status)
|
||||
}
|
||||
|
||||
suspend fun HttpClient.postAp(urlString: String,username:String,jsonLd: JsonLd): HttpResponse {
|
||||
return this.post(urlString){
|
||||
header("Accept", ContentType.Application.Activity)
|
||||
header("Content-Type", ContentType.Application.Activity)
|
||||
header("Signature","keyId=\"$username\",algorithm=\"rsa-sha256\",headers=\"(request-target) digest date\"")
|
||||
val text = Config.configData.objectMapper.writeValueAsString(jsonLd)
|
||||
setBody(text)
|
||||
}
|
||||
}
|
||||
|
||||
class HttpSignaturePluginConfig {
|
||||
lateinit var keyMap: KeyMap
|
||||
}
|
||||
|
|
|
@ -2,12 +2,8 @@ package dev.usbharu.hideout.service
|
|||
|
||||
import dev.usbharu.hideout.ap.*
|
||||
import dev.usbharu.hideout.config.Config
|
||||
import dev.usbharu.hideout.util.HttpUtil.Activity
|
||||
import dev.usbharu.hideout.plugins.postAp
|
||||
import io.ktor.client.*
|
||||
import io.ktor.client.call.*
|
||||
import io.ktor.client.plugins.*
|
||||
import io.ktor.client.request.*
|
||||
import io.ktor.http.*
|
||||
|
||||
class ActivityPubUserService(
|
||||
private val httpClient: HttpClient,
|
||||
|
@ -48,14 +44,12 @@ class ActivityPubUserService(
|
|||
val actor = follow.actor ?: throw IllegalArgumentException("actor is null")
|
||||
val person = webFingerService.fetchUserModel(actor) ?: throw IllegalArgumentException("actor is not found")
|
||||
val inboxUrl = person.inbox ?: throw IllegalArgumentException("inbox is not found")
|
||||
httpClient.post(inboxUrl) {
|
||||
contentType(ContentType.Application.Activity)
|
||||
header("Signature","keyId=\"${person.preferredUsername}\",algorithm=\"rsa-sha256\",headers=\"(request-target) digest date\"")
|
||||
setBody(Accept(
|
||||
httpClient.postAp(
|
||||
inboxUrl, person.preferredUsername!!, Accept(
|
||||
name = "Follow",
|
||||
`object` = follow,
|
||||
actor = follow.`object`.orEmpty()
|
||||
))
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue