fix: ドメインの抽出を修正

This commit is contained in:
usbharu 2023-04-28 23:36:27 +09:00
parent bd122ea164
commit a31b1226e9
2 changed files with 10 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.domain.model.ap
import com.fasterxml.jackson.annotation.JsonAutoDetect import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.JsonCreator import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.JsonDeserializer import com.fasterxml.jackson.databind.JsonDeserializer
@ -15,7 +16,8 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize
open class JsonLd { open class JsonLd {
@JsonProperty("@context") @JsonProperty("@context")
@JsonDeserialize(contentUsing = ContextDeserializer::class) @JsonDeserialize(contentUsing = ContextDeserializer::class)
@JsonSerialize(using = ContextSerializer::class) @JsonSerialize(include = JsonSerialize.Inclusion.NON_EMPTY, using = ContextSerializer::class)
@JsonInclude(JsonInclude.Include.NON_EMPTY)
var context: List<String> = emptyList() var context: List<String> = emptyList()
@JsonCreator @JsonCreator
@ -57,6 +59,12 @@ class ContextDeserializer : JsonDeserializer<String>() {
} }
class ContextSerializer : JsonSerializer<List<String>>() { class ContextSerializer : JsonSerializer<List<String>>() {
override fun isEmpty(value: List<String>?): Boolean {
return value.isNullOrEmpty()
}
override fun serialize(value: List<String>?, gen: JsonGenerator?, serializers: SerializerProvider?) { override fun serialize(value: List<String>?, gen: JsonGenerator?, serializers: SerializerProvider?) {
if (value.isNullOrEmpty()) { if (value.isNullOrEmpty()) {
gen?.writeNull() gen?.writeNull()

View File

@ -89,7 +89,7 @@ class ActivityPubUserServiceImpl(
RemoteUserCreateDto( RemoteUserCreateDto(
name = person.preferredUsername name = person.preferredUsername
?: throw IllegalActivityPubObjectException("preferredUsername is null"), ?: throw IllegalActivityPubObjectException("preferredUsername is null"),
domain = url.substringAfter(":").substringBeforeLast("/"), domain = url.substringAfter("://").substringBefore("/"),
screenName = (person.name ?: person.preferredUsername) ?: throw IllegalActivityPubObjectException("preferredUsername is null"), screenName = (person.name ?: person.preferredUsername) ?: throw IllegalActivityPubObjectException("preferredUsername is null"),
description = person.summary ?: "", description = person.summary ?: "",
inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"), inbox = person.inbox ?: throw IllegalActivityPubObjectException("inbox is null"),