From 634fed8e87855b10442ad686dfb465586df441d1 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Sat, 3 Mar 2018 16:44:21 +0100 Subject: [PATCH] Fixed WebP loading and auto-update avatar --- pages/upload/avatar.go | 2 +- scripts/Actions/Upload.ts | 6 ++++++ scripts/AnimeNotifier.ts | 14 ++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pages/upload/avatar.go b/pages/upload/avatar.go index 2bc61f06..424174bc 100644 --- a/pages/upload/avatar.go +++ b/pages/upload/avatar.go @@ -32,5 +32,5 @@ func Avatar(ctx *aero.Context) string { // Save avatar information user.Save() - return "ok" + return user.SmallAvatar() } diff --git a/scripts/Actions/Upload.ts b/scripts/Actions/Upload.ts index 7d747f85..fa0ff9fa 100644 --- a/scripts/Actions/Upload.ts +++ b/scripts/Actions/Upload.ts @@ -48,6 +48,12 @@ function uploadFile(file: File, endpoint: string, arn: AnimeNotifier) { body: reader.result }) + let newURL = await response.text() + let sidebar = document.getElementById("sidebar") + let userImage = sidebar.getElementsByClassName("user-image")[0] as HTMLImageElement + userImage.dataset.src = newURL + userImage["became visible"]() + if(response.ok) { arn.statusMessage.showInfo("Successfully uploaded your new avatar.") } else { diff --git a/scripts/AnimeNotifier.ts b/scripts/AnimeNotifier.ts index 2e3c41fa..fed0cda1 100644 --- a/scripts/AnimeNotifier.ts +++ b/scripts/AnimeNotifier.ts @@ -510,15 +510,21 @@ export class AnimeNotifier { // Once the image becomes visible, load it element["became visible"] = () => { let dataSrc = element.dataset.src - let dot = dataSrc.lastIndexOf(".") - let base = dataSrc.substring(0, dot) + let dotPos = dataSrc.lastIndexOf(".") + let base = dataSrc.substring(0, dotPos) let extension = "" // Replace URL with WebP if supported if(this.webpEnabled && element.dataset.webp) { - extension = ".webp" + let queryPos = dataSrc.lastIndexOf("?") + + if(queryPos !== -1) { + extension = ".webp" + dataSrc.substring(queryPos) + } else { + extension = ".webp" + } } else { - extension = dataSrc.substring(dot) + extension = dataSrc.substring(dotPos) } // Anime images on Retina displays