...
This commit is contained in:
parent
a11aa8fbd0
commit
3dcb077e2f
@ -17,7 +17,7 @@ class AppConfig : WebMvcConfigurer {
|
||||
@Value("\${resource.location}")
|
||||
private val resourceLocation: String? = null
|
||||
|
||||
val cacheControl: CacheControl = CacheControl.maxAge(Duration.ofDays(365))
|
||||
val cacheControl: CacheControl = CacheControl.maxAge(Duration.ofHours(1))
|
||||
|
||||
@Bean
|
||||
fun authInterceptor(): BumsInterceptor {
|
||||
|
||||
@ -218,7 +218,7 @@ class BlogController() {
|
||||
val firstImg: Element? = doc.select("img")?.first()
|
||||
val imgSrc: String = firstImg?.attr("src") ?: ""
|
||||
it.image = imgSrc
|
||||
it.thumb = imgSrc.replaceBeforeLast(".", "_thumbnail.")
|
||||
it.thumb = imgSrc.replace(imgSrc.split("/").last(), imgSrc.split("/").last().replace(".","_thumbnail."))
|
||||
generateThumbnail(imgSrc.split("/").last(), 200)
|
||||
it.html = doc.text()
|
||||
}
|
||||
@ -233,13 +233,15 @@ class BlogController() {
|
||||
fun generateThumbnail(originalPath: String, targetWidth: Int) {
|
||||
try {
|
||||
val originalFile = File("$uploadPath${File.separator}$originalPath")
|
||||
|
||||
println("origin ${originalPath}")
|
||||
println("thumb ${originalPath
|
||||
.replace(".", "_thumbnail.")}")
|
||||
// 썸네일 경로 생성 (예: /upload/uuid.jpg → /upload/uuid_thumbnail.jpg)
|
||||
val thumbnailPath = originalFile.path
|
||||
.replaceBeforeLast(".", "_thumbnail.")
|
||||
val thumbnailPath = originalPath
|
||||
.replace(".", "_thumbnail.")
|
||||
|
||||
|
||||
val thumbnailFile = File(thumbnailPath)
|
||||
val thumbnailFile = File("$uploadPath${File.separator}$thumbnailPath")
|
||||
// 썸네일 이미 존재하면 종료
|
||||
if (thumbnailFile.exists()) {
|
||||
println("썸네일 이미 존재: $thumbnailPath")
|
||||
@ -257,7 +259,7 @@ class BlogController() {
|
||||
Thumbnails.of(originalFile)
|
||||
.width(targetWidth)
|
||||
.keepAspectRatio(true)
|
||||
.toFile(thumbnailPath)
|
||||
.toFile(thumbnailFile)
|
||||
|
||||
println("썸네일 생성 완료: $thumbnailPath")
|
||||
} catch (e: IOException) {
|
||||
|
||||
@ -5,16 +5,20 @@ import jakarta.servlet.http.HttpServletResponse
|
||||
import kr.lunaticbum.back.lun.model.PostManageg
|
||||
import kr.lunaticbum.back.lun.model.ResultMV
|
||||
import kr.lunaticbum.back.lun.utils.LogService
|
||||
import net.coobird.thumbnailator.Thumbnails
|
||||
import org.commonmark.node.Node
|
||||
import org.commonmark.parser.Parser
|
||||
import org.commonmark.renderer.html.HtmlRenderer
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Element
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.data.domain.Pageable
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.URLDecoder
|
||||
|
||||
@RestController
|
||||
@ -42,6 +46,8 @@ class Home {
|
||||
val firstImg: Element? = doc.select("img")?.first()
|
||||
val imgSrc: String = firstImg?.attr("src") ?: ""
|
||||
it.image = imgSrc
|
||||
it.thumb = imgSrc.replace(imgSrc.split("/").last(), imgSrc.split("/").last().replace(".","_thumbnail."))
|
||||
generateThumbnail(imgSrc.split("/").last(), 200)
|
||||
it.html = doc.text()
|
||||
}
|
||||
it.title = if ((it.title?.length ?: 0) >= 1) it.title else ""
|
||||
@ -52,6 +58,49 @@ class Home {
|
||||
return vm
|
||||
}
|
||||
|
||||
@Value("\${image.upload.path}")
|
||||
private val uploadPath: String? = null
|
||||
|
||||
@Value("\${resource.handler}")
|
||||
private val resourceHandler: String? = null
|
||||
|
||||
fun generateThumbnail(originalPath: String, targetWidth: Int) {
|
||||
try {
|
||||
val originalFile = File("$uploadPath${File.separator}$originalPath")
|
||||
println("origin ${originalPath}")
|
||||
println("thumb ${originalPath
|
||||
.replace(".", "_thumbnail.")}")
|
||||
// 썸네일 경로 생성 (예: /upload/uuid.jpg → /upload/uuid_thumbnail.jpg)
|
||||
val thumbnailPath = originalPath
|
||||
.replace(".", "_thumbnail.")
|
||||
|
||||
|
||||
val thumbnailFile = File("$uploadPath${File.separator}$thumbnailPath")
|
||||
// 썸네일 이미 존재하면 종료
|
||||
if (thumbnailFile.exists()) {
|
||||
println("썸네일 이미 존재: $thumbnailPath")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// 원본 파일 존재 확인
|
||||
if (!originalFile.exists()) {
|
||||
println("원본 파일 없음: $originalPath")
|
||||
return
|
||||
}
|
||||
|
||||
// 썸네일 생성 (가로 기준 비율 유지)
|
||||
Thumbnails.of(originalFile)
|
||||
.width(targetWidth)
|
||||
.keepAspectRatio(true)
|
||||
.toFile(thumbnailFile)
|
||||
|
||||
println("썸네일 생성 완료: $thumbnailFile")
|
||||
} catch (e: IOException) {
|
||||
println("썸네일 생성 실패: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/h2")
|
||||
fun home2() : ResultMV {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user