From d9f0ce074fc8010e8000ece1028d056537ea1e02 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 11 Oct 2023 11:02:57 +0900 Subject: [PATCH] style: fix lint --- build.gradle.kts | 2 +- detekt.yml | 5 +++++ .../usbharu/hideout/config/JsonOrFormBind.kt | 2 +- .../config/JsonOrFormModelMethodProcessor.kt | 10 +++++----- .../mastodon/MastodonStatusesApiContoller.kt | 11 +++++++--- .../hideout/domain/model/ap/Document.kt | 6 ++---- .../usbharu/hideout/domain/model/ap/Note.kt | 4 +++- .../domain/model/mastodon/StatusesRequest.kt | 6 +++++- .../query/mastodon/StatusQueryServiceImpl.kt | 18 +++++++++-------- .../api/mastodon/StatusesApiService.kt | 20 +++++++++---------- .../hideout/service/media/MediaServiceImpl.kt | 1 + .../hideout/service/media/S3MediaDataStore.kt | 10 +++++----- .../converter/MediaProcessServiceImpl.kt | 1 + 13 files changed, 57 insertions(+), 39 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index a5b224ee..e324753a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -156,7 +156,7 @@ detekt { parallel = true config = files("detekt.yml") buildUponDefaultConfig = true - basePath = rootDir.absolutePath + basePath = "${rootDir.absolutePath}/src/" autoCorrect = true } diff --git a/detekt.yml b/detekt.yml index 658f1b3b..c1b54432 100644 --- a/detekt.yml +++ b/detekt.yml @@ -4,6 +4,7 @@ build: Indentation: 0 MagicNumber: 0 InjectDispatcher: 0 + EnumEntryNameCase: 0 style: ClassOrdering: @@ -161,3 +162,7 @@ potential-bugs: HasPlatformType: active: false + +coroutines: + RedundantSuspendModifier: + active: false diff --git a/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormBind.kt b/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormBind.kt index 10460b20..02ff8520 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormBind.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormBind.kt @@ -3,4 +3,4 @@ package dev.usbharu.hideout.config @MustBeDocumented @Retention(AnnotationRetention.RUNTIME) @Target(AnnotationTarget.VALUE_PARAMETER) -annotation class JsonOrFormBind() +annotation class JsonOrFormBind diff --git a/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormModelMethodProcessor.kt b/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormModelMethodProcessor.kt index d7b4943f..6d1e7382 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormModelMethodProcessor.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/JsonOrFormModelMethodProcessor.kt @@ -9,16 +9,16 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver import org.springframework.web.method.support.ModelAndViewContainer import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor +@Suppress("TooGenericExceptionCaught") class JsonOrFormModelMethodProcessor( private val modelAttributeMethodProcessor: ModelAttributeMethodProcessor, private val requestResponseBodyMethodProcessor: RequestResponseBodyMethodProcessor ) : HandlerMethodArgumentResolver { - override fun supportsParameter(parameter: MethodParameter): Boolean { - return parameter.hasParameterAnnotation(JsonOrFormBind::class.java) - } - private val isJsonRegex = Regex("application/((\\w*)\\+)?json") + override fun supportsParameter(parameter: MethodParameter): Boolean = + parameter.hasParameterAnnotation(JsonOrFormBind::class.java) + override fun resolveArgument( parameter: MethodParameter, mavContainer: ModelAndViewContainer?, @@ -39,7 +39,7 @@ class JsonOrFormModelMethodProcessor( return try { modelAttributeMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) - } catch (e: Exception) { + } catch (ignore: Exception) { try { requestResponseBodyMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) } catch (e: Exception) { diff --git a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt index 5d3171cd..7b537601 100644 --- a/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt +++ b/src/main/kotlin/dev/usbharu/hideout/controller/mastodon/MastodonStatusesApiContoller.kt @@ -2,6 +2,7 @@ package dev.usbharu.hideout.controller.mastodon import dev.usbharu.hideout.controller.mastodon.generated.StatusApi import dev.usbharu.hideout.domain.mastodon.model.generated.Status +import dev.usbharu.hideout.domain.model.mastodon.StatusesRequest import dev.usbharu.hideout.service.api.mastodon.StatusesApiService import kotlinx.coroutines.runBlocking import org.springframework.http.HttpStatus @@ -12,13 +13,17 @@ import org.springframework.stereotype.Controller @Controller class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiService) : StatusApi { - override fun apiV1StatusesPost(statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest): ResponseEntity = - runBlocking { + override fun apiV1StatusesPost(devUsbharuHideoutDomainModelMastodonStatusesRequest: StatusesRequest): ResponseEntity { + return runBlocking { val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt ResponseEntity( - statusesApiService.postStatus(statusesRequest, jwt.getClaim("uid").toLong()), + statusesApiService.postStatus( + devUsbharuHideoutDomainModelMastodonStatusesRequest, + jwt.getClaim("uid").toLong() + ), HttpStatus.OK ) } + } } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Document.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Document.kt index 0c4ac36f..0dacaf00 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Document.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Document.kt @@ -1,6 +1,6 @@ package dev.usbharu.hideout.domain.model.ap -class Document : Object { +open class Document : Object { var mediaType: String? = null var url: String? = null @@ -39,7 +39,5 @@ class Document : Object { return result } - override fun toString(): String { - return "Document(mediaType=$mediaType, url=$url) ${super.toString()}" - } + override fun toString(): String = "Document(mediaType=$mediaType, url=$url) ${super.toString()}" } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt index caba5383..930a3da7 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/ap/Note.kt @@ -71,6 +71,8 @@ open class Note : Object { } override fun toString(): String { - return "Note(attributedTo=$attributedTo, attachment=$attachment, content=$content, published=$published, to=$to, cc=$cc, sensitive=$sensitive, inReplyTo=$inReplyTo) ${super.toString()}" + return "Note(attributedTo=$attributedTo, attachment=$attachment, " + + "content=$content, published=$published, to=$to, cc=$cc, sensitive=$sensitive," + + " inReplyTo=$inReplyTo) ${super.toString()}" } } diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/mastodon/StatusesRequest.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/mastodon/StatusesRequest.kt index 0deca5a8..0003af2d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/mastodon/StatusesRequest.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/mastodon/StatusesRequest.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.domain.model.mastodon import com.fasterxml.jackson.annotation.JsonProperty import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequestPoll +@Suppress("VariableNaming") class StatusesRequest { @JsonProperty("status") var status: String? = null @@ -61,9 +62,12 @@ class StatusesRequest { } override fun toString(): String { - return "StatusesRequest(status=$status, mediaIds=$media_ids, poll=$poll, inReplyToId=$in_reply_to_id, sensitive=$sensitive, spoilerText=$spoiler_text, visibility=$visibility, language=$language, scheduledAt=$scheduled_at)" + return "StatusesRequest(status=$status, mediaIds=$media_ids, poll=$poll, inReplyToId=$in_reply_to_id, " + + "sensitive=$sensitive, spoilerText=$spoiler_text, visibility=$visibility, language=$language," + + " scheduledAt=$scheduled_at)" } + @Suppress("EnumNaming") enum class Visibility { `public`, unlisted, diff --git a/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt index 7b045508..5fba667c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/query/mastodon/StatusQueryServiceImpl.kt @@ -16,6 +16,7 @@ class StatusQueryServiceImpl : StatusQueryService { @Suppress("LongMethod") override suspend fun findByPostIds(ids: List): List = findByPostIdsWithMediaAttachments(ids) + @Suppress("unused") private suspend fun internalFindByPostIds(ids: List): List { val pairs = Posts .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) @@ -46,6 +47,7 @@ class StatusQueryServiceImpl : StatusQueryService { } } + @Suppress("FunctionMaxLength") private suspend fun findByPostIdsWithMediaAttachments(ids: List): List { val pairs = Posts .innerJoin(PostsMedia, onColumn = { Posts.id }, otherColumn = { PostsMedia.postId }) @@ -59,19 +61,19 @@ class StatusQueryServiceImpl : StatusQueryService { mediaAttachments = it.map { it.toMedia().let { MediaAttachment( - it.id.toString(), - when (it.type) { + id = it.id.toString(), + type = when (it.type) { FileType.Image -> MediaAttachment.Type.image FileType.Video -> MediaAttachment.Type.video FileType.Audio -> MediaAttachment.Type.audio FileType.Unknown -> MediaAttachment.Type.unknown }, - it.url, - it.thumbnailUrl, - it.remoteUrl, - "", - it.blurHash, - it.url + url = it.url, + previewUrl = it.thumbnailUrl, + remoteUrl = it.remoteUrl, + description = "", + blurhash = it.blurHash, + textUrl = it.url ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt index 93d1634f..039dfc2c 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/StatusesApiService.kt @@ -34,7 +34,7 @@ class StatsesApiServiceImpl( private val transaction: Transaction ) : StatusesApiService { - @Suppress("LongMethod") + @Suppress("LongMethod", "CyclomaticComplexMethod") override suspend fun postStatus( statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest, userId: Long @@ -55,7 +55,7 @@ class StatsesApiServiceImpl( visibility = visibility, repolyId = statusesRequest.in_reply_to_id?.toLongOrNull(), userId = userId, - mediaIds = statusesRequest.media_ids.orEmpty().map { it.toLong() } + mediaIds = statusesRequest.media_ids.map { it.toLong() } ) ) val account = accountService.findById(userId) @@ -83,19 +83,19 @@ class StatsesApiServiceImpl( mediaRepository.findById(mediaId) }.map { MediaAttachment( - it.id.toString(), - when (it.type) { + id = it.id.toString(), + type = when (it.type) { FileType.Image -> MediaAttachment.Type.image FileType.Video -> MediaAttachment.Type.video FileType.Audio -> MediaAttachment.Type.audio FileType.Unknown -> MediaAttachment.Type.unknown }, - it.url, - it.thumbnailUrl, - it.remoteUrl, - "", - it.blurHash, - it.url + url = it.url, + previewUrl = it.thumbnailUrl, + remoteUrl = it.remoteUrl, + description = "", + blurhash = it.blurHash, + textUrl = it.url ) } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/media/MediaServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/media/MediaServiceImpl.kt index 313bb8e1..b208f2f3 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/MediaServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/MediaServiceImpl.kt @@ -20,6 +20,7 @@ import javax.imageio.ImageIO import dev.usbharu.hideout.domain.model.hideout.entity.Media as EntityMedia @Service +@Suppress("TooGenericExceptionCaught") class MediaServiceImpl( private val mediaDataStore: MediaDataStore, private val fileTypeDeterminationService: FileTypeDeterminationService, diff --git a/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt b/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt index 4a20efbb..6dd357c5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/S3MediaDataStore.kt @@ -29,7 +29,7 @@ class S3MediaDataStore(private val s3Client: S3Client, private val storageConfig .key(thumbnailKey) .build() - val pairList = withContext(Dispatchers.IO) { + withContext(Dispatchers.IO) { awaitAll( async { if (dataMediaSave.thumbnailInputStream != null) { @@ -37,19 +37,19 @@ class S3MediaDataStore(private val s3Client: S3Client, private val storageConfig thumbnailUploadRequest, RequestBody.fromBytes(dataMediaSave.thumbnailInputStream) ) - "thumbnail" to s3Client.utilities() + s3Client.utilities() .getUrl(GetUrlRequest.builder().bucket(storageConfig.bucket).key(thumbnailKey).build()) } else { - "thumbnail" to null + null } }, async { s3Client.putObject(fileUploadRequest, RequestBody.fromBytes(dataMediaSave.fileInputStream)) - "file" to s3Client.utilities() + s3Client.utilities() .getUrl(GetUrlRequest.builder().bucket(storageConfig.bucket).key(dataMediaSave.name).build()) } ) - }.toMap() + } return SuccessSavedMedia( name = dataMediaSave.name, url = "${storageConfig.publicUrl}/${storageConfig.bucket}/${dataMediaSave.name}", diff --git a/src/main/kotlin/dev/usbharu/hideout/service/media/converter/MediaProcessServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/media/converter/MediaProcessServiceImpl.kt index c32688d5..7ad96ecd 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/converter/MediaProcessServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/converter/MediaProcessServiceImpl.kt @@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory import org.springframework.stereotype.Service @Service +@Suppress("TooGenericExceptionCaught") class MediaProcessServiceImpl( private val mediaConverterRoot: MediaConverterRoot, private val thumbnailGenerateService: ThumbnailGenerateService