mirror of https://github.com/usbharu/Hideout.git
refactor: ログを追加
This commit is contained in:
parent
8347bd7d0f
commit
63c15b35d1
|
@ -10,13 +10,24 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@RestController
|
||||
class InboxControllerImpl(private val apService: APService) : InboxController {
|
||||
override suspend fun inbox(@RequestBody string: String): ResponseEntity<Unit> {
|
||||
val parseActivity = apService.parseActivity(string)
|
||||
val parseActivity = try {
|
||||
apService.parseActivity(string)
|
||||
} catch (e: Exception) {
|
||||
LOGGER.warn("FAILED Parse Activity", e)
|
||||
return ResponseEntity.accepted().build()
|
||||
}
|
||||
LOGGER.info("INBOX Processing Activity Type: {}", parseActivity)
|
||||
try {
|
||||
apService.processActivity(string, parseActivity)
|
||||
} catch (e: Exception) {
|
||||
LOGGER.warn("FAILED Process Activity $parseActivity", e)
|
||||
return ResponseEntity(HttpStatus.ACCEPTED)
|
||||
}
|
||||
LOGGER.info("SUCCESS Processing Activity Type: {}", parseActivity)
|
||||
return ResponseEntity(HttpStatus.ACCEPTED)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val LOGGER = LoggerFactory.getLogger(InboxControllerImpl::class.java)
|
||||
private val LOGGER = LoggerFactory.getLogger(InboxControllerImpl::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import dev.usbharu.hideout.domain.model.wellknown.WebFinger
|
|||
import dev.usbharu.hideout.service.api.WebFingerApiService
|
||||
import dev.usbharu.hideout.util.AcctUtil
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
|
@ -18,7 +19,13 @@ class WebFingerController(
|
|||
) {
|
||||
@GetMapping("/.well-known/webfinger")
|
||||
fun webfinger(@RequestParam("resource") resource: String): ResponseEntity<WebFinger> = runBlocking {
|
||||
val acct = AcctUtil.parse(resource.replace("acct:", ""))
|
||||
logger.info("WEBFINGER Lookup webfinger resource: {}", resource)
|
||||
val acct = try {
|
||||
AcctUtil.parse(resource.replace("acct:", ""))
|
||||
} catch (e: IllegalArgumentException) {
|
||||
logger.warn("FAILED Parse acct.", e)
|
||||
return@runBlocking ResponseEntity.badRequest().build()
|
||||
}
|
||||
val user =
|
||||
webFingerApiService.findByNameAndDomain(acct.username, acct.domain ?: applicationConfig.url.host)
|
||||
val webFinger = WebFinger(
|
||||
|
@ -31,6 +38,11 @@ class WebFingerController(
|
|||
)
|
||||
)
|
||||
)
|
||||
logger.info("SUCCESS Lookup webfinger resource: {} acct: {}", resource, acct)
|
||||
ResponseEntity(webFinger, HttpStatus.OK)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = LoggerFactory.getLogger(WebFingerController::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,11 +188,21 @@ class APServiceImpl(
|
|||
val logger: Logger = LoggerFactory.getLogger(APServiceImpl::class.java)
|
||||
override fun parseActivity(json: String): ActivityType {
|
||||
val readTree = objectMapper.readTree(json)
|
||||
logger.trace("readTree: {}", readTree)
|
||||
logger.trace(
|
||||
"""
|
||||
|
|
||||
|***** Trace Begin Activity *****
|
||||
|
|
||||
|{}
|
||||
|
|
||||
|***** Trace End Activity *****
|
||||
|
|
||||
""".trimMargin(), readTree.toPrettyString()
|
||||
)
|
||||
if (readTree.isObject.not()) {
|
||||
throw JsonParseException("Json is not object.")
|
||||
}
|
||||
val type = readTree["type"]
|
||||
val type = readTree["type"] ?: throw JsonParseException("Type is null")
|
||||
if (type.isArray) {
|
||||
return type.firstNotNullOf { jsonNode: JsonNode ->
|
||||
ActivityType.values().firstOrNull { it.name.equals(jsonNode.asText(), true) }
|
||||
|
|
|
@ -7,6 +7,7 @@ import dev.usbharu.hideout.query.PostQueryService
|
|||
import dev.usbharu.hideout.repository.PostRepository
|
||||
import dev.usbharu.hideout.repository.UserRepository
|
||||
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
@ -22,12 +23,19 @@ class PostServiceImpl(
|
|||
private val interceptors = Collections.synchronizedList(mutableListOf<PostCreateInterceptor>())
|
||||
|
||||
override suspend fun createLocal(post: PostCreateDto): Post {
|
||||
logger.info("START Create Local Post user: {}, media: {}", post.userId, post.mediaIds.size)
|
||||
val create = internalCreate(post, true)
|
||||
interceptors.forEach { it.run(create) }
|
||||
logger.info("SUCCESS Create Local Post url: {}", create.url)
|
||||
return create
|
||||
}
|
||||
|
||||
override suspend fun createRemote(post: Post): Post = internalCreate(post, false)
|
||||
override suspend fun createRemote(post: Post): Post {
|
||||
logger.info("START Create Remote Post user: {}, remote url: {}", post.userId, post.apId)
|
||||
val createdPost = internalCreate(post, false)
|
||||
logger.info("SUCCESS Create Remote Post url: {}", createdPost.url)
|
||||
return createdPost
|
||||
}
|
||||
|
||||
override fun addInterceptor(postCreateInterceptor: PostCreateInterceptor) {
|
||||
interceptors.add(postCreateInterceptor)
|
||||
|
@ -58,4 +66,8 @@ class PostServiceImpl(
|
|||
)
|
||||
return internalCreate(createPost, isLocal)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = LoggerFactory.getLogger(PostServiceImpl::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,9 +20,7 @@ class ReactionServiceImpl(
|
|||
reactionRepository.save(
|
||||
Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||
)
|
||||
} catch (e: ExposedSQLException) {
|
||||
LOGGER.warn("FAILED Failure to persist reaction information.")
|
||||
LOGGER.debug("FAILED", e)
|
||||
} catch (_: ExposedSQLException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,4 +14,5 @@
|
|||
<logger name="io.ktor.server.plugins.contentnegotiation" level="INFO"/>
|
||||
<logger name="org.springframework.web.filter.CommonsRequestLoggingFilter" level="INFO"/>
|
||||
<logger name="org.mongodb.driver.protocol.command" level="INFO"/>
|
||||
<logger name="dev.usbharu" level="TRACE"/>
|
||||
</configuration>
|
||||
|
|
Loading…
Reference in New Issue