feat: misskeyが要求してくるアカウント名の形式にも対応

This commit is contained in:
usbharu 2023-03-24 17:46:01 +09:00
parent 819ec3ba52
commit de0516d710
1 changed files with 20 additions and 14 deletions

View File

@ -1,7 +1,6 @@
package dev.usbharu.hideout.routing
import dev.usbharu.hideout.config.Config
import dev.usbharu.hideout.exception.UserNotFoundException
import dev.usbharu.hideout.service.UserService
import dev.usbharu.hideout.util.HttpUtil.Activity
import io.ktor.http.*
@ -46,17 +45,23 @@ fun Application.wellKnown(userService: UserService) {
}
get("/webfinger") {
val uri = call.request.queryParameters["resource"] ?: return@get call.respondText("resource was not found",
val uri = call.request.queryParameters["resource"] ?: return@get call.respondText(
"resource was not found",
status = HttpStatusCode.BadRequest
)
val decodeURLPart = uri.decodeURLPart()
if (!decodeURLPart.startsWith("acct:")) {
return@get call.respondText("$uri was not found.",status =HttpStatusCode.BadRequest)
return@get call.respondText(
"$uri was not found.",
status = HttpStatusCode.BadRequest
)
}
val accountName = uri.substringBeforeLast("@").substringAfter("@")
val accountName =
uri.substringBeforeLast("@").substringAfter("acct:").trimStart('@')
val userEntity = userService.findByName(accountName)
return@get call.respond(WebFingerResource(
return@get call.respond(
WebFingerResource(
subject = decodeURLPart,
listOf(
WebFingerResource.Link(
@ -65,7 +70,8 @@ fun Application.wellKnown(userService: UserService) {
href = "${Config.configData.hostname}/users/${userEntity.name}"
)
)
))
)
)
}
}