From b6bb0dc8a3391442fad0124baa12799982cd6d8d Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 20 Nov 2018 19:07:59 +0300 Subject: fix api avatar urls --- src/main/java/com/juick/server/www/WebApp.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/main/java/com/juick/server/www') diff --git a/src/main/java/com/juick/server/www/WebApp.java b/src/main/java/com/juick/server/www/WebApp.java index 08c6188d..7282eeeb 100644 --- a/src/main/java/com/juick/server/www/WebApp.java +++ b/src/main/java/com/juick/server/www/WebApp.java @@ -25,6 +25,7 @@ import org.springframework.stereotype.Component; import org.springframework.web.servlet.resource.ResourceUrlProvider; import org.springframework.web.util.UriComponentsBuilder; +import javax.annotation.PostConstruct; import javax.inject.Inject; import java.util.ArrayList; import java.util.Arrays; @@ -43,6 +44,12 @@ public class WebApp { private ResourceUrlProvider resourceUrlProvider; @Value("${img_url:http://localhost:8080/i/}") private String baseImagesUri; + UriComponentsBuilder avatarBuilder; + + @PostConstruct + public void init() { + avatarBuilder = UriComponentsBuilder.fromUriString(baseImagesUri); + } public List parseTags(String tagsStr) { List tags = new ArrayList<>(); @@ -79,4 +86,9 @@ public class WebApp { } return resourceUrlProvider.getForLookupPath("/av-96.png"); } + + public String getAvatarUrl(User user) { + avatarBuilder.replacePath(getAvatarWebPath(user)); + return avatarBuilder.build().toUriString(); + } } -- cgit v1.2.3