From d7db89b3dc22215152e508b9629632d7a604bbf0 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 20 Feb 2019 10:05:33 +0300 Subject: return raw image from legacy avatar endpoint --- src/main/java/com/juick/server/api/Users.java | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) (limited to 'src') 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 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() { -- cgit v1.2.3