From 688c09760b8086b05fd4b507492bfae6555f10b4 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 13 Jun 2017 15:08:10 +0200 Subject: [PATCH] Handle both WebP and original avatars --- main.go | 26 ++++++++++++++++++++++---- styles/user.scarlet | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index ceefeaf1..50ee9498 100644 --- a/main.go +++ b/main.go @@ -92,8 +92,17 @@ func main() { return ctx.File("images/avatars/large/webp/" + user.ID + ".webp") } - err = errors.New("Your browser doesn't support the WebP image format") - return ctx.Error(http.StatusBadRequest, err.Error(), err) + original := arn.FindFileWithExtension( + user.ID, + "images/avatars/large/original/", + arn.OriginalImageExtensions, + ) + + if original == "" { + return ctx.Error(http.StatusNotFound, "Avatar not found", errors.New("Image not found for user: "+user.ID)) + } + + return ctx.File(original) }) // Avatars @@ -109,8 +118,17 @@ func main() { return ctx.File("images/avatars/small/webp/" + user.ID + ".webp") } - err = errors.New("Your browser doesn't support the WebP image format") - return ctx.Error(http.StatusBadRequest, err.Error(), err) + original := arn.FindFileWithExtension( + user.ID, + "images/avatars/small/original/", + arn.OriginalImageExtensions, + ) + + if original == "" { + return ctx.Error(http.StatusNotFound, "Avatar not found", errors.New("Image not found for user: "+user.ID)) + } + + return ctx.File(original) }) // Elements diff --git a/styles/user.scarlet b/styles/user.scarlet index 5a39867f..e7c497c0 100644 --- a/styles/user.scarlet +++ b/styles/user.scarlet @@ -4,6 +4,7 @@ height avatar-size border-radius 100% object-fit cover + opacity 0 default-transition :hover box-shadow outline-shadow-heavy \ No newline at end of file