From ef00cfbddd8f666c4b24697bd7e82374db79303c Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Wed, 6 Mar 2024 00:07:57 -0500 Subject: [PATCH] [+] Serve uploads directory --- .../java/icu/samnyan/aqua/net/utils/PathProps.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt b/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt index fa32727f..8746d234 100644 --- a/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt +++ b/src/main/java/icu/samnyan/aqua/net/utils/PathProps.kt @@ -4,6 +4,8 @@ import ext.path import jakarta.annotation.PostConstruct import org.springframework.boot.context.properties.ConfigurationProperties import org.springframework.context.annotation.Configuration +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer @Configuration @ConfigurationProperties(prefix = "paths") @@ -18,4 +20,17 @@ class PathProps { mai2Portrait = mai2Portrait.path().apply { toFile().mkdirs() }.toString() aquaNetPortrait = aquaNetPortrait.path().apply { toFile().mkdirs() }.toString() } +} + +@Configuration +class UploadStatic(val paths: PathProps): WebMvcConfigurer { + override fun addResourceHandlers(registry: ResourceHandlerRegistry) { + mapOf( + "/uploads/net/portrait/**" to paths.aquaNetPortrait, + "/uploads/mai2/portrait/**" to paths.mai2Portrait, + "/uploads/mai2/plays/**" to paths.mai2Plays + ).forEach { (k, v) -> + registry.addResourceHandler(k).addResourceLocations("file:$v").setCachePeriod(10).resourceChain(true) + } + } } \ No newline at end of file