style: fix lint

This commit is contained in:
usbharu 2023-10-11 11:02:57 +09:00
parent 63c22627c5
commit d9f0ce074f
13 changed files with 57 additions and 39 deletions

View File

@ -156,7 +156,7 @@ detekt {
parallel = true parallel = true
config = files("detekt.yml") config = files("detekt.yml")
buildUponDefaultConfig = true buildUponDefaultConfig = true
basePath = rootDir.absolutePath basePath = "${rootDir.absolutePath}/src/"
autoCorrect = true autoCorrect = true
} }

View File

@ -4,6 +4,7 @@ build:
Indentation: 0 Indentation: 0
MagicNumber: 0 MagicNumber: 0
InjectDispatcher: 0 InjectDispatcher: 0
EnumEntryNameCase: 0
style: style:
ClassOrdering: ClassOrdering:
@ -161,3 +162,7 @@ potential-bugs:
HasPlatformType: HasPlatformType:
active: false active: false
coroutines:
RedundantSuspendModifier:
active: false

View File

@ -3,4 +3,4 @@ package dev.usbharu.hideout.config
@MustBeDocumented @MustBeDocumented
@Retention(AnnotationRetention.RUNTIME) @Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.VALUE_PARAMETER) @Target(AnnotationTarget.VALUE_PARAMETER)
annotation class JsonOrFormBind() annotation class JsonOrFormBind

View File

@ -9,16 +9,16 @@ import org.springframework.web.method.support.HandlerMethodArgumentResolver
import org.springframework.web.method.support.ModelAndViewContainer import org.springframework.web.method.support.ModelAndViewContainer
import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor import org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor
@Suppress("TooGenericExceptionCaught")
class JsonOrFormModelMethodProcessor( class JsonOrFormModelMethodProcessor(
private val modelAttributeMethodProcessor: ModelAttributeMethodProcessor, private val modelAttributeMethodProcessor: ModelAttributeMethodProcessor,
private val requestResponseBodyMethodProcessor: RequestResponseBodyMethodProcessor private val requestResponseBodyMethodProcessor: RequestResponseBodyMethodProcessor
) : HandlerMethodArgumentResolver { ) : HandlerMethodArgumentResolver {
override fun supportsParameter(parameter: MethodParameter): Boolean {
return parameter.hasParameterAnnotation(JsonOrFormBind::class.java)
}
private val isJsonRegex = Regex("application/((\\w*)\\+)?json") private val isJsonRegex = Regex("application/((\\w*)\\+)?json")
override fun supportsParameter(parameter: MethodParameter): Boolean =
parameter.hasParameterAnnotation(JsonOrFormBind::class.java)
override fun resolveArgument( override fun resolveArgument(
parameter: MethodParameter, parameter: MethodParameter,
mavContainer: ModelAndViewContainer?, mavContainer: ModelAndViewContainer?,
@ -39,7 +39,7 @@ class JsonOrFormModelMethodProcessor(
return try { return try {
modelAttributeMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) modelAttributeMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory)
} catch (e: Exception) { } catch (ignore: Exception) {
try { try {
requestResponseBodyMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory) requestResponseBodyMethodProcessor.resolveArgument(parameter, mavContainer, webRequest, binderFactory)
} catch (e: Exception) { } catch (e: Exception) {

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.controller.mastodon
import dev.usbharu.hideout.controller.mastodon.generated.StatusApi import dev.usbharu.hideout.controller.mastodon.generated.StatusApi
import dev.usbharu.hideout.domain.mastodon.model.generated.Status 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 dev.usbharu.hideout.service.api.mastodon.StatusesApiService
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus
@ -12,13 +13,17 @@ import org.springframework.stereotype.Controller
@Controller @Controller
class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiService) : StatusApi { class MastodonStatusesApiContoller(private val statusesApiService: StatusesApiService) : StatusApi {
override fun apiV1StatusesPost(statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest): ResponseEntity<Status> = override fun apiV1StatusesPost(devUsbharuHideoutDomainModelMastodonStatusesRequest: StatusesRequest): ResponseEntity<Status> {
runBlocking { return runBlocking {
val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt
ResponseEntity( ResponseEntity(
statusesApiService.postStatus(statusesRequest, jwt.getClaim<String>("uid").toLong()), statusesApiService.postStatus(
devUsbharuHideoutDomainModelMastodonStatusesRequest,
jwt.getClaim<String>("uid").toLong()
),
HttpStatus.OK HttpStatus.OK
) )
} }
}
} }

View File

@ -1,6 +1,6 @@
package dev.usbharu.hideout.domain.model.ap package dev.usbharu.hideout.domain.model.ap
class Document : Object { open class Document : Object {
var mediaType: String? = null var mediaType: String? = null
var url: String? = null var url: String? = null
@ -39,7 +39,5 @@ class Document : Object {
return result return result
} }
override fun toString(): String { override fun toString(): String = "Document(mediaType=$mediaType, url=$url) ${super.toString()}"
return "Document(mediaType=$mediaType, url=$url) ${super.toString()}"
}
} }

View File

@ -71,6 +71,8 @@ open class Note : Object {
} }
override fun toString(): String { 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()}"
} }
} }

View File

@ -3,6 +3,7 @@ package dev.usbharu.hideout.domain.model.mastodon
import com.fasterxml.jackson.annotation.JsonProperty import com.fasterxml.jackson.annotation.JsonProperty
import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequestPoll import dev.usbharu.hideout.domain.mastodon.model.generated.StatusesRequestPoll
@Suppress("VariableNaming")
class StatusesRequest { class StatusesRequest {
@JsonProperty("status") @JsonProperty("status")
var status: String? = null var status: String? = null
@ -61,9 +62,12 @@ class StatusesRequest {
} }
override fun toString(): String { 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 { enum class Visibility {
`public`, `public`,
unlisted, unlisted,

View File

@ -16,6 +16,7 @@ class StatusQueryServiceImpl : StatusQueryService {
@Suppress("LongMethod") @Suppress("LongMethod")
override suspend fun findByPostIds(ids: List<Long>): List<Status> = findByPostIdsWithMediaAttachments(ids) override suspend fun findByPostIds(ids: List<Long>): List<Status> = findByPostIdsWithMediaAttachments(ids)
@Suppress("unused")
private suspend fun internalFindByPostIds(ids: List<Long>): List<Status> { private suspend fun internalFindByPostIds(ids: List<Long>): List<Status> {
val pairs = Posts val pairs = Posts
.innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id }) .innerJoin(Users, onColumn = { Posts.userId }, otherColumn = { id })
@ -46,6 +47,7 @@ class StatusQueryServiceImpl : StatusQueryService {
} }
} }
@Suppress("FunctionMaxLength")
private suspend fun findByPostIdsWithMediaAttachments(ids: List<Long>): List<Status> { private suspend fun findByPostIdsWithMediaAttachments(ids: List<Long>): List<Status> {
val pairs = Posts val pairs = Posts
.innerJoin(PostsMedia, onColumn = { Posts.id }, otherColumn = { PostsMedia.postId }) .innerJoin(PostsMedia, onColumn = { Posts.id }, otherColumn = { PostsMedia.postId })
@ -59,19 +61,19 @@ class StatusQueryServiceImpl : StatusQueryService {
mediaAttachments = it.map { mediaAttachments = it.map {
it.toMedia().let { it.toMedia().let {
MediaAttachment( MediaAttachment(
it.id.toString(), id = it.id.toString(),
when (it.type) { type = when (it.type) {
FileType.Image -> MediaAttachment.Type.image FileType.Image -> MediaAttachment.Type.image
FileType.Video -> MediaAttachment.Type.video FileType.Video -> MediaAttachment.Type.video
FileType.Audio -> MediaAttachment.Type.audio FileType.Audio -> MediaAttachment.Type.audio
FileType.Unknown -> MediaAttachment.Type.unknown FileType.Unknown -> MediaAttachment.Type.unknown
}, },
it.url, url = it.url,
it.thumbnailUrl, previewUrl = it.thumbnailUrl,
it.remoteUrl, remoteUrl = it.remoteUrl,
"", description = "",
it.blurHash, blurhash = it.blurHash,
it.url textUrl = it.url
) )
} }
} }

View File

@ -34,7 +34,7 @@ class StatsesApiServiceImpl(
private val transaction: Transaction private val transaction: Transaction
) : ) :
StatusesApiService { StatusesApiService {
@Suppress("LongMethod") @Suppress("LongMethod", "CyclomaticComplexMethod")
override suspend fun postStatus( override suspend fun postStatus(
statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest, statusesRequest: dev.usbharu.hideout.domain.model.mastodon.StatusesRequest,
userId: Long userId: Long
@ -55,7 +55,7 @@ class StatsesApiServiceImpl(
visibility = visibility, visibility = visibility,
repolyId = statusesRequest.in_reply_to_id?.toLongOrNull(), repolyId = statusesRequest.in_reply_to_id?.toLongOrNull(),
userId = userId, userId = userId,
mediaIds = statusesRequest.media_ids.orEmpty().map { it.toLong() } mediaIds = statusesRequest.media_ids.map { it.toLong() }
) )
) )
val account = accountService.findById(userId) val account = accountService.findById(userId)
@ -83,19 +83,19 @@ class StatsesApiServiceImpl(
mediaRepository.findById(mediaId) mediaRepository.findById(mediaId)
}.map { }.map {
MediaAttachment( MediaAttachment(
it.id.toString(), id = it.id.toString(),
when (it.type) { type = when (it.type) {
FileType.Image -> MediaAttachment.Type.image FileType.Image -> MediaAttachment.Type.image
FileType.Video -> MediaAttachment.Type.video FileType.Video -> MediaAttachment.Type.video
FileType.Audio -> MediaAttachment.Type.audio FileType.Audio -> MediaAttachment.Type.audio
FileType.Unknown -> MediaAttachment.Type.unknown FileType.Unknown -> MediaAttachment.Type.unknown
}, },
it.url, url = it.url,
it.thumbnailUrl, previewUrl = it.thumbnailUrl,
it.remoteUrl, remoteUrl = it.remoteUrl,
"", description = "",
it.blurHash, blurhash = it.blurHash,
it.url textUrl = it.url
) )
} }

View File

@ -20,6 +20,7 @@ import javax.imageio.ImageIO
import dev.usbharu.hideout.domain.model.hideout.entity.Media as EntityMedia import dev.usbharu.hideout.domain.model.hideout.entity.Media as EntityMedia
@Service @Service
@Suppress("TooGenericExceptionCaught")
class MediaServiceImpl( class MediaServiceImpl(
private val mediaDataStore: MediaDataStore, private val mediaDataStore: MediaDataStore,
private val fileTypeDeterminationService: FileTypeDeterminationService, private val fileTypeDeterminationService: FileTypeDeterminationService,

View File

@ -29,7 +29,7 @@ class S3MediaDataStore(private val s3Client: S3Client, private val storageConfig
.key(thumbnailKey) .key(thumbnailKey)
.build() .build()
val pairList = withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
awaitAll( awaitAll(
async { async {
if (dataMediaSave.thumbnailInputStream != null) { if (dataMediaSave.thumbnailInputStream != null) {
@ -37,19 +37,19 @@ class S3MediaDataStore(private val s3Client: S3Client, private val storageConfig
thumbnailUploadRequest, thumbnailUploadRequest,
RequestBody.fromBytes(dataMediaSave.thumbnailInputStream) RequestBody.fromBytes(dataMediaSave.thumbnailInputStream)
) )
"thumbnail" to s3Client.utilities() s3Client.utilities()
.getUrl(GetUrlRequest.builder().bucket(storageConfig.bucket).key(thumbnailKey).build()) .getUrl(GetUrlRequest.builder().bucket(storageConfig.bucket).key(thumbnailKey).build())
} else { } else {
"thumbnail" to null null
} }
}, },
async { async {
s3Client.putObject(fileUploadRequest, RequestBody.fromBytes(dataMediaSave.fileInputStream)) s3Client.putObject(fileUploadRequest, RequestBody.fromBytes(dataMediaSave.fileInputStream))
"file" to s3Client.utilities() s3Client.utilities()
.getUrl(GetUrlRequest.builder().bucket(storageConfig.bucket).key(dataMediaSave.name).build()) .getUrl(GetUrlRequest.builder().bucket(storageConfig.bucket).key(dataMediaSave.name).build())
} }
) )
}.toMap() }
return SuccessSavedMedia( return SuccessSavedMedia(
name = dataMediaSave.name, name = dataMediaSave.name,
url = "${storageConfig.publicUrl}/${storageConfig.bucket}/${dataMediaSave.name}", url = "${storageConfig.publicUrl}/${storageConfig.bucket}/${dataMediaSave.name}",

View File

@ -8,6 +8,7 @@ import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@Service @Service
@Suppress("TooGenericExceptionCaught")
class MediaProcessServiceImpl( class MediaProcessServiceImpl(
private val mediaConverterRoot: MediaConverterRoot, private val mediaConverterRoot: MediaConverterRoot,
private val thumbnailGenerateService: ThumbnailGenerateService private val thumbnailGenerateService: ThumbnailGenerateService