mirror of https://github.com/usbharu/Hideout.git
style: fix lint
This commit is contained in:
parent
63c22627c5
commit
d9f0ce074f
|
@ -156,7 +156,7 @@ detekt {
|
|||
parallel = true
|
||||
config = files("detekt.yml")
|
||||
buildUponDefaultConfig = true
|
||||
basePath = rootDir.absolutePath
|
||||
basePath = "${rootDir.absolutePath}/src/"
|
||||
autoCorrect = true
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -3,4 +3,4 @@ package dev.usbharu.hideout.config
|
|||
@MustBeDocumented
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Target(AnnotationTarget.VALUE_PARAMETER)
|
||||
annotation class JsonOrFormBind()
|
||||
annotation class JsonOrFormBind
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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<Status> =
|
||||
runBlocking {
|
||||
override fun apiV1StatusesPost(devUsbharuHideoutDomainModelMastodonStatusesRequest: StatusesRequest): ResponseEntity<Status> {
|
||||
return runBlocking {
|
||||
val jwt = SecurityContextHolder.getContext().authentication.principal as Jwt
|
||||
|
||||
ResponseEntity(
|
||||
statusesApiService.postStatus(statusesRequest, jwt.getClaim<String>("uid").toLong()),
|
||||
statusesApiService.postStatus(
|
||||
devUsbharuHideoutDomainModelMastodonStatusesRequest,
|
||||
jwt.getClaim<String>("uid").toLong()
|
||||
),
|
||||
HttpStatus.OK
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()}"
|
||||
}
|
||||
|
|
|
@ -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()}"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -16,6 +16,7 @@ class StatusQueryServiceImpl : StatusQueryService {
|
|||
@Suppress("LongMethod")
|
||||
override suspend fun findByPostIds(ids: List<Long>): List<Status> = findByPostIdsWithMediaAttachments(ids)
|
||||
|
||||
@Suppress("unused")
|
||||
private suspend fun internalFindByPostIds(ids: List<Long>): List<Status> {
|
||||
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<Long>): List<Status> {
|
||||
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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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}",
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue