From b0cfa955c77c4e36bd334324d0ccb2ff24ff549f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Nov 2018 15:16:08 +0300 Subject: versioned avatars in www --- .../server/configuration/WwwAppConfiguration.java | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/juick/server/configuration') diff --git a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java index 534154af..2286165d 100644 --- a/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java +++ b/src/main/java/com/juick/server/configuration/WwwAppConfiguration.java @@ -43,6 +43,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.resource.VersionResourceResolver; import javax.inject.Inject; +import java.net.MalformedURLException; +import java.nio.file.Paths; import java.util.Collections; import java.util.concurrent.TimeUnit; @@ -56,7 +58,7 @@ public class WwwAppConfiguration implements WebMvcConfigurer { private UserService userService; @Inject private TagService tagService; - @Value("${avatars_path:#{systemEnvironment['TEMP'] ?: 'file:/tmp/'}}") + @Value("${avatars_path:#{systemEnvironment['TEMP'] ?: '/tmp'}}") private String avatarsPath; @Bean public CaffeineCacheManager cacheManager() { @@ -126,11 +128,15 @@ public class WwwAppConfiguration implements WebMvcConfigurer { } @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry - .addResourceHandler("/**", "/i/a/**") - .addResourceLocations("classpath:/static/", avatarsPath) - .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)) - .resourceChain(false) - .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**", "/i/a/**")); + try { + registry + .addResourceHandler("/**", "/i/a/**") + .addResourceLocations("classpath:/static/", Paths.get(avatarsPath, "/a/").toUri().toURL().toString()) + .setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS)) + .resourceChain(false) + .addResolver(new VersionResourceResolver().addContentVersionStrategy("/**", "/i/a/**")); + } catch (MalformedURLException e) { + e.printStackTrace(); + } } } -- cgit v1.2.3