style: スタイルを調整

This commit is contained in:
usbharu 2023-10-05 12:23:11 +09:00
parent 7c66ceac00
commit d19a6029e2
9 changed files with 25 additions and 28 deletions

View File

@ -3,6 +3,7 @@ build:
weights: weights:
Indentation: 0 Indentation: 0
MagicNumber: 0 MagicNumber: 0
InjectDispatcher: 0
style: style:
ClassOrdering: ClassOrdering:

View File

@ -10,7 +10,7 @@ import java.net.URI
@Configuration @Configuration
class AwsConfig { class AwsConfig {
@Bean @Bean
fun s3(awsConfig: StorageConfig): S3Client { fun s3Client(awsConfig: StorageConfig): S3Client {
return S3Client.builder() return S3Client.builder()
.endpointOverride(URI.create(awsConfig.endpoint)) .endpointOverride(URI.create(awsConfig.endpoint))
.region(Region.of(awsConfig.region)) .region(Region.of(awsConfig.region))

View File

@ -9,7 +9,6 @@ class SuccessSavedMedia(
) : ) :
SavedMedia(true) SavedMedia(true)
class FaildSavedMedia( class FaildSavedMedia(
val reason: String, val reason: String,
val description: String, val description: String,

View File

@ -1,6 +1,5 @@
package dev.usbharu.hideout.repository package dev.usbharu.hideout.repository
import dev.usbharu.hideout.domain.model.hideout.dto.FileType import dev.usbharu.hideout.domain.model.hideout.dto.FileType
import dev.usbharu.hideout.exception.FailedToGetResourcesException import dev.usbharu.hideout.exception.FailedToGetResourcesException
import dev.usbharu.hideout.service.core.IdGenerateService 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 { override suspend fun save(media: EntityMedia): EntityMedia {
if (Media.select { if (Media.select {
Media.id eq media.id Media.id eq media.id
}.singleOrNull() != null) { }.singleOrNull() != null
) {
Media.update({ Media.id eq media.id }) { Media.update({ Media.id eq media.id }) {
it[Media.name] = media.name it[Media.name] = media.name
it[Media.url] = media.url it[Media.url] = media.url
@ -58,13 +58,13 @@ class MediaRepositoryImpl(private val idGenerateService: IdGenerateService) : Me
fun ResultRow.toMedia(): EntityMedia { fun ResultRow.toMedia(): EntityMedia {
return EntityMedia( return EntityMedia(
this[Media.id], id = this[Media.id],
this[Media.name], name = this[Media.name],
this[Media.url], url = this[Media.url],
this[Media.remoteUrl], remoteUrl = this[Media.remoteUrl],
this[Media.thumbnailUrl], thumbnailUrl = this[Media.thumbnailUrl],
FileType.values().first { it.ordinal == this[Media.type] }, type = FileType.values().first { it.ordinal == this[Media.type] },
this[Media.blurhash], blurHash = this[Media.blurhash],
) )
} }
} }

View File

@ -12,7 +12,6 @@ class ReactionRepositoryImpl(
private val idGenerateService: IdGenerateService private val idGenerateService: IdGenerateService
) : ReactionRepository { ) : ReactionRepository {
override suspend fun generateId(): Long = idGenerateService.generateId() override suspend fun generateId(): Long = idGenerateService.generateId()
override suspend fun save(reaction: Reaction): Reaction { override suspend fun save(reaction: Reaction): Reaction {

View File

@ -13,7 +13,6 @@ class MediaApiServiceImpl(private val mediaService: MediaService, private val tr
override suspend fun postMedia(media: Media): MediaAttachment { override suspend fun postMedia(media: Media): MediaAttachment {
return transaction.transaction { return transaction.transaction {
val uploadLocalMedia = mediaService.uploadLocalMedia(media) val uploadLocalMedia = mediaService.uploadLocalMedia(media)
val type = when (uploadLocalMedia.type) { val type = when (uploadLocalMedia.type) {
FileType.Image -> MediaAttachment.Type.image FileType.Image -> MediaAttachment.Type.image
@ -22,14 +21,14 @@ class MediaApiServiceImpl(private val mediaService: MediaService, private val tr
FileType.Unknown -> MediaAttachment.Type.unknown FileType.Unknown -> MediaAttachment.Type.unknown
} }
return@transaction MediaAttachment( return@transaction MediaAttachment(
uploadLocalMedia.id.toString(), id = uploadLocalMedia.id.toString(),
type, type = type,
uploadLocalMedia.url, url = uploadLocalMedia.url,
uploadLocalMedia.thumbnailUrl, previewUrl = uploadLocalMedia.thumbnailUrl,
null, remoteUrl = null,
media.description, description = media.description,
uploadLocalMedia.blurHash, blurhash = uploadLocalMedia.blurHash,
uploadLocalMedia.url textUrl = uploadLocalMedia.url
) )
} }
} }

View File

@ -4,5 +4,4 @@ import dev.usbharu.hideout.domain.model.hideout.dto.FileType
interface FileTypeDeterminationService { interface FileTypeDeterminationService {
fun fileType(byteArray: ByteArray, filename: String, contentType: String?): FileType fun fileType(byteArray: ByteArray, filename: String, contentType: String?): FileType
} }

View File

@ -28,7 +28,9 @@ class MediaServiceImpl(
private val mediaProcessService: MediaProcessService private val mediaProcessService: MediaProcessService
) : MediaService { ) : MediaService {
override suspend fun uploadLocalMedia(media: Media): EntityMedia { 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) { if (media.file.size == 0L) {
throw MediaFileSizeIsZeroException("Media file size is zero.") 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 { companion object {
private val logger = LoggerFactory.getLogger(MediaServiceImpl::class.java) private val logger = LoggerFactory.getLogger(MediaServiceImpl::class.java)

View File

@ -19,7 +19,6 @@ class MediaProcessServiceImpl(
file: ByteArray, file: ByteArray,
thumbnail: ByteArray? thumbnail: ByteArray?
): ProcessedMedia { ): ProcessedMedia {
val fileInputStream = try { val fileInputStream = try {
mediaConverterRoot.convert(fileType, contentType, filename, file.inputStream().buffered()) mediaConverterRoot.convert(fileType, contentType, filename, file.inputStream().buffered())
} catch (e: Exception) { } catch (e: Exception) {
@ -33,7 +32,8 @@ class MediaProcessServiceImpl(
null null
} }
return ProcessedMedia( return ProcessedMedia(
fileInputStream, thumbnailGenerateService.generate( fileInputStream,
thumbnailGenerateService.generate(
thumbnailInputStream?.byteArray ?: file, thumbnailInputStream?.byteArray ?: file,
2048, 2048,
2048 2048