mirror of https://github.com/usbharu/Hideout.git
feat: Instanceの取得に失敗したら仮の情報で保存するように
This commit is contained in:
parent
32faf70116
commit
4f084a375b
|
@ -37,7 +37,7 @@ interface InstanceService {
|
||||||
class InstanceServiceImpl(
|
class InstanceServiceImpl(
|
||||||
private val instanceRepository: InstanceRepository,
|
private val instanceRepository: InstanceRepository,
|
||||||
private val resourceResolveService: ResourceResolveService,
|
private val resourceResolveService: ResourceResolveService,
|
||||||
@Qualifier("activitypub") private val objectMapper: ObjectMapper
|
@Qualifier("activitypub") private val objectMapper: ObjectMapper,
|
||||||
) : InstanceService {
|
) : InstanceService {
|
||||||
override suspend fun fetchInstance(url: String, sharedInbox: String?): Instance {
|
override suspend fun fetchInstance(url: String, sharedInbox: String?): Instance {
|
||||||
val u = URL(url)
|
val u = URL(url)
|
||||||
|
@ -51,6 +51,9 @@ class InstanceServiceImpl(
|
||||||
|
|
||||||
logger.info("Instance not found. try fetch instance info. url: {}", resolveInstanceUrl)
|
logger.info("Instance not found. try fetch instance info. url: {}", resolveInstanceUrl)
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
val nodeinfoJson = resourceResolveService.resolve("$resolveInstanceUrl/.well-known/nodeinfo").bodyAsText()
|
val nodeinfoJson = resourceResolveService.resolve("$resolveInstanceUrl/.well-known/nodeinfo").bodyAsText()
|
||||||
val nodeinfo = objectMapper.readValue(nodeinfoJson, Nodeinfo::class.java)
|
val nodeinfo = objectMapper.readValue(nodeinfoJson, Nodeinfo::class.java)
|
||||||
val nodeinfoPathMap = nodeinfo.links.associate { it.rel to it.href }
|
val nodeinfoPathMap = nodeinfo.links.associate { it.rel to it.href }
|
||||||
|
@ -100,7 +103,21 @@ class InstanceServiceImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw IllegalStateException("Nodeinfo aren't found.")
|
|
||||||
|
} catch (e: Exception) {
|
||||||
|
logger.warn("FAILED Fetch Instance", e)
|
||||||
|
}
|
||||||
|
return createNewInstance(
|
||||||
|
InstanceCreateDto(
|
||||||
|
name = null,
|
||||||
|
description = null,
|
||||||
|
url = resolveInstanceUrl,
|
||||||
|
iconUrl = "$resolveInstanceUrl/favicon.ico",
|
||||||
|
sharedInbox = null,
|
||||||
|
software = null,
|
||||||
|
version = null
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun createNewInstance(instanceCreateDto: InstanceCreateDto): Instance {
|
override suspend fun createNewInstance(instanceCreateDto: InstanceCreateDto): Instance {
|
||||||
|
|
Loading…
Reference in New Issue