forked from Cookies_Github_mirror/AquaDX
[+] Serve uploads directory
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user