From c27599ac55d5846f5d83f2edc08536d98f2f9730 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 12 Oct 2023 14:58:34 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BE=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resource/APResourceResolveServiceImpl.kt | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImpl.kt index 304c10da..55d1faa2 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/ap/resource/APResourceResolveServiceImpl.kt @@ -1,17 +1,26 @@ package dev.usbharu.hideout.service.ap.resource +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.readValue import dev.usbharu.hideout.domain.model.ap.Object import dev.usbharu.hideout.domain.model.hideout.entity.User import dev.usbharu.hideout.repository.UserRepository import io.ktor.client.* -import io.ktor.client.call.* import io.ktor.client.request.* +import io.ktor.client.statement.* import kotlinx.coroutines.delay +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.stereotype.Service import java.time.Instant import java.util.* import java.util.concurrent.ConcurrentHashMap -class APResourceResolveServiceImpl(private val httpClient: HttpClient, private val userRepository: UserRepository) : +@Service +class APResourceResolveServiceImpl( + private val httpClient: HttpClient, + private val userRepository: UserRepository, + @Qualifier("activitypub") private val objectMapper: ObjectMapper +) : APResourceResolveService { override suspend fun resolve(url: String, singerId: Long?): Object { @@ -53,7 +62,8 @@ class APResourceResolveServiceImpl(private val httpClient: HttpClient, private v } private suspend fun runResolve(url: String, singer: User?): Object { - return httpClient.get(url).body() + val bodyAsText = httpClient.get(url).bodyAsText() + return objectMapper.readValue(bodyAsText) } private fun genCacheKey(url: String, singerId: Long?): String { @@ -63,8 +73,6 @@ class APResourceResolveServiceImpl(private val httpClient: HttpClient, private v return url } - companion object { - private val cacheKey = ConcurrentHashMap() - private val valueStore = Collections.synchronizedMap(mutableMapOf()) - } + private val cacheKey = ConcurrentHashMap() + private val valueStore = Collections.synchronizedMap(mutableMapOf()) }