From ff4d60548039157af838346560ba5294fa06c423 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 7 Dec 2023 00:02:41 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Twidere=E3=81=A7=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=8C=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=81=95=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hideout/application/config/SecurityConfig.kt | 4 +++- .../service/account/AccountApiService.kt | 10 ++++++---- .../mastodon/service/account/AccountService.kt | 16 +++++++++++----- src/main/resources/openapi/mastodon.yaml | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt b/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt index 59caf58d..fd129a61 100644 --- a/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/application/config/SecurityConfig.kt @@ -186,11 +186,13 @@ class SecurityConfig { authorize(POST, "/api/v1/accounts", permitAll) authorize("/auth/sign_up", hasRole("ANONYMOUS")) - authorize(GET, "/files", permitAll) + authorize(GET, "/files/*", permitAll) authorize(GET, "/users/*/icon.jpg", permitAll) authorize(GET, "/users/*/header.jpg", permitAll) authorize(GET, "/api/v1/accounts/verify_credentials", hasAnyScope("read", "read:accounts")) + authorize(GET, "/api/v1/accounts/*", permitAll) + authorize(GET, "/api/v1/accounts/*/statuses", permitAll) authorize(POST, "/api/v1/media", hasAnyScope("write", "write:media")) authorize(POST, "/api/v1/statuses", hasAnyScope("write", "write:statuses")) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt index 7a3a6820..946a6710 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountApiService.kt @@ -9,6 +9,7 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.* import dev.usbharu.hideout.mastodon.query.StatusQueryService import org.slf4j.LoggerFactory import org.springframework.stereotype.Service +import kotlin.math.min @Service interface AccountApiService { @@ -126,17 +127,18 @@ class AccountApiServiceImpl( return@transaction accountService.findById(id) } - override suspend fun relationships(userid: Long, id: List, withSuspended: Boolean): List { + override suspend fun relationships(userid: Long, id: List, withSuspended: Boolean): List = + transaction.transaction { if (id.isEmpty()) { - return emptyList() + return@transaction emptyList() } logger.warn("id is too long! ({}) truncate to 20", id.size) - val subList = id.subList(0, 20) + val subList = id.subList(0, min(id.size, 20)) - return subList.map { + return@transaction subList.map { val alreadyFollow = followerQueryService.alreadyFollow(userid, it) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountService.kt index a7f5f766..72050167 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/account/AccountService.kt @@ -1,5 +1,6 @@ package dev.usbharu.hideout.mastodon.service.account +import dev.usbharu.hideout.application.config.ApplicationConfig import dev.usbharu.hideout.core.query.UserQueryService import dev.usbharu.hideout.domain.mastodon.model.generated.Account import org.springframework.stereotype.Service @@ -10,9 +11,14 @@ interface AccountService { } @Service -class AccountServiceImpl(private val userQueryService: UserQueryService) : AccountService { +class AccountServiceImpl( + private val userQueryService: UserQueryService, + private val applicationConfig: ApplicationConfig +) : AccountService { override suspend fun findById(id: Long): Account { val findById = userQueryService.findById(id) + val userUrl = applicationConfig.url.toString() + "/users/" + findById.id.toString() + return Account( id = findById.id.toString(), username = findById.name, @@ -20,10 +26,10 @@ class AccountServiceImpl(private val userQueryService: UserQueryService) : Accou url = findById.url, displayName = findById.screenName, note = findById.description, - avatar = findById.url + "/icon.jpg", - avatarStatic = findById.url + "/icon.jpg", - header = findById.url + "/header.jpg", - headerStatic = findById.url + "/header.jpg", + avatar = "$userUrl/icon.jpg", + avatarStatic = "$userUrl/icon.jpg", + header = "$userUrl/header.jpg", + headerStatic = "$userUrl/header.jpg", locked = false, fields = emptyList(), emojis = emptyList(), diff --git a/src/main/resources/openapi/mastodon.yaml b/src/main/resources/openapi/mastodon.yaml index 5d39ad40..3049c1d9 100644 --- a/src/main/resources/openapi/mastodon.yaml +++ b/src/main/resources/openapi/mastodon.yaml @@ -215,7 +215,7 @@ paths: - "read:follows" parameters: - in: query - name: id + name: id[] required: false schema: type: array