aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-02-20 10:05:33 +0300
committerGravatar Vitaly Takmazov2019-02-20 10:30:02 +0300
commitd7db89b3dc22215152e508b9629632d7a604bbf0 (patch)
treeaa77aea113a5fd431c39882f61b17800551d02c8 /src/main/java/com
parentae3da8bbc97ad839505dc14e3f524249b5802940 (diff)
return raw image from legacy avatar endpoint
Diffstat (limited to 'src/main/java/com')
-rw-r--r--src/main/java/com/juick/server/api/Users.java26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/main/java/com/juick/server/api/Users.java b/src/main/java/com/juick/server/api/Users.java
index 216cd68d..33b3704b 100644
--- a/src/main/java/com/juick/server/api/Users.java
+++ b/src/main/java/com/juick/server/api/Users.java
@@ -20,15 +20,16 @@ package com.juick.server.api;
import com.juick.User;
import com.juick.model.AnonymousUser;
import com.juick.model.ApplicationStatus;
-import com.juick.server.util.*;
+import com.juick.server.util.HttpNotFoundException;
+import com.juick.server.util.HttpUtils;
+import com.juick.server.util.UserUtils;
+import com.juick.server.util.WebUtils;
import com.juick.server.www.WebApp;
import com.juick.service.*;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -172,10 +173,11 @@ public class Users {
}
@Deprecated
- @GetMapping("/api/avatar")
- public ResponseEntity<Void> getAvatarUrl(@RequestParam(required = false) String uname,
- @RequestParam(required = false) String jid,
- @RequestParam(required = false, defaultValue = "48") Integer size) {
+ @GetMapping(value = "/api/avatar", produces = MediaType.IMAGE_PNG_VALUE)
+ public byte[] getAvatarUrl(
+ @RequestParam(required = false) String uname,
+ @RequestParam(required = false) String jid)
+ throws IOException {
User user = AnonymousUser.INSTANCE;
if (StringUtils.isNotEmpty(uname)) {
user = userService.getUserByName(uname);
@@ -183,13 +185,7 @@ public class Users {
if (user.isAnonymous() && StringUtils.isNotEmpty(jid)) {
user = userService.getUserByJID(jid);
}
- if (!user.isAnonymous()) {
- String imagePrefix = size == 32 ? "as" : "a";
- HttpHeaders httpHeaders = new HttpHeaders();
- httpHeaders.setLocation(URI.create(String.format("http://i.juick.com/%s/%d.png", imagePrefix, user.getUid())));
- return new ResponseEntity<>(httpHeaders, HttpStatus.MOVED_PERMANENTLY);
- }
- return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ return IOUtils.toByteArray(URI.create(webApp.getAvatarUrl(user)));
}
class SecureUser extends User {
public String getHash() {