fetch pfp attempt uno
Anirudh Oppiliappan x@icyphox.sh
Tue, 08 Nov 2022 15:41:52 +0530
1 files changed,
33 insertions(+),
16 deletions(-)
jump to
M
web.go
→
web.go
@@ -2304,18 +2304,14 @@ secs := 432000 + notrand.Int63n(432000)
return fmt.Sprintf("%d", secs) } -func lookatme(ava string) string { - if strings.Contains(ava, serverName+"/"+userSep) { - idx := strings.LastIndexByte(ava, '/') - if idx < len(ava) { - name := ava[idx+1:] - user, _ := butwhatabout(name) - if user != nil && user.URL == ava { - return user.Options.Avatar - } - } - } - return "" +func isurl(s string) bool { + u, err := url.Parse(s) + return err == nil && u.Scheme != "" && u.Host != "" +} + +func avatateautogen(r *http.Request) []byte { + n := r.FormValue("a") + return genAvatar(n) } func avatate(w http.ResponseWriter, r *http.Request) {@@ -2324,11 +2320,32 @@ loadAvatarColors()
} var a []byte n := r.FormValue("a") - if redir := lookatme(n); redir != "" { - http.Redirect(w, r, redir, http.StatusSeeOther) - return + + if isurl(n) { + uinfo := login.GetUserInfo(r) + j, err := GetJunkFast(uinfo.UserID, n) + if err != nil { + dlog.Println("avatating: getting junk:", err) + a = avatateautogen(r) + } + pfpurl, _ := j.GetString("icon", "url") + res, err := http.Get(pfpurl) + if err != nil { + dlog.Println("avatating: getting pfp url:", err) + a = avatateautogen(r) + } + defer res.Body.Close() + + pfpbytes, err := io.ReadAll(res.Body) + if err != nil { + dlog.Println("avatating: bruh shits clapped:", err) + a = avatateautogen(r) + } + a = pfpbytes + } else { + a = avatateautogen(r) } - a = genAvatar(n) + if !develMode { w.Header().Set("Cache-Control", "max-age="+somedays()) }