From 5320915f7fcd3ddf3a2f75638427c2c5502db39a Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 30 Mar 2023 19:47:08 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20accept=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/service/WebFingerService.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt b/src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt index 90e99a07..e099a951 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/WebFingerService.kt @@ -12,8 +12,8 @@ import io.ktor.client.request.* import io.ktor.http.* class WebFingerService( - private val httpClient: HttpClient, - private val userService: UserService + private val httpClient: HttpClient, + private val userService: UserService ) : IWebFingerService { override suspend fun fetch(acct: String): WebFinger? { @@ -22,7 +22,7 @@ class WebFingerService( return try { httpClient.get("https://$domain/.well-known/webfinger?resource=acct:$fullName") - .body() + .body() } catch (e: ResponseException) { if (e.response.status == HttpStatusCode.NotFound) { return null @@ -33,7 +33,9 @@ class WebFingerService( override suspend fun fetchUserModel(url: String): Person? { return try { - httpClient.get(url).body() + httpClient.get(url) { + header("Accept", "application/activity+json") + }.body() } catch (e: ResponseException) { if (e.response.status == HttpStatusCode.NotFound) { return null @@ -46,9 +48,9 @@ class WebFingerService( val link = webFinger.links.find { it.rel == "self" && HttpUtil.isContentTypeOfActivityPub( - ContentType.parse( - it.type.orEmpty() - ) + ContentType.parse( + it.type.orEmpty() + ) ) }?.href ?: throw Exception() @@ -59,10 +61,10 @@ class WebFingerService( val userModel = fetchUserModel(link) ?: throw Exception() val user = User( - userModel.preferredUsername ?: throw IllegalStateException(), - domain, - userName, - userModel.summary.orEmpty() + userModel.preferredUsername ?: throw IllegalStateException(), + domain, + userName, + userModel.summary.orEmpty() ) return userService.create(user) }