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
user.Save()
return "ok"
return user.SmallAvatar()
}

View File

@ -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 {

View File

@ -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