Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
fix(avatar): empty response if user has no avatar
Browse files Browse the repository at this point in the history
  • Loading branch information
phiz71 committed Mar 13, 2020
1 parent 9240a5f commit b18e55e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
Expand Up @@ -160,18 +160,13 @@ public Response getCurrentUserPicture(@Context Request request) {
String userId = userService.findById(getAuthenticatedUser()).getId();
PictureEntity picture = userService.getPicture(userId);

if (picture == null) {
throw new NotFoundException();
}

if (picture instanceof UrlPictureEntity) {
return Response.temporaryRedirect(URI.create(((UrlPictureEntity) picture).getUrl())).build();
}

InlinePictureEntity image = (InlinePictureEntity) picture;

if (image.getContent() == null) {
throw new NotFoundException();
if (image == null || image.getContent() == null) {
return Response.ok().build();
}

EntityTag etag = new EntityTag(Integer.toString(new String(image.getContent()).hashCode()));
Expand Down
Expand Up @@ -144,12 +144,13 @@ public Response resetPassword(@PathParam("id") String userId) {
public Response getUserAvatar(@PathParam("id") String id, @Context Request request) {
PictureEntity picture = userService.getPicture(id);

if (picture == null) {
throw new NotFoundException();
}

if (picture instanceof UrlPictureEntity) {
return Response.temporaryRedirect(URI.create(((UrlPictureEntity)picture).getUrl())).build();
return Response.temporaryRedirect(URI.create(((UrlPictureEntity) picture).getUrl())).build();
}

InlinePictureEntity image = (InlinePictureEntity) picture;
if (image == null || image.getContent() == null) {
return Response.ok().build();
}

CacheControl cc = new CacheControl();
Expand All @@ -158,7 +159,6 @@ public Response getUserAvatar(@PathParam("id") String id, @Context Request reque
cc.setNoCache(false);
cc.setMaxAge(86400);

InlinePictureEntity image = (InlinePictureEntity) picture;

EntityTag etag = new EntityTag(Integer.toString(new String(image.getContent()).hashCode()));
Response.ResponseBuilder builder = request.evaluatePreconditions(etag);
Expand Down

0 comments on commit b18e55e

Please sign in to comment.