From afcdcfe8c80a610e5917f011300ee05d1762cca9 Mon Sep 17 00:00:00 2001 From: Anirudh Oppiliappan Date: Fri, 12 Dec 2025 11:28:28 +0200 Subject: [PATCH] appview/pages: upload and render avatar Change-Id: tolqptymwvpqvmnkonyqqwuxkvxkyunx Signed-off-by: Anirudh Oppiliappan --- appview/pages/funcmap.go | 40 +++++++++++++++++ .../pages/templates/layouts/profilebase.html | 2 +- .../templates/user/fragments/editAvatar.html | 44 +++++++++++++++++++ .../templates/user/fragments/profileCard.html | 20 +++++++-- .../pages/templates/user/settings/emails.html | 6 ++- .../pages/templates/user/settings/keys.html | 6 ++- 6 files changed, 110 insertions(+), 8 deletions(-) create mode 100644 appview/pages/templates/user/fragments/editAvatar.html diff --git a/appview/pages/funcmap.go b/appview/pages/funcmap.go index ec123657..602d6247 100644 --- a/appview/pages/funcmap.go +++ b/appview/pages/funcmap.go @@ -360,6 +360,9 @@ func (p *Pages) funcMap() template.FuncMap { "fullAvatar": func(handle string) string { return p.AvatarUrl(handle, "") }, + "profileAvatarUrl": func(profile *models.Profile, size string) string { + return p.ProfileAvatarUrl(profile, size) + }, "langColor": enry.GetColor, "layoutSide": func() string { return "col-span-1 md:col-span-2 lg:col-span-3" @@ -414,6 +417,43 @@ func (p *Pages) AvatarUrl(handle, size string) string { return fmt.Sprintf("%s/%s/%s?%s", p.avatar.Host, signature, handle, sizeArg) } +func (p *Pages) ProfileAvatarUrl(profile *models.Profile, size string) string { + if profile != nil && profile.Avatar != "" { + ident, err := p.resolver.ResolveIdent(context.Background(), profile.Did) + if err == nil && ident.PDSEndpoint() != "" { + blobUrl := fmt.Sprintf("%s/xrpc/com.atproto.sync.getBlob?did=%s&cid=%s", + ident.PDSEndpoint(), + profile.Did, + profile.Avatar) + + handle := strings.TrimPrefix(profile.Did, "@") + handle = p.resolveDid(handle) + + secret := p.avatar.SharedSecret + h := hmac.New(sha256.New, []byte(secret)) + h.Write([]byte(handle)) + signature := hex.EncodeToString(h.Sum(nil)) + + sizeArg := "" + if size != "" { + sizeArg = fmt.Sprintf("&size=%s", size) + } + + return fmt.Sprintf("%s/%s/%s?blob=%s%s", + p.avatar.Host, + signature, + handle, + url.QueryEscape(blobUrl), + sizeArg) + } + } + + if profile != nil { + return p.AvatarUrl(profile.Did, size) + } + return "" +} + func (p *Pages) icon(name string, classes []string) (template.HTML, error) { iconPath := filepath.Join("static", "icons", name) diff --git a/appview/pages/templates/layouts/profilebase.html b/appview/pages/templates/layouts/profilebase.html index 0747a39f..7aeb4937 100644 --- a/appview/pages/templates/layouts/profilebase.html +++ b/appview/pages/templates/layouts/profilebase.html @@ -2,7 +2,7 @@ {{ define "extrameta" }} {{ $handle := resolve .Card.UserDid }} - {{ $avatarUrl := fullAvatar $handle }} + {{ $avatarUrl := profileAvatarUrl .Card.Profile "" }} diff --git a/appview/pages/templates/user/fragments/editAvatar.html b/appview/pages/templates/user/fragments/editAvatar.html new file mode 100644 index 00000000..66ceed36 --- /dev/null +++ b/appview/pages/templates/user/fragments/editAvatar.html @@ -0,0 +1,44 @@ +{{ define "user/fragments/editAvatar" }} +
+ +

Select an image (PNG or JPEG, max 1MB)

+ +
+ + +
+
+
+{{ end }} diff --git a/appview/pages/templates/user/fragments/profileCard.html b/appview/pages/templates/user/fragments/profileCard.html index 59480f82..cb5bf443 100644 --- a/appview/pages/templates/user/fragments/profileCard.html +++ b/appview/pages/templates/user/fragments/profileCard.html @@ -3,9 +3,24 @@
- + + {{ if eq .FollowStatus.String "IsSelf" }} + + {{ end }}
+
+ {{ template "user/fragments/editAvatar" . }} +

-

+
{{ if .Location }}
{{ i "map-pin" "size-4" }} @@ -111,4 +126,3 @@
{{ end }} {{ end }} - diff --git a/appview/pages/templates/user/settings/emails.html b/appview/pages/templates/user/settings/emails.html index 9dd5a627..90e62f98 100644 --- a/appview/pages/templates/user/settings/emails.html +++ b/appview/pages/templates/user/settings/emails.html @@ -62,7 +62,9 @@ hx-swap="none" class="flex flex-col gap-2" > -

ADD EMAIL

+

Commits using this email will be associated with your profile.

-{{ end }} \ No newline at end of file +{{ end }} diff --git a/appview/pages/templates/user/settings/keys.html b/appview/pages/templates/user/settings/keys.html index 038c344d..a22ae549 100644 --- a/appview/pages/templates/user/settings/keys.html +++ b/appview/pages/templates/user/settings/keys.html @@ -21,7 +21,7 @@

SSH Keys

- SSH public keys added here will be broadcasted to knots that you are a member of, + SSH public keys added here will be broadcasted to knots that you are a member of, allowing you to push to repositories there.

@@ -63,7 +63,9 @@ hx-swap="none" class="flex flex-col gap-2" > -

ADD SSH KEY

+

SSH keys allow you to push to repositories in knots you're a member of.