~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

A host's operator names it and gives the console their own look

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:branding/to-main
.changeset/appearance-choice.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# Choose to see the console light or dark
The menu under your handle has Appearance: System, Light or Dark. A choice takes effect at once, is kept in a cookie of the console's own for a year, and every page is drawn in it from its first byte. System, as before, follows the device.
.changeset/authorize-alone.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# Approving an app is a page of its own, over the host's background
The page an app's request is approved on is one card, without the console's header and footer: at its top, the host's name and logo and who is signed in, whose menu switches account, adds one or signs out. With one group to approve, Decline sits beside its button. "Technical details" and the operator's links are at the card's foot. `BACKGROUND_LIGHT_URL` and `BACKGROUND_DARK_URL` set the picture behind the card, served at `/img/background-light` and `/img/background-dark`, and `getBrand` names them as `backgrounds`.
.changeset/host-branding.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# A host's operator names it, and gives it a logo and links to their pages
`SERVICE_NAME`, `LOGO_URL`, `HOME_URL`, `PRIVACY_POLICY_URL`, `TERMS_OF_SERVICE_URL`, `SUPPORT_URL` and `CONTACT_EMAIL` say how the host shows itself. The console draws the name and logo in its header and its pages' titles, and links the operator's pages from its footer, reading them from the host by `org.atgrp.internal.getBrand`. The host serves its logo at `/img/host`, read as an app's logo is: only a PNG, JPEG, GIF or WebP image of at most 256 KiB. `describeServer` gives the privacy policy and terms of service as its `links`, and the email address as its `contact`. Unset, the console is Atmosphere Groups as before.
.changeset/host-colours.mdnew+7−0
@@ -0,0 +1,7 @@
---
default: minor
---
# A host's operator sets the colour that acts, and the console's palette
`PRIMARY_COLOR` and `PRIMARY_COLOR_DARK`, each `#rgb` or `#rrggbb`, make the console's buttons, links and marks the operator's colour, with their hover, wash and link line mixed from it and the text on a button whichever of white or the page's ink reads better. Without a dark one, the light one is lifted lighter. `PALETTE` sets the rest of the console, its paper, cards, lines and ink: `paper`, its own warm one, or a gray faintly tinted to go with a primary colour, `slate` (blue), `neutral` (none), `sage` (green) or `mauve` (purple). `getBrand` answers them as `colors` and `palette`; the host refuses to start on any other colour or palette. In dark, the quietest text reads more clearly on the console's wells.
crates/group-host/src/api.rs+9−2
@@ -117,14 +117,21 @@ pub async fn check_address(State(host): State<Arc<Host>>, Query(p): Query<Params
Ok(Json(json!({ "address": address, "available": available })))
}
/// The host as a PDS describes itself: its DID, and the domain whose names
/// it gives its groups. Nobody signs up here: a group is made for someone.
/// The host as a PDS describes itself: its DID, the domain whose names it
/// gives its groups, and its operator's policies and address, as far as
/// set. Nobody signs up here: a group is made for someone.
pub async fn describe_server(State(host): State<Arc<Host>>) -> Json<Value> {
let b = &host.config.brand;
Json(json!({
"did": host.config.service_did,
"availableUserDomains": [host.config.handle_domain],
"inviteCodeRequired": true,
"blobUploadLimit": host.config.blob_upload_limit,
"links": crate::brand::set([
("privacyPolicy", &b.privacy_policy),
("termsOfService", &b.terms_of_service),
]),
"contact": crate::brand::set([("email", &b.contact_email)]),
}))
}
crates/group-host/src/apps.rs+39−17
@@ -29,7 +29,7 @@ const KEEP_FOR: i64 = 10 * 60_000;
/// How many apps' logos are kept at once.
const KEEP_AT_MOST: usize = 100;
/// The most bytes a logo may be.
const LOGO_AT_MOST: usize = 256 * 1024;
pub(crate) const LOGO_AT_MOST: usize = 256 * 1024;
/// An app's logo: its type, as its bytes say, and its bytes.
#[derive(Debug, Clone, PartialEq)]
@@ -130,21 +130,21 @@ impl Host {
/// whose metadata names no logo a page may show, or whose logo is no
/// image.
pub async fn logo(&self, id: &str, now: i64) -> Option<Logo> {
if let Some(kept) = self.logos.get(id, now) {
return kept;
}
let logo = self.read_logo(id, now).await;
tracing::info!(client = id, found = logo.is_some(), "read a logo");
self.logos.keep(id, now, logo.clone());
logo
kept(&self.logos, id, now, self.read_logo(id, now)).await
}
async fn read_logo(&self, id: &str, now: i64) -> Option<Logo> {
let view = self.client_view(id, now).await?;
let asked = self.guarded.get(view["logo"].as_str()?).ok()?;
self.read_image(view["logo"].as_str()?, LOGO_AT_MOST).await
}
/// The image at `url`, read as a logo is: from a public address, at
/// most `at_most` bytes, and only an image by its first bytes.
pub(crate) async fn read_image(&self, url: &str, at_most: usize) -> Option<Logo> {
let asked = self.guarded.get(url).ok()?;
let res = asked.send().await.ok()?;
let res = res.error_for_status().ok()?;
let bytes = capped(res, LOGO_AT_MOST).await?;
let bytes = capped(res, at_most).await?;
let kind = image_kind(&bytes)?;
Some(Logo {
kind,
@@ -153,13 +153,25 @@ impl Host {
}
}
/// The logo of the app `?id=` names, for a page to draw: nothing for one
/// the host does not serve.
pub async fn logo(State(host): State<Arc<Host>>, Query(p): Query<Params>) -> Response {
let id = p.get("id").map(String::as_str).unwrap_or_default();
let Some(logo) = host.logo(id, now_millis()).await else {
return StatusCode::NOT_FOUND.into_response();
};
/// The logo `logos` keeps under `key`, or else the one `read` reads, kept
/// for next time either way.
pub(crate) async fn kept(
logos: &Logos,
key: &str,
now: i64,
read: impl Future<Output = Option<Logo>>,
) -> Option<Logo> {
if let Some(kept) = logos.get(key, now) {
return kept;
}
let logo = read.await;
tracing::info!(of = key, found = logo.is_some(), "read a logo");
logos.keep(key, now, logo.clone());
logo
}
/// A logo as a page is to draw it: as an image, and nothing more.
pub(crate) fn served(logo: Logo) -> Response {
let headers = [
(header::CONTENT_TYPE, logo.kind),
(header::X_CONTENT_TYPE_OPTIONS, "nosniff"),
@@ -171,3 +183,13 @@ pub async fn logo(State(host): State<Arc<Host>>, Query(p): Query<Params>) -> Res
];
(headers, logo.bytes).into_response()
}
/// The logo of the app `?id=` names, for a page to draw: nothing for one
/// the host does not serve.
pub async fn logo(State(host): State<Arc<Host>>, Query(p): Query<Params>) -> Response {
let id = p.get("id").map(String::as_str).unwrap_or_default();
match host.logo(id, now_millis()).await {
Some(logo) => served(logo),
None => StatusCode::NOT_FOUND.into_response(),
}
}
crates/group-host/src/brand.rsnew+88−0
@@ -0,0 +1,88 @@
//! How the host shows itself, as its operator names it (`config::Brand`):
//! its name, logo, pages and backgrounds, for the console to draw
//! (`getBrand`), and its pictures served from here, read as an app's logo
//! is (`apps`), so that a reader's browser asks no other server for them:
//! its logo at `/img/host`, its backgrounds at `/img/background-light`
//! and `/img/background-dark`.
use crate::Host;
use crate::apps::{LOGO_AT_MOST, Logo, kept, served};
use crate::time::now_millis;
use axum::Json;
use axum::extract::State;
use axum::http::StatusCode;
use axum::response::{IntoResponse, Response};
use serde_json::{Map, Value, json};
use std::sync::Arc;
/// The most bytes a background may be: a photograph, larger than a logo.
const BACKGROUND_AT_MOST: usize = 2 * 1024 * 1024;
/// The fields of `fields` that are set, as an object.
pub(crate) fn set<const N: usize>(fields: [(&str, &Option<String>); N]) -> Value {
let set = fields
.into_iter()
.filter_map(|(k, v)| Some((k.to_string(), json!(v.as_ref()?))));
Value::Object(set.collect::<Map<_, _>>())
}
/// How the host shows itself: its name and logo, the links to its
/// operator's pages, its backgrounds, its colours and the console's
/// palette it's in, each only when set.
pub async fn get_brand(State(host): State<Arc<Host>>) -> Json<Value> {
let b = &host.config.brand;
let mut brand = set([
("name", &b.name),
("logo", &b.logo),
("palette", &b.palette),
]);
brand["links"] = set([
("home", &b.home),
("privacyPolicy", &b.privacy_policy),
("termsOfService", &b.terms_of_service),
("support", &b.support),
]);
brand["backgrounds"] = set([("light", &b.background_light), ("dark", &b.background_dark)]);
brand["colors"] = set([
("primary", &b.primary_color),
("primaryDark", &b.primary_color_dark),
]);
Json(brand)
}
impl Host {
/// The host's own picture `key` names, at `url`, kept or read now:
/// none when it names none, or when what it names is no image of at
/// most `at_most` bytes.
async fn own_image(&self, key: &str, url: Option<&str>, at_most: usize) -> Option<Logo> {
let url = url?;
let now = now_millis();
kept(&self.host_images, key, now, self.read_image(url, at_most)).await
}
}
/// A picture for a page to draw, or nothing.
fn answer(image: Option<Logo>) -> Response {
match image {
Some(image) => served(image),
None => StatusCode::NOT_FOUND.into_response(),
}
}
/// The host's logo: nothing when it has none.
pub async fn logo(State(host): State<Arc<Host>>) -> Response {
let url = host.config.brand.logo.as_deref();
answer(host.own_image("logo", url, LOGO_AT_MOST).await)
}
/// The host's background in a light colour scheme: nothing when it has none.
pub async fn background_light(State(host): State<Arc<Host>>) -> Response {
let url = host.config.brand.background_light.as_deref();
answer(host.own_image("light", url, BACKGROUND_AT_MOST).await)
}
/// The host's background in a dark colour scheme: nothing when it has none.
pub async fn background_dark(State(host): State<Arc<Host>>) -> Response {
let url = host.config.brand.background_dark.as_deref();
answer(host.own_image("dark", url, BACKGROUND_AT_MOST).await)
}
crates/group-host/src/config.rs+106−0
@@ -84,6 +84,110 @@ pub struct Config {
/// Whether it limits how much one caller asks, `RATE_LIMITS`: `on`,
/// unless `off` (`limits`).
pub rate_limits: bool,
/// How it shows itself to people: its name, logo and pages.
pub brand: Brand,
}
/// How the host shows itself on its pages, as its operator names it: none
/// of it set, the console's own name, and no logo or links.
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Brand {
/// Its name, `SERVICE_NAME`, at most [`NAME_AT_MOST`] characters.
pub name: Option<String>,
/// Its logo, `LOGO_URL`, which it serves at `/img/host`.
pub logo: Option<String>,
/// Its operator's home page, `HOME_URL`.
pub home: Option<String>,
/// Its privacy policy, `PRIVACY_POLICY_URL`.
pub privacy_policy: Option<String>,
/// Its terms of service, `TERMS_OF_SERVICE_URL`.
pub terms_of_service: Option<String>,
/// Where people get help, `SUPPORT_URL`.
pub support: Option<String>,
/// Where its operator is written to, `CONTACT_EMAIL`.
pub contact_email: Option<String>,
/// The picture behind the card an app's request is approved on, in a
/// light colour scheme, `BACKGROUND_LIGHT_URL`, served at
/// `/img/background-light`.
pub background_light: Option<String>,
/// And in a dark one, `BACKGROUND_DARK_URL`, at `/img/background-dark`.
pub background_dark: Option<String>,
/// The colour of what acts on its pages, `PRIMARY_COLOR`, as `#rrggbb`
/// or `#rgb`, lower case.
pub primary_color: Option<String>,
/// The same in a dark colour scheme, `PRIMARY_COLOR_DARK`: unset, the
/// console lifts `primary_color` lighter.
pub primary_color_dark: Option<String>,
/// Which of the console's palettes its pages are in, `PALETTE`, one of
/// [`PALETTES`] but the first, `paper`, which is none.
pub palette: Option<String>,
}
/// The most characters a host's name may be, as a page's header has room for.
pub const NAME_AT_MOST: usize = 40;
/// The console's palettes, its own first.
pub const PALETTES: [&str; 5] = ["paper", "slate", "neutral", "sage", "mauve"];
impl Brand {
/// The brand `var` names, each variable left empty as unset.
fn from(var: &impl Fn(&str) -> Option<String>) -> Result<Brand> {
let set = |name: &str| {
var(name)
.map(|v| v.trim().to_string())
.filter(|v| !v.is_empty())
};
let page = |name: &str| -> Result<Option<String>> {
let Some(url) = set(name) else {
return Ok(None);
};
match reqwest::Url::parse(&url) {
Ok(u) if ["https", "http"].contains(&u.scheme()) => Ok(Some(url)),
_ => bail!("{name} is no http or https URL: {url}"),
}
};
let name = set("SERVICE_NAME");
if let Some(n) = name.as_ref().filter(|n| n.chars().count() > NAME_AT_MOST) {
bail!("SERVICE_NAME is at most {NAME_AT_MOST} characters: {n}");
}
let contact_email = set("CONTACT_EMAIL");
if let Some(e) = contact_email.as_ref().filter(|e| !e.contains('@')) {
bail!("CONTACT_EMAIL is no email address: {e}");
}
// Only a colour as #rgb or #rrggbb: one the console writes into its
// styles as it is.
let colour = |name: &str| -> Result<Option<String>> {
let Some(c) = set(name) else {
return Ok(None);
};
let hex =
|h: &&str| [3, 6].contains(&h.len()) && h.chars().all(|d| d.is_ascii_hexdigit());
match c.strip_prefix('#').filter(hex) {
Some(_) => Ok(Some(c.to_ascii_lowercase())),
None => bail!("{name} is a colour as #rgb or #rrggbb, not {c}"),
}
};
let palette = match set("PALETTE") {
Some(p) if !PALETTES.contains(&p.as_str()) => {
bail!("PALETTE is one of {}, not {p}", PALETTES.join(", "))
}
p => p.filter(|p| p != PALETTES[0]),
};
Ok(Brand {
name,
logo: page("LOGO_URL")?,
home: page("HOME_URL")?,
privacy_policy: page("PRIVACY_POLICY_URL")?,
terms_of_service: page("TERMS_OF_SERVICE_URL")?,
support: page("SUPPORT_URL")?,
contact_email,
background_light: page("BACKGROUND_LIGHT_URL")?,
background_dark: page("BACKGROUND_DARK_URL")?,
primary_color: colour("PRIMARY_COLOR")?,
primary_color_dark: colour("PRIMARY_COLOR_DARK")?,
palette,
})
}
}
/// The service that finds anyone on the network by what is typed.
@@ -203,6 +307,7 @@ impl Config {
Some("off") => false,
Some(other) => bail!("RATE_LIMITS is on or off, not {other}"),
};
let brand = Brand::from(&var)?;
Ok(Config {
port,
public_url,
@@ -225,6 +330,7 @@ impl Config {
logs_keep,
domain_check_at,
rate_limits,
brand,
})
}
crates/group-host/src/lexicons.rs+1−0
@@ -79,6 +79,7 @@ pub const FILES: &[&str] = &[
lexicon!("org/atgrp/internal/getActorGroups"),
lexicon!("org/atgrp/internal/getActorInvites"),
lexicon!("org/atgrp/internal/getAuthorization"),
lexicon!("org/atgrp/internal/getBrand"),
lexicon!("org/atgrp/internal/getGroup"),
lexicon!("org/atgrp/internal/getGroupAuth"),
lexicon!("org/atgrp/internal/getJoinRequest"),
crates/group-host/src/lib.rs+8−0
@@ -14,6 +14,7 @@ pub mod authority;
pub mod authority_api;
pub mod authorization;
pub mod blobs;
pub mod brand;
pub mod config;
pub mod console_login;
pub mod firehose;
@@ -109,6 +110,8 @@ pub struct Host {
pub(crate) lexicons: permission_sets::Read,
/// Apps' logos, as read.
pub(crate) logos: apps::Logos,
/// Its own pictures, its logo and backgrounds, as read.
pub(crate) host_images: apps::Logos,
/// The lines it logged, kept for its operators.
pub logs: Arc<logs::Logs>,
/// How it is used, counted for its operators.
@@ -156,6 +159,7 @@ impl Host {
handles: Default::default(),
lexicons: Default::default(),
logos: Default::default(),
host_images: Default::default(),
logs: Arc::new(logs),
stats,
limits,
@@ -383,6 +387,7 @@ pub(crate) fn routes(host: Arc<Host>) -> Router {
"/xrpc/org.atgrp.internal.getViewer",
get(actors::get_viewer),
)
.route("/xrpc/org.atgrp.internal.getBrand", get(brand::get_brand))
.route("/xrpc/org.atgrp.internal.getActor", get(actors::get_actor))
.route(
"/xrpc/org.atgrp.internal.getActorGroups",
@@ -480,6 +485,9 @@ pub(crate) fn routes(host: Arc<Host>) -> Router {
get(console_login::client_metadata),
)
.route("/img/app", get(apps::logo))
.route("/img/host", get(brand::logo))
.route("/img/background-light", get(brand::background_light))
.route("/img/background-dark", get(brand::background_dark))
.route("/img/{did}/{cid}", get(blobs::image))
.route("/console/login", get(console_login::login))
.route("/console/move/login", get(account_move::login))
crates/group-host/tests/brand.rsnew+162−0
crates/group-host/tests/config.rs+77−1
deploy/docker-compose.yml+14−0
docs/design/signing-in.md+9−0
docs/guides/shots/apps-activity-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-activity.png+0−0
A binary file, not shown.
docs/guides/shots/apps-approve-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-approve.png+0−0
A binary file, not shown.
docs/guides/shots/apps-approve.txt+3−5
docs/guides/shots/apps-made-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-made.png+0−0
A binary file, not shown.
docs/guides/shots/apps-signed-in-dark.png+0−0
A binary file, not shown.
docs/guides/shots/apps-signed-in.png+0−0
A binary file, not shown.
docs/guides/signing-in-as-a-group.md+7−5
docs/reference/api.md+3−1
docs/reference/config.md+28−2
docs/deploying.md+1−0
harness/e2e/flows.spec.mjs+20−0
lexicons/org/atgrp/internal/getBrand.jsonnew+110−0
web/messages/en.json+19−14
web/src/lib/atoms/Title.sveltenew+10−0
web/src/lib/molecules/Appearance.sveltenew+26−0
web/src/lib/molecules/AskedScopes.sveltenew+14−0
web/src/lib/molecules/SiteBrand.sveltenew+14−0
web/src/lib/molecules/SiteLinks.sveltenew+13−0
web/src/lib/molecules/UserMenu.svelte+21−11
web/src/lib/organisms/AuthorizeRequest.svelte+30−24
web/src/lib/organisms/SiteFooter.svelte+12−3
web/src/lib/organisms/SiteHeader.svelte+6−3
web/src/lib/templates/Alone.sveltenew+32−0
web/src/lib/appearance.tsnew+28−0
web/src/lib/brand.tsnew+103−0
web/src/routes/authorize/+page.server.ts+4−3
web/src/routes/authorize/+page.svelte+35−5
web/src/routes/g/[handle]/moderation/+page.svelte+2−3
web/src/routes/g/[handle]/settings/apps/+page.svelte+2−4
web/src/routes/g/[handle]/settings/labels/+page.svelte+2−4
web/src/routes/g/[handle]/settings/recovery/+page.svelte+2−4
web/src/routes/g/[handle]/settings/roles/+page.svelte+2−4
web/src/routes/g/[handle]/settings/rules/+page.svelte+2−4
web/src/routes/g/[handle]/settings/+page.svelte+2−3
web/src/routes/g/[handle]/+page.svelte+2−1
web/src/routes/move/+page.svelte+2−1
web/src/routes/new/+page.svelte+2−1
web/src/routes/+error.svelte+2−1
web/src/routes/+layout.server.tsnew+20−0
web/src/routes/+layout.svelte+22−8
web/src/routes/+layout.ts+6−2
web/src/routes/+page.svelte+3−2
web/src/app.css+122−5
web/src/app.d.ts+15−1
web/src/app.html+1−1
web/src/hooks.server.ts+16−4
web/src/tokens.css+102−82