Add the profile image UI and docs (SCR-1)
CI / validate-monitoring (push) Successful in 10s
CI / lint (push) Successful in 14s
CI / federation-interop (push) Successful in 1m15s
CI / test (push) Successful in 7m2s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / trigger-deploy (push) Skipped
CI / notify (push) Successful in 5s

A Profile page to upload, use Gravatar or remove the image, the avatar in the page
header and on the public profile, a Sharing switch for it, and user/admin guide notes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
mattandClaude Sonnet 5.5 committed 2026-10-13 11:47:13 +01:00
1 parent b878523d51
commit b388e7112d
10 files changed
+246 -2

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Profile · Scrobbled</title>
<link rel="icon" href="favicon.ico" sizes="48x48">
<link rel="icon" href="favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="manifest" href="site.webmanifest">
<meta name="theme-color" content="#1F1C28">
<link rel="stylesheet" href="css/style.css">
<script src="config.js"></script>
<script type="module" src="js/account.js"></script>
</head>
<body>
<header class="site-header" id="site-header"></header>
<main id="main">
<h1 class="page-title">Profile</h1>
<p class="lede">Your profile image, shown next to your name.</p>
<div id="messages" aria-live="polite"></div>
<section id="avatar-panel"></section>
</main>
</body>
</html>
+67 -1
View File
@@ -209,10 +209,76 @@ code {
margin-left: auto;
display: flex;
gap: 1rem;
align-items: baseline;
align-items: center;
color: var(--ink-soft);
}
.account-link {
display: flex;
gap: 0.5rem;
align-items: center;
color: inherit;
text-decoration: none;
}
.account-link:hover .account-name {
color: var(--ink);
}
.account-avatar {
display: flex;
}
/* A profile image: round, with the placeholder ring while there's none */
.avatar {
display: block;
flex: none;
border-radius: 50%;
object-fit: cover;
background: var(--paper-raised);
border: 1px solid var(--rule);
}
.avatar-sm {
width: 1.75rem;
height: 1.75rem;
}
.avatar-lg {
width: 7rem;
height: 7rem;
}
.avatar-empty {
position: relative;
}
.avatar-empty::after {
content: "";
position: absolute;
inset: 32%;
border-radius: 50%;
border: 2px solid var(--bar);
}
.avatar-row {
display: flex;
gap: 1.5rem;
align-items: flex-start;
}
.avatar-body {
display: grid;
gap: 0.75rem;
max-width: 40rem;
}
.avatar-xl {
width: 6rem;
height: 6rem;
margin-bottom: 1rem;
}
main {
max-width: 1120px;
margin: 0 auto;
+95
View File
@@ -0,0 +1,95 @@
import { api, describeError, upload } from "./api.js";
import { avatarImage } from "./avatar.js";
import { errorBox, h, replace } from "./dom.js";
import { signedInPage } from "./layout.js";
const root = document.getElementById("avatar-panel");
const messages = document.getElementById("messages");
let user = await signedInPage("account.html");
render();
const SOURCES = {
upload: "An image you uploaded.",
gravatar: "Your Gravatar, copied to this server.",
none: "You haven't set a profile image yet.",
};
function say(notice) {
replace(messages, notice);
}
// Runs a change, adopts the user it returns (or refetches), and redraws everything that
// shows the image - this panel and the one in the page header.
async function change(action, done) {
const buttons = root.querySelectorAll("button");
buttons.forEach((button) => (button.disabled = true));
try {
user = (await action()) ?? (await api("/auth/me"));
say(h("p", { class: "notice notice-ok" }, done));
} catch (error) {
say(errorBox(describeError(error)));
}
render();
const slot = document.querySelector(".account-avatar");
if (slot) replace(slot, avatarImage(user, "avatar-sm"));
}
function render() {
const file = h("input", { type: "file", accept: "image/jpeg,image/png,image/webp", hidden: true });
file.addEventListener("change", () => {
if (!file.files[0]) return;
const data = new FormData();
data.append("file", file.files[0]);
change(() => upload("/me/avatar", data, undefined, "PUT"), "Profile image updated.");
});
const buttons = [
h("button", { type: "button", class: "button", onclick: () => file.click() }, "Upload image"),
user.gravatar_enabled
? h(
"button",
{
type: "button",
class: "button button-quiet",
onclick: () => change(() => api("/me/avatar/gravatar", { method: "POST" }), "Now using your Gravatar."),
},
user.avatar_source === "gravatar" ? "Refresh Gravatar" : "Use my Gravatar",
)
: null,
user.has_avatar
? h(
"button",
{
type: "button",
class: "button button-quiet",
onclick: () => change(() => api("/me/avatar", { method: "DELETE" }), "Profile image removed."),
},
"Remove",
)
: null,
];
replace(
root,
h(
"div",
{ class: "avatar-row" },
avatarImage(user, "avatar-lg"),
h(
"div",
{ class: "avatar-body" },
h("p", {}, SOURCES[user.avatar_source] ?? SOURCES.none),
h("p", { class: "muted" }, "JPEG, PNG or WebP. Only you see it, unless you choose to share it on your fediverse profile."),
h("div", { class: "button-row" }, buttons, file),
user.gravatar_enabled
? h(
"p",
{ class: "muted" },
"Using Gravatar makes this server ask Gravatar for the picture linked to your email address, sending it a hash of that address (not the address itself). Your browser never contacts Gravatar.",
)
: null,
),
),
);
}
+19
View File
@@ -0,0 +1,19 @@
// A round profile image that starts as a placeholder ring and swaps itself for the real
// picture once (if) it loads. `source` is either a signed-in user (their own image,
// fetched with their token) or { path } for another public image URL.
import { fetchImage } from "./api.js";
import { h } from "./dom.js";
export function avatarImage(user, extraClass, path = "/me/avatar") {
const classes = extraClass ? `avatar ${extraClass}` : "avatar";
const el = h("span", { class: `${classes} avatar-empty`, "aria-hidden": "true" });
if (!user?.has_avatar) return el;
fetchImage(path).then((url) => {
if (!url) return; // miss or failed fetch: leave the placeholder
const img = h("img", { class: classes, alt: "" });
img.src = url;
el.replaceWith(img);
});
return el;
}
+7 -1
View File
@@ -1,6 +1,7 @@
// Shared page shell: site header, navigation, sign-in guard.
import { api, getToken, redirectToLogin, setToken } from "./api.js";
import { avatarImage } from "./avatar.js";
import { h, replace } from "./dom.js";
const NAV = [
@@ -26,7 +27,12 @@ export async function signedInPage(active) {
h(
"div",
{ class: "account" },
h("span", { class: "account-name" }, user.username),
h(
"a",
{ class: "account-link", href: "account.html", title: "Your profile image" },
h("span", { class: "account-avatar" }, avatarImage(user, "avatar-sm")),
h("span", { class: "account-name" }, user.username),
),
h("button", { type: "button", class: "link-button", onclick: signOut }, "Sign out"),
),
);
+4
View File
@@ -1,4 +1,5 @@
import { api } from "./api.js";
import { avatarImage } from "./avatar.js";
import { errorBox, h, replace } from "./dom.js";
import { publicPage } from "./layout.js";
@@ -22,6 +23,9 @@ try {
});
replace(
root,
profile.has_avatar
? avatarImage(profile, "avatar-xl", `/federation/profiles/${encodeURIComponent(username)}/avatar`)
: null,
h("h1", {}, profile.display_name),
h("div", { class: "approve-app handle" }, profile.handle),
profile.bio ? h("p", { class: "lede profile-bio" }, profile.bio) : null,
+2
View File
@@ -16,6 +16,7 @@ const FIELDS = [
"post_milestones",
"timezone",
"now_playing_mode",
"share_avatar",
"display_name",
"bio",
];
@@ -155,6 +156,7 @@ async function save(event) {
post_milestones: form.elements.post_milestones.checked,
timezone: form.elements.timezone.value.trim() || "UTC",
now_playing_mode: form.querySelector("input[name=now_playing_mode]:checked").value,
share_avatar: form.elements.share_avatar.checked,
display_name: form.elements.display_name.value.trim() || null,
bio: form.elements.bio.value.trim() || null,
};
+4
View File
@@ -114,6 +114,10 @@
<textarea id="bio" name="bio" maxlength="500" rows="3"></textarea>
<span class="hint">Shown on your fediverse profile. Plain text.</span>
</div>
<div class="choice">
<input type="checkbox" id="share_avatar" name="share_avatar">
<label for="share_avatar"><strong>Share my profile image</strong><span class="muted">Show the image from your <a href="account.html">profile</a> on your public profile page, and send it to other servers as your picture. Without this it stays private.</span></label>
</div>
<p class="muted" id="profile-link"></p>
</fieldset>