feat: 微修正

This commit is contained in:
usbharu 2023-10-12 14:58:34 +09:00
parent ed296637d9
commit c27599ac55
1 changed files with 15 additions and 7 deletions

View File

@ -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<Object>()
val bodyAsText = httpClient.get(url).bodyAsText()
return objectMapper.readValue<Object>(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<String, Long>()
private val valueStore = Collections.synchronizedMap(mutableMapOf<String, Object>())
}
private val cacheKey = ConcurrentHashMap<String, Long>()
private val valueStore = Collections.synchronizedMap(mutableMapOf<String, Object>())
}