From d19a6029e21883fb60b8c8b88e95d12fe4e36059 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:23:11 +0900 Subject: [PATCH] =?UTF-8?q?style:=20=E3=82=B9=E3=82=BF=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=82=92=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- detekt.yml | 1 + .../dev/usbharu/hideout/config/AwsConfig.kt | 2 +- .../domain/model/hideout/dto/SavedMedia.kt | 1 - .../hideout/repository/MediaRepositoryImpl.kt | 18 +++++++++--------- .../repository/ReactionRepositoryImpl.kt | 1 - .../api/mastodon/MediaApiServiceImpl.kt | 17 ++++++++--------- .../media/FileTypeDeterminationService.kt | 1 - .../hideout/service/media/MediaServiceImpl.kt | 8 ++++---- .../media/converter/MediaProcessServiceImpl.kt | 4 ++-- 9 files changed, 25 insertions(+), 28 deletions(-) diff --git a/detekt.yml b/detekt.yml index 26af6de1..658f1b3b 100644 --- a/detekt.yml +++ b/detekt.yml @@ -3,6 +3,7 @@ build: weights: Indentation: 0 MagicNumber: 0 + InjectDispatcher: 0 style: ClassOrdering: diff --git a/src/main/kotlin/dev/usbharu/hideout/config/AwsConfig.kt b/src/main/kotlin/dev/usbharu/hideout/config/AwsConfig.kt index ce9ad5a3..b697bb61 100644 --- a/src/main/kotlin/dev/usbharu/hideout/config/AwsConfig.kt +++ b/src/main/kotlin/dev/usbharu/hideout/config/AwsConfig.kt @@ -10,7 +10,7 @@ import java.net.URI @Configuration class AwsConfig { @Bean - fun s3(awsConfig: StorageConfig): S3Client { + fun s3Client(awsConfig: StorageConfig): S3Client { return S3Client.builder() .endpointOverride(URI.create(awsConfig.endpoint)) .region(Region.of(awsConfig.region)) diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/SavedMedia.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/SavedMedia.kt index 60ea05b8..b8ab7490 100644 --- a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/SavedMedia.kt +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/dto/SavedMedia.kt @@ -9,7 +9,6 @@ class SuccessSavedMedia( ) : SavedMedia(true) - class FaildSavedMedia( val reason: String, val description: String, diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/MediaRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/MediaRepositoryImpl.kt index f2ffb720..610d3e5a 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/MediaRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/MediaRepositoryImpl.kt @@ -1,6 +1,5 @@ package dev.usbharu.hideout.repository - import dev.usbharu.hideout.domain.model.hideout.dto.FileType import dev.usbharu.hideout.exception.FailedToGetResourcesException import dev.usbharu.hideout.service.core.IdGenerateService @@ -17,7 +16,8 @@ class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : Me override suspend fun save(media: EntityMedia): EntityMedia { if (Media.select { Media.id eq media.id - }.singleOrNull() != null) { + }.singleOrNull() != null + ) { Media.update({ Media.id eq media.id }) { it[Media.name] = media.name it[Media.url] = media.url @@ -58,13 +58,13 @@ class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : Me fun ResultRow.toMedia(): EntityMedia { return EntityMedia( - this[Media.id], - this[Media.name], - this[Media.url], - this[Media.remoteUrl], - this[Media.thumbnailUrl], - FileType.values().first { it.ordinal == this[Media.type] }, - this[Media.blurhash], + id = this[Media.id], + name = this[Media.name], + url = this[Media.url], + remoteUrl = this[Media.remoteUrl], + thumbnailUrl = this[Media.thumbnailUrl], + type = FileType.values().first { it.ordinal == this[Media.type] }, + blurHash = this[Media.blurhash], ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt index 866feaf3..34789884 100644 --- a/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/repository/ReactionRepositoryImpl.kt @@ -12,7 +12,6 @@ class ReactionRepositoryImpl( private val idGenerateService: IdGenerateService ) : ReactionRepository { - override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun save(reaction: Reaction): Reaction { diff --git a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/MediaApiServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/MediaApiServiceImpl.kt index ae4c444e..ab4d07de 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/MediaApiServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/api/mastodon/MediaApiServiceImpl.kt @@ -13,7 +13,6 @@ class MediaApiServiceImpl(private val mediaService: MediaService, private val tr override suspend fun postMedia(media: Media): MediaAttachment { return transaction.transaction { - val uploadLocalMedia = mediaService.uploadLocalMedia(media) val type = when (uploadLocalMedia.type) { FileType.Image -> MediaAttachment.Type.image @@ -22,14 +21,14 @@ class MediaApiServiceImpl(private val mediaService: MediaService, private val tr FileType.Unknown -> MediaAttachment.Type.unknown } return@transaction MediaAttachment( - uploadLocalMedia.id.toString(), - type, - uploadLocalMedia.url, - uploadLocalMedia.thumbnailUrl, - null, - media.description, - uploadLocalMedia.blurHash, - uploadLocalMedia.url + id = uploadLocalMedia.id.toString(), + type = type, + url = uploadLocalMedia.url, + previewUrl = uploadLocalMedia.thumbnailUrl, + remoteUrl = null, + description = media.description, + blurhash = uploadLocalMedia.blurHash, + textUrl = uploadLocalMedia.url ) } } diff --git a/src/main/kotlin/dev/usbharu/hideout/service/media/FileTypeDeterminationService.kt b/src/main/kotlin/dev/usbharu/hideout/service/media/FileTypeDeterminationService.kt index 19a7feb6..5849feea 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/FileTypeDeterminationService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/FileTypeDeterminationService.kt @@ -4,5 +4,4 @@ import dev.usbharu.hideout.domain.model.hideout.dto.FileType interface FileTypeDeterminationService { fun fileType(byteArray: ByteArray, filename: String, contentType: String?): FileType - } 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 2ed7d274..313bb8e1 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/media/MediaServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/media/MediaServiceImpl.kt @@ -28,7 +28,9 @@ class MediaServiceImpl( private val mediaProcessService: MediaProcessService ) : MediaService { override suspend fun uploadLocalMedia(media: Media): EntityMedia { - logger.info("Media upload. filename:${media.file.name} size:${media.file.size} contentType:${media.file.contentType}") + logger.info( + "Media upload. filename:${media.file.name} size:${media.file.size} contentType:${media.file.contentType}" + ) if (media.file.size == 0L) { throw MediaFileSizeIsZeroException("Media file size is zero.") @@ -85,9 +87,7 @@ class MediaServiceImpl( ) } - override suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia) { - - } + override suspend fun uploadRemoteMedia(remoteMedia: RemoteMedia) = Unit companion object { private val logger = LoggerFactory.getLogger(MediaServiceImpl::class.java) 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 6ae5d834..c32688d5 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 @@ -19,7 +19,6 @@ class MediaProcessServiceImpl( file: ByteArray, thumbnail: ByteArray? ): ProcessedMedia { - val fileInputStream = try { mediaConverterRoot.convert(fileType, contentType, filename, file.inputStream().buffered()) } catch (e: Exception) { @@ -33,7 +32,8 @@ class MediaProcessServiceImpl( null } return ProcessedMedia( - fileInputStream, thumbnailGenerateService.generate( + fileInputStream, + thumbnailGenerateService.generate( thumbnailInputStream?.byteArray ?: file, 2048, 2048