Skip to content

Commit

Permalink
[Feature/512] 기존 유저의 블러 처리 강도 높이는 API 구현한다 (#513)
Browse files Browse the repository at this point in the history
  • Loading branch information
miseongk authored Oct 14, 2024
1 parent e318ca6 commit 570275b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.nexters.bottles.api.admin.controller

import com.nexters.bottles.api.admin.facade.AdminFacade
import com.nexters.bottles.api.admin.facade.dto.*
import com.nexters.bottles.api.admin.facade.dto.CreateCustomTokenRequest
import com.nexters.bottles.api.admin.facade.dto.CustomTokenResponse
import com.nexters.bottles.api.admin.facade.dto.ExpireTokenRequest
import com.nexters.bottles.api.admin.facade.dto.FcmTestRequest
import com.nexters.bottles.api.admin.facade.dto.ForceAfterProfileResponse
import com.nexters.bottles.api.admin.facade.dto.PushMessageRequest
import com.nexters.bottles.api.global.interceptor.AuthRequired
import com.nexters.bottles.api.global.resolver.AuthUserId
import io.swagger.annotations.ApiOperation
Expand Down Expand Up @@ -86,4 +91,10 @@ class AdminController(
fun makeBlurImage(@PathVariable userId: Long) {
adminFacade.makeBlurImage(userId)
}

@ApiOperation("블러 강도 높이기")
@PostMapping("/blur-image/more/{userId}")
fun makeMoreBlurImage(@PathVariable userId: Long) {
adminFacade.makeMoreBlurImage(userId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,42 @@ class AdminFacade(
}
}

fun makeMoreBlurImage(userId: Long) {
userProfileService.findAllWithImage()
.filter { it.user.id > userId }
.filter { it.imageUrl != null }
.forEach {
val imageFile = amazonS3FileService.downloadAsMultipartFile(it.imageUrl!!.substringAfterLast("/"))
val path = makeFirstPathWithUserId(imageFile, it.user.id)
val imageUrl = imageUploader.upload(imageFile, path).toString();
val blurredImageUrl = imageUrl.replace(PREFIX_ORIGINAL_IMAGE_MAIN, PREFIX_BLURRED_IMAGE)

userProfileService.upsertImageUrls(it.id, listOf(imageUrl), blurredImageUrl)
}
}

fun makePathWithUserId(
file: MultipartFile,
userId: Long
) = "" + userId + FILE_NAME_DELIMITER + LocalDateTime.now()
.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) + FILE_NAME_DELIMITER + file.originalFilename

private fun makeFirstPathWithUserId(
file: MultipartFile,
userId: Long
): String {
val filePath = "$PREFIX_ORIGINAL_IMAGE_MAIN${userId}${FILE_NAME_DELIMITER}${
LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
}${FILE_NAME_DELIMITER}${file.originalFilename}"

return filePath
}

companion object {
private const val FILE_NAME_DELIMITER = "_"
private const val PREFIX_ORIGINAL_IMAGE_MAIN = "original/main/"
private const val PREFIX_ORIGINAL_IMAGE = "original/"
private const val PREFIX_BLURRED_IMAGE = "blur/"
private const val mockMaleUserId = 1L
private const val mockFemaleUserId1 = 2L
private const val mockFemaleUserId2 = 9L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ImageProcessor {
}

private fun applyGaussianBlur(image: BufferedImage): BufferedImage {
val matrix = FloatArray(1225) { 1 / 1225f }
val matrix = FloatArray(80 * 80) { 1f / (80 * 80) }
val size = sqrt(matrix.size.toDouble()).toInt()
val kernel = Kernel(size, size, matrix)
val convolveOp = ConvolveOp(kernel, ConvolveOp.EDGE_ZERO_FILL, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class UserProfileService(
prevImageUrls = it.imageUrls,
prevBlurredImageUrl = it.blurredImageUrl
)
it.imageUrl = imageUrls[0]
it.imageUrls = imageUrls
it.blurredImageUrl = blurredImageUrl
applicationEventPublisher.publishEvent(uploadImageEventDto)
Expand Down

0 comments on commit 570275b

Please sign in to comment.