aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/www
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-20 16:37:42 +0300
committerGravatar Vitaly Takmazov2018-11-20 16:37:42 +0300
commita3ec3587e1fa33e4e08da9783d9d66c55ac84550 (patch)
tree9311de2f6511421eefed3e2e10bc821d2179dbd4 /src/main/java/com/juick/server/www
parentd2b04d9b719b79a35e90b1c5569722ba5cbf794b (diff)
avatar public url
Diffstat (limited to 'src/main/java/com/juick/server/www')
-rw-r--r--src/main/java/com/juick/server/www/WebApp.java12
-rw-r--r--src/main/java/com/juick/server/www/controllers/Help.java2
-rw-r--r--src/main/java/com/juick/server/www/controllers/MessagesWWW.java39
-rw-r--r--src/main/java/com/juick/server/www/controllers/NewMessage.java2
-rw-r--r--src/main/java/com/juick/server/www/controllers/Settings.java2
-rw-r--r--src/main/java/com/juick/server/www/controllers/SignUp.java2
6 files changed, 32 insertions, 27 deletions
diff --git a/src/main/java/com/juick/server/www/WebApp.java b/src/main/java/com/juick/server/www/WebApp.java
index d2729c89..3ab09de2 100644
--- a/src/main/java/com/juick/server/www/WebApp.java
+++ b/src/main/java/com/juick/server/www/WebApp.java
@@ -20,12 +20,12 @@ import com.juick.Tag;
import com.juick.User;
import com.juick.service.TagService;
import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Value;
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.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -41,6 +41,8 @@ public class WebApp {
private TagService tagService;
@Inject
private ResourceUrlProvider resourceUrlProvider;
+ @Value("${img_url:http://localhost:8080/i/}")
+ private String baseImagesUri;
public List<Tag> parseTags(String tagsStr) {
List<Tag> tags = new ArrayList<>();
@@ -70,11 +72,15 @@ public class WebApp {
public String getScriptsUrl() {
return resourceUrlProvider.getForLookupPath("/scripts.js");
}
- public String getAvatarUrl(User user) {
+ public String getAvatarWebPath(User user) {
String avatarUri = resourceUrlProvider.getForLookupPath(String.format("/i/a/%d.png", user.getUid()));
if (StringUtils.isNotEmpty(avatarUri)) {
return avatarUri;
}
return resourceUrlProvider.getForLookupPath("/av-96.png");
}
+ public String getAvatarPublicUrl(User user) {
+ UriComponentsBuilder uri = UriComponentsBuilder.fromUriString(baseImagesUri);
+ return uri.replacePath(getAvatarWebPath(user)).toUriString();
+ }
}
diff --git a/src/main/java/com/juick/server/www/controllers/Help.java b/src/main/java/com/juick/server/www/controllers/Help.java
index e2a89bd6..12abee80 100644
--- a/src/main/java/com/juick/server/www/controllers/Help.java
+++ b/src/main/java/com/juick/server/www/controllers/Help.java
@@ -59,7 +59,7 @@ public class Help {
@PathVariable(required = false, name = "langOrPage") String langOrPage,
Model model) throws IOException, URISyntaxException {
com.juick.User visitor = UserUtils.getCurrentUser();
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String navigation = null;
if (langOrPage != null) {
diff --git a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
index 9ccd099b..ba8e7b66 100644
--- a/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
+++ b/src/main/java/com/juick/server/www/controllers/MessagesWWW.java
@@ -30,7 +30,6 @@ import com.juick.util.MessageUtils;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
-import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
@@ -72,7 +71,7 @@ public class MessagesWWW {
private WebApp webApp;
private void fillUserModel(ModelMap model, com.juick.User user, com.juick.User visitor) {
- user.setAvatar(webApp.getAvatarUrl(user));
+ user.setAvatar(webApp.getAvatarWebPath(user));
model.addAttribute("user", user);
model.addAttribute("isSubscribed", userService.isSubscribed(visitor.getUid(), user.getUid()));
model.addAttribute("isInBL", userService.isInBL(visitor.getUid(), user.getUid()));
@@ -102,7 +101,7 @@ public class MessagesWWW {
}
com.juick.User visitor = UserUtils.getCurrentUser();
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
if (paramSearch != null && paramSearch.length() > 64) {
paramSearch = null;
@@ -156,7 +155,7 @@ public class MessagesWWW {
model.addAttribute("visitor", visitor);
model.addAttribute("noindex", !(paramShow == null && paramBefore == 0));
List<com.juick.Message> msgs = messagesService.getMessages(visitor, mids);
- msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
if (!visitor.isAnonymous()) {
fillUserModel(model, visitor, visitor);
List<Integer> unread = messagesService.getUnread(visitor);
@@ -208,7 +207,7 @@ public class MessagesWWW {
if (user.isBanned() || user.isAnonymous()) {
throw new HttpNotFoundException();
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
List<Integer> mids;
@@ -275,7 +274,7 @@ public class MessagesWWW {
fillUserModel(model, user, visitor);
model.addAttribute("paramTag", paramTag);
List<com.juick.Message> msgs = messagesService.getMessages(visitor, mids);
- msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
if (!visitor.isAnonymous()) {
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
@@ -320,7 +319,7 @@ public class MessagesWWW {
if (visitor.isBanned()) {
throw new HttpNotFoundException();
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("title", "Теги " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex,nofollow\"/>");
@@ -339,7 +338,7 @@ public class MessagesWWW {
if (visitor.isBanned()) {
throw new HttpNotFoundException();
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("title", "Подписки " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
@@ -356,7 +355,7 @@ public class MessagesWWW {
if (visitor.isBanned()) {
throw new HttpForbiddenException();
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("title", "Читатели " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
@@ -373,7 +372,7 @@ public class MessagesWWW {
if (visitor.isBanned() || visitor.getUid() != user.getUid()) {
throw new HttpForbiddenException();
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("title", "Черный список " + user.getName());
model.addAttribute("headers", "<meta name=\"robots\" content=\"noindex\"/>");
model.addAttribute("visitor", visitor);
@@ -389,7 +388,7 @@ public class MessagesWWW {
@RequestParam(required = false, defaultValue = "0") int before,
ModelMap model) throws IOException {
com.juick.User visitor = UserUtils.getCurrentUser();
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String paramTagStr = StringEscapeUtils.unescapeHtml4(tagName);
com.juick.Tag paramTag = tagService.getTag(paramTagStr, false);
if (paramTag == null) {
@@ -413,7 +412,7 @@ public class MessagesWWW {
model.addAttribute("title", title);
List<Integer> mids = messagesService.getTag(paramTag.TID, visitor.getUid(), before, (visitor.isAnonymous()) ? 40 : 20);
List<com.juick.Message> msgs = messagesService.getMessages(visitor, mids);
- msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
if (!visitor.isAnonymous()) {
List<Integer> unread = messagesService.getUnread(visitor);
visitor.setUnreadCount(unread.size());
@@ -463,10 +462,10 @@ public class MessagesWWW {
if (visitor.isAnonymous()) {
return "redirect:/login";
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String title = "PM: Inbox";
List<com.juick.Message> msgs = pmQueriesService.getLastPMInbox(visitor.getUid());
- msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
fillUserModel(model, visitor, visitor);
model.addAttribute("title", title);
model.addAttribute("visitor", visitor);
@@ -482,10 +481,10 @@ public class MessagesWWW {
if (visitor.isAnonymous()) {
return "redirect:/login";
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
String title = "PM: Sent";
List<com.juick.Message> msgs = pmQueriesService.getLastPMSent(visitor.getUid());
- msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarUrl(m.getUser())));
+ msgs.forEach(m -> m.getUser().setAvatar(webApp.getAvatarWebPath(m.getUser())));
if (WebUtils.isNotUserName(uname)) {
uname = StringUtils.EMPTY;
}
@@ -508,7 +507,7 @@ public class MessagesWWW {
if (!messagesService.canViewThread(mid, visitor.getUid())) {
throw new HttpForbiddenException();
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
Optional<com.juick.Message> message = messagesService.getMessage(mid);
if (!message.isPresent() || message.get().getUser().isBanned()) {
@@ -522,7 +521,7 @@ public class MessagesWWW {
return String.format("redirect:/%s/%d", msg.getUser().getName(), mid);
}
msg.VisitorCanComment = !visitor.isAnonymous();
- msg.getUser().setAvatar(webApp.getAvatarUrl(msg.getUser()));
+ msg.getUser().setAvatar(webApp.getAvatarWebPath(msg.getUser()));
List<com.juick.Message> replies = messagesService.getReplies(visitor, msg.getMid());
// this should be after getReplies to mark thread as read
fillUserModel(model, user, visitor);
@@ -552,7 +551,7 @@ public class MessagesWWW {
headers += "<meta property=\"og:image\" content=\"" + msgImage + "\" />";
}
} else {
- String msgImage ="https://i.juick.com/a/" + msg.getUser().getUid() + ".png";
+ String msgImage = webApp.getAvatarPublicUrl(msg.getUser());
headers += "<meta property=\"og:image\" content=\"" + msgImage + "\" />";
}
model.addAttribute("ogtype", "article");
@@ -582,7 +581,7 @@ public class MessagesWWW {
blUIDs.add(reply.getUser().getUid());
}
reply.VisitorCanComment = !visitor.isAnonymous();
- reply.getUser().setAvatar(webApp.getAvatarUrl(reply.getUser()));
+ reply.getUser().setAvatar(webApp.getAvatarWebPath(reply.getUser()));
if (!visitor.isAnonymous()) {
boolean isMsgAuthor = visitor.getUid() == msg.getUser().getUid();
boolean isReplyAuthor = visitor.getUid() == reply.getUser().getUid();
diff --git a/src/main/java/com/juick/server/www/controllers/NewMessage.java b/src/main/java/com/juick/server/www/controllers/NewMessage.java
index 418d8805..1d3d2f5e 100644
--- a/src/main/java/com/juick/server/www/controllers/NewMessage.java
+++ b/src/main/java/com/juick/server/www/controllers/NewMessage.java
@@ -42,7 +42,7 @@ public class NewMessage {
@GetMapping("/post")
protected String postAction(@RequestParam(required = false) String body, ModelMap model) {
com.juick.User visitor = UserUtils.getCurrentUser();
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("title", "Написать");
model.addAttribute("headers", "");
model.addAttribute("visitor", visitor);
diff --git a/src/main/java/com/juick/server/www/controllers/Settings.java b/src/main/java/com/juick/server/www/controllers/Settings.java
index 82eb593a..03682586 100644
--- a/src/main/java/com/juick/server/www/controllers/Settings.java
+++ b/src/main/java/com/juick/server/www/controllers/Settings.java
@@ -87,7 +87,7 @@ public class Settings {
if (visitor.isAnonymous()) {
response.sendRedirect("/login");
}
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
List<String> pages = Arrays.asList("main", "password", "about", "auth-email", "privacy");
String page = request.getParameter("page");
if (StringUtils.isEmpty(page) || !pages.contains(page)) {
diff --git a/src/main/java/com/juick/server/www/controllers/SignUp.java b/src/main/java/com/juick/server/www/controllers/SignUp.java
index ee9c6703..eac1c767 100644
--- a/src/main/java/com/juick/server/www/controllers/SignUp.java
+++ b/src/main/java/com/juick/server/www/controllers/SignUp.java
@@ -87,7 +87,7 @@ public class SignUp {
}
model.addAttribute("title", "Новый пользователь");
- visitor.setAvatar(webApp.getAvatarUrl(visitor));
+ visitor.setAvatar(webApp.getAvatarWebPath(visitor));
model.addAttribute("visitor", visitor);
model.addAttribute("account", account);
model.addAttribute("type", type);