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
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:
1 parent
b878523d51
commit
b388e7112d
10 files changed
+246
-2
No files matched your search
@@ -62,6 +62,8 @@ read **Putting it behind TLS** below — the quick start above serves plain HTTP
|
|||||||
| `LASTFM_API_KEY` | api, worker | *(unset)* | Enables importing straight from Last.fm ([get a key](https://www.last.fm/api/account/create)) |
|
| `LASTFM_API_KEY` | api, worker | *(unset)* | Enables importing straight from Last.fm ([get a key](https://www.last.fm/api/account/create)) |
|
||||||
| `MUSICBRAINZ_CONTACT` | api, worker | `UI_BASE_URL` | Contact URL/email sent to MusicBrainz for album art lookups (no key needed, but they ask for one) |
|
| `MUSICBRAINZ_CONTACT` | api, worker | `UI_BASE_URL` | Contact URL/email sent to MusicBrainz for album art lookups (no key needed, but they ask for one) |
|
||||||
| `ART_STORAGE_DIR` | api, worker | `var/album-art` | Where downloaded album art is stored; the worker writes it, the api serves it — both need access to the same directory (`docker compose` mounts a shared volume there) |
|
| `ART_STORAGE_DIR` | api, worker | `var/album-art` | Where downloaded album art is stored; the worker writes it, the api serves it — both need access to the same directory (`docker compose` mounts a shared volume there) |
|
||||||
|
| `AVATAR_UPLOAD_MAX_BYTES` | api | 2 MB | Largest profile image a user may upload (a reverse proxy needs a body limit at least this large too). Images are stored in `avatars/` inside `ART_STORAGE_DIR` |
|
||||||
|
| `AVATAR_GRAVATAR_ENABLED` | api | off | Lets users use their Gravatar as their profile image. The api then calls gravatar.com (outbound HTTPS needed), sending it a SHA-256 hash of the user's email address; browsers never contact Gravatar |
|
||||||
| `ART_UPLOAD_MAX_BYTES` | api | 5 MB | Largest image a user may upload as their own album art. A reverse proxy in front of the api needs a body limit at least this large |
|
| `ART_UPLOAD_MAX_BYTES` | api | 5 MB | Largest image a user may upload as their own album art. A reverse proxy in front of the api needs a body limit at least this large |
|
||||||
| `IMPORT_MAX_BYTES` | api | 200 MB | Largest export file accepted |
|
| `IMPORT_MAX_BYTES` | api | 200 MB | Largest export file accepted |
|
||||||
| `WORKER_METRICS_PORT` | worker | `9101` | The worker's Prometheus metrics port |
|
| `WORKER_METRICS_PORT` | worker | `9101` | The worker's Prometheus metrics port |
|
||||||
@@ -201,6 +203,11 @@ disposable cache — it's simply re-downloaded the next time it's requested. Ima
|
|||||||
volume and can't be re-created, so include the volume in your backups. The database rows
|
volume and can't be re-created, so include the volume in your backups. The database rows
|
||||||
that point at them are in `user_album_art`; restore the two together.
|
that point at them are in `user_album_art`; restore the two together.
|
||||||
|
|
||||||
|
Profile images (uploads, and copies of users' Gravatars) are in `avatars/` in that volume,
|
||||||
|
one file per user id, and likewise belong in your backups. The `users` table records
|
||||||
|
which users have one (`avatar_source`); a missing file just shows as no image. Gravatar
|
||||||
|
copies can be re-fetched by their users, but uploads can't be re-created.
|
||||||
|
|
||||||
## Upgrades
|
## Upgrades
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|||||||
@@ -65,6 +65,22 @@ flight. Unlike live scrobbles, imports keep plays of any age (still skipping row
|
|||||||
artist or track, or plays dated in the future). Plays already in your history are
|
artist or track, or plays dated in the future). Plays already in your history are
|
||||||
skipped, so importing the same export again, or importing overlapping exports, is safe.
|
skipped, so importing the same export again, or importing overlapping exports, is safe.
|
||||||
|
|
||||||
|
## Your profile image
|
||||||
|
|
||||||
|
Click your name in the page header to open **Profile**, where you can give yourself a
|
||||||
|
picture, shown next to your name. Upload a JPEG, PNG or WebP image, or remove it again.
|
||||||
|
|
||||||
|
If your instance's admin has allowed it, you can also **use your Gravatar**. The server
|
||||||
|
asks Gravatar for the picture linked to your account email, sending it a hash of that
|
||||||
|
address (never the address itself), and keeps a copy; your browser doesn't contact
|
||||||
|
Gravatar. **Refresh Gravatar** fetches it again after you change it there. Choosing an
|
||||||
|
upload replaces a Gravatar and vice versa.
|
||||||
|
|
||||||
|
Your image is private by default. If your instance shares on the fediverse, **Sharing**
|
||||||
|
has a **Share my profile image** switch that shows it on your public profile page and
|
||||||
|
sends it to other servers as your picture. They keep their own copies, so a change or
|
||||||
|
removal can take a while to show up everywhere.
|
||||||
|
|
||||||
## Sharing on the fediverse
|
## Sharing on the fediverse
|
||||||
|
|
||||||
Only available if your instance's admin has turned this on — ask them, or check whether
|
Only available if your instance's admin has turned this on — ask them, or check whether
|
||||||
|
|||||||
@@ -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
@@ -209,10 +209,76 @@ code {
|
|||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
align-items: baseline;
|
align-items: center;
|
||||||
color: var(--ink-soft);
|
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 {
|
main {
|
||||||
max-width: 1120px;
|
max-width: 1120px;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|||||||
@@ -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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// Shared page shell: site header, navigation, sign-in guard.
|
// Shared page shell: site header, navigation, sign-in guard.
|
||||||
|
|
||||||
import { api, getToken, redirectToLogin, setToken } from "./api.js";
|
import { api, getToken, redirectToLogin, setToken } from "./api.js";
|
||||||
|
import { avatarImage } from "./avatar.js";
|
||||||
import { h, replace } from "./dom.js";
|
import { h, replace } from "./dom.js";
|
||||||
|
|
||||||
const NAV = [
|
const NAV = [
|
||||||
@@ -26,7 +27,12 @@ export async function signedInPage(active) {
|
|||||||
h(
|
h(
|
||||||
"div",
|
"div",
|
||||||
{ class: "account" },
|
{ 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"),
|
h("button", { type: "button", class: "link-button", onclick: signOut }, "Sign out"),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { api } from "./api.js";
|
import { api } from "./api.js";
|
||||||
|
import { avatarImage } from "./avatar.js";
|
||||||
import { errorBox, h, replace } from "./dom.js";
|
import { errorBox, h, replace } from "./dom.js";
|
||||||
import { publicPage } from "./layout.js";
|
import { publicPage } from "./layout.js";
|
||||||
|
|
||||||
@@ -22,6 +23,9 @@ try {
|
|||||||
});
|
});
|
||||||
replace(
|
replace(
|
||||||
root,
|
root,
|
||||||
|
profile.has_avatar
|
||||||
|
? avatarImage(profile, "avatar-xl", `/federation/profiles/${encodeURIComponent(username)}/avatar`)
|
||||||
|
: null,
|
||||||
h("h1", {}, profile.display_name),
|
h("h1", {}, profile.display_name),
|
||||||
h("div", { class: "approve-app handle" }, profile.handle),
|
h("div", { class: "approve-app handle" }, profile.handle),
|
||||||
profile.bio ? h("p", { class: "lede profile-bio" }, profile.bio) : null,
|
profile.bio ? h("p", { class: "lede profile-bio" }, profile.bio) : null,
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const FIELDS = [
|
|||||||
"post_milestones",
|
"post_milestones",
|
||||||
"timezone",
|
"timezone",
|
||||||
"now_playing_mode",
|
"now_playing_mode",
|
||||||
|
"share_avatar",
|
||||||
"display_name",
|
"display_name",
|
||||||
"bio",
|
"bio",
|
||||||
];
|
];
|
||||||
@@ -155,6 +156,7 @@ async function save(event) {
|
|||||||
post_milestones: form.elements.post_milestones.checked,
|
post_milestones: form.elements.post_milestones.checked,
|
||||||
timezone: form.elements.timezone.value.trim() || "UTC",
|
timezone: form.elements.timezone.value.trim() || "UTC",
|
||||||
now_playing_mode: form.querySelector("input[name=now_playing_mode]:checked").value,
|
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,
|
display_name: form.elements.display_name.value.trim() || null,
|
||||||
bio: form.elements.bio.value.trim() || null,
|
bio: form.elements.bio.value.trim() || null,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -114,6 +114,10 @@
|
|||||||
<textarea id="bio" name="bio" maxlength="500" rows="3"></textarea>
|
<textarea id="bio" name="bio" maxlength="500" rows="3"></textarea>
|
||||||
<span class="hint">Shown on your fediverse profile. Plain text.</span>
|
<span class="hint">Shown on your fediverse profile. Plain text.</span>
|
||||||
</div>
|
</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>
|
<p class="muted" id="profile-link"></p>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user