From fc7ad5f5849e28c0f0d4d5eed695236d0576b4b3 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 19 Feb 2019 16:03:55 +0300 Subject: legacy avatar api --- src/main/java/com/juick/server/api/Users.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (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 5c6efe0c..03e916d1 100644 --- a/src/main/java/com/juick/server/api/Users.java +++ b/src/main/java/com/juick/server/api/Users.java @@ -18,18 +18,23 @@ 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.www.WebApp; import com.juick.service.*; 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; import javax.inject.Inject; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -166,6 +171,24 @@ public class Users { throw new HttpNotFoundException(); } + @Deprecated + @GetMapping("/api/avatar") + public ResponseEntity getAvatarUrl(@RequestParam(required = false) String uname, + @RequestParam(required = false) String jid) { + User user = AnonymousUser.INSTANCE; + if (StringUtils.isNotEmpty(uname)) { + user = userService.getUserByName(uname); + } + if (user.isAnonymous() && StringUtils.isNotEmpty(jid)) { + user = userService.getUserByJID(jid); + } + if (!user.isAnonymous()) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.setLocation(URI.create(webApp.getAvatarUrl(user))); + return new ResponseEntity<>(httpHeaders, HttpStatus.MOVED_PERMANENTLY); + } + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } class SecureUser extends User { public String getHash() { return getAuthHash(); -- cgit v1.2.3