fix: リモートユーザーを取得時に使用したURLでurlが登録されてしまう問題を修正

This commit is contained in:
usbharu 2023-11-21 15:47:38 +09:00
parent d93c34adb4
commit 9ce7b6e6dd
1 changed files with 11 additions and 9 deletions

View File

@ -80,26 +80,27 @@ class APUserServiceImpl(
override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, User> { override suspend fun fetchPersonWithEntity(url: String, targetActor: String?): Pair<Person, User> {
return try { return try {
val userEntity = userQueryService.findByUrl(url) val userEntity = userQueryService.findByUrl(url)
val id = userEntity.url
return Person( return Person(
type = emptyList(), type = emptyList(),
name = userEntity.name, name = userEntity.name,
id = url, id = id,
preferredUsername = userEntity.name, preferredUsername = userEntity.name,
summary = userEntity.description, summary = userEntity.description,
inbox = "$url/inbox", inbox = "$id/inbox",
outbox = "$url/outbox", outbox = "$id/outbox",
url = url, url = id,
icon = Image( icon = Image(
type = emptyList(), type = emptyList(),
name = "$url/icon.png", name = "$id/icon.png",
mediaType = "image/png", mediaType = "image/png",
url = "$url/icon.png" url = "$id/icon.png"
), ),
publicKey = Key( publicKey = Key(
type = emptyList(), type = emptyList(),
name = "Public Key", name = "Public Key",
id = userEntity.keyId, id = userEntity.keyId,
owner = url, owner = id,
publicKeyPem = userEntity.publicKey publicKeyPem = userEntity.publicKey
), ),
endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"), endpoints = mapOf("sharedInbox" to "${applicationConfig.url}/inbox"),
@ -109,17 +110,18 @@ class APUserServiceImpl(
} catch (ignore: FailedToGetResourcesException) { } catch (ignore: FailedToGetResourcesException) {
val person = apResourceResolveService.resolve<Person>(url, null as Long?) val person = apResourceResolveService.resolve<Person>(url, null as Long?)
val id = person.id ?: throw IllegalActivityPubObjectException("id is null")
person to userService.createRemoteUser( person to userService.createRemoteUser(
RemoteUserCreateDto( RemoteUserCreateDto(
name = person.preferredUsername name = person.preferredUsername
?: throw IllegalActivityPubObjectException("preferredUsername is null"), ?: throw IllegalActivityPubObjectException("preferredUsername is null"),
domain = url.substringAfter("://").substringBefore("/"), domain = id.substringAfter("://").substringBefore("/"),
screenName = (person.name ?: person.preferredUsername) screenName = (person.name ?: person.preferredUsername)
?: throw IllegalActivityPubObjectException("preferredUsername is null"), ?: throw IllegalActivityPubObjectException("preferredUsername is null"),
description = person.summary.orEmpty(), description = person.summary.orEmpty(),
inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"), inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),
outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"), outbox = person.outbox ?: throw IllegalActivityPubObjectException("outbox is null"),
url = url, url = id,
publicKey = person.publicKey?.publicKeyPem publicKey = person.publicKey?.publicKeyPem
?: throw IllegalActivityPubObjectException("publicKey is null"), ?: throw IllegalActivityPubObjectException("publicKey is null"),
keyId = person.publicKey?.id ?: throw IllegalActivityPubObjectException("publicKey keyId is null"), keyId = person.publicKey?.id ?: throw IllegalActivityPubObjectException("publicKey keyId is null"),