From 8d69492b895ff70bad36341ab2ded7abdb9d76d2 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:32:14 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E3=82=B3=E3=83=B3=E3=83=88=E3=83=AD?= =?UTF-8?q?=E3=83=BC=E3=83=A9=E3=83=BC=E3=81=AE=E3=83=90=E3=82=B0=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/actor/UserAPControllerImpl.kt | 7 +++++- .../interfaces/api/inbox/InboxController.kt | 2 +- .../interfaces/api/outbox/OutboxController.kt | 3 +-- .../api/outbox/OutboxControllerImpl.kt | 3 +-- .../api/webfinger/WebFingerController.kt | 6 ++++- .../service/reaction/ReactionServiceImpl.kt | 25 +++++++++++++------ 6 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImpl.kt index 0e52ca36..74ede688 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/actor/UserAPControllerImpl.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.activitypub.interfaces.api.actor import dev.usbharu.hideout.activitypub.domain.model.Person import dev.usbharu.hideout.activitypub.service.objects.user.APUserService +import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.RestController @@ -9,7 +10,11 @@ import org.springframework.web.bind.annotation.RestController @RestController class UserAPControllerImpl(private val apUserService: APUserService) : UserAPController { override suspend fun userAp(username: String): ResponseEntity { - val person = apUserService.getPersonByName(username) + val person = try { + apUserService.getPersonByName(username) + } catch (e: FailedToGetResourcesException) { + return ResponseEntity.notFound().build() + } person.context += listOf("https://www.w3.org/ns/activitystreams") return ResponseEntity(person, HttpStatus.OK) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxController.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxController.kt index f0c4b55d..b2e401cc 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxController.kt @@ -15,7 +15,7 @@ interface InboxController { "application/activity+json", "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" ], - method = [RequestMethod.GET, RequestMethod.POST] + method = [RequestMethod.POST] ) suspend fun inbox(@RequestBody string: String): ResponseEntity } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxController.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxController.kt index 1a4d9f60..0f422688 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxController.kt @@ -1,7 +1,6 @@ package dev.usbharu.hideout.activitypub.interfaces.api.outbox import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestMethod import org.springframework.web.bind.annotation.RestController @@ -9,5 +8,5 @@ import org.springframework.web.bind.annotation.RestController @RestController interface OutboxController { @RequestMapping("/outbox", "/users/{username}/outbox", method = [RequestMethod.POST, RequestMethod.GET]) - suspend fun outbox(@RequestBody string: String): ResponseEntity + suspend fun outbox(): ResponseEntity } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImpl.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImpl.kt index 398c680f..63eb9b50 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImpl.kt @@ -2,11 +2,10 @@ package dev.usbharu.hideout.activitypub.interfaces.api.outbox import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RestController @RestController class OutboxControllerImpl : OutboxController { - override suspend fun outbox(@RequestBody string: String): ResponseEntity = + override suspend fun outbox(): ResponseEntity = ResponseEntity(HttpStatus.NOT_IMPLEMENTED) } diff --git a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/webfinger/WebFingerController.kt b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/webfinger/WebFingerController.kt index c365d161..3a7bfdd8 100644 --- a/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/webfinger/WebFingerController.kt +++ b/src/main/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/webfinger/WebFingerController.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.activitypub.interfaces.api.webfinger import dev.usbharu.hideout.activitypub.domain.model.webfinger.WebFinger import dev.usbharu.hideout.activitypub.service.webfinger.WebFingerApiService import dev.usbharu.hideout.application.config.ApplicationConfig +import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException import dev.usbharu.hideout.util.AcctUtil import kotlinx.coroutines.runBlocking import org.slf4j.LoggerFactory @@ -26,8 +27,11 @@ class WebFingerController( logger.warn("FAILED Parse acct.", e) return@runBlocking ResponseEntity.badRequest().build() } - val user = + val user = try { webFingerApiService.findByNameAndDomain(acct.username, acct.domain ?: applicationConfig.url.host) + } catch (_: FailedToGetResourcesException) { + return@runBlocking ResponseEntity.notFound().build() + } val webFinger = WebFinger( "acct:${user.name}@${user.domain}", listOf( diff --git a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt index fdd2db74..baad0e56 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImpl.kt @@ -1,6 +1,7 @@ package dev.usbharu.hideout.core.service.reaction import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService +import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException import dev.usbharu.hideout.core.domain.model.reaction.Reaction import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository import dev.usbharu.hideout.core.query.ReactionQueryService @@ -26,18 +27,26 @@ class ReactionServiceImpl( } override suspend fun sendReaction(name: String, userId: Long, postId: Long) { - if (reactionQueryService.reactionAlreadyExist(postId, userId, 0)) { - // delete - reactionQueryService.deleteByPostIdAndUserId(postId, userId) - } else { - val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId) - reactionRepository.save(reaction) - apReactionService.reaction(reaction) + try { + val findByPostIdAndUserIdAndEmojiId = + reactionQueryService.findByPostIdAndUserIdAndEmojiId(postId, userId, 0) + apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId) + reactionRepository.delete(findByPostIdAndUserIdAndEmojiId) + } catch (_: FailedToGetResourcesException) { } + val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId) + reactionRepository.save(reaction) + apReactionService.reaction(reaction) } override suspend fun removeReaction(userId: Long, postId: Long) { - reactionQueryService.deleteByPostIdAndUserId(postId, userId) + try { + val findByPostIdAndUserIdAndEmojiId = + reactionQueryService.findByPostIdAndUserIdAndEmojiId(postId, userId, 0) + reactionRepository.delete(findByPostIdAndUserIdAndEmojiId) + apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId) + } catch (e: FailedToGetResourcesException) { + } } companion object {