Fixed WebP loading and auto-update avatar

This commit is contained in:
Eduard Urbach 2018-03-03 16:44:21 +01:00
parent 61f4fdb386
commit 634fed8e87
3 changed files with 17 additions and 5 deletions

View File

@ -32,5 +32,5 @@ func Avatar(ctx *aero.Context) string {
// Save avatar information // Save avatar information
user.Save() user.Save()
return "ok" return user.SmallAvatar()
} }

View File

@ -48,6 +48,12 @@ function uploadFile(file: File, endpoint: string, arn: AnimeNotifier) {
body: reader.result 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) { if(response.ok) {
arn.statusMessage.showInfo("Successfully uploaded your new avatar.") arn.statusMessage.showInfo("Successfully uploaded your new avatar.")
} else { } else {

View File

@ -510,15 +510,21 @@ export class AnimeNotifier {
// Once the image becomes visible, load it // Once the image becomes visible, load it
element["became visible"] = () => { element["became visible"] = () => {
let dataSrc = element.dataset.src let dataSrc = element.dataset.src
let dot = dataSrc.lastIndexOf(".") let dotPos = dataSrc.lastIndexOf(".")
let base = dataSrc.substring(0, dot) let base = dataSrc.substring(0, dotPos)
let extension = "" let extension = ""
// Replace URL with WebP if supported // Replace URL with WebP if supported
if(this.webpEnabled && element.dataset.webp) { if(this.webpEnabled && element.dataset.webp) {
extension = ".webp" let queryPos = dataSrc.lastIndexOf("?")
if(queryPos !== -1) {
extension = ".webp" + dataSrc.substring(queryPos)
} else { } else {
extension = dataSrc.substring(dot) extension = ".webp"
}
} else {
extension = dataSrc.substring(dotPos)
} }
// Anime images on Retina displays // Anime images on Retina displays