feat(hub): let users upload their own avatar

POST/DELETE /v1/account/avatar (session, exact Origin, CSRF) and public
GET /v1/avatars/<id>. Uploads are sniffed, size and dimension limited,
fully decoded, re-encoded to a 256x256 PNG without metadata and stored in
SQLite, one per account. avatar_url in the session points to it, with the
provider avatar as fallback.
This commit is contained in:
Loki 2026-10-24 21:43:44 +02:00
parent fea876654b
commit e59fa9c713
15 changed files with 1332 additions and 13 deletions

View file

@ -106,6 +106,7 @@ async fn index() -> Html<&'static str> {
async fn headers(request: Request<Body>, next: Next) -> Response {
let mut response = next.run(request).await;
// Handlers that set their own cache policy or CSP (avatar delivery) keep them.
for (name, value) in [
("cache-control", "no-store"),
("x-content-type-options", "nosniff"),
@ -115,6 +116,10 @@ async fn headers(request: Request<Body>, next: Next) -> Response {
"default-src 'none'; style-src 'unsafe-inline'; img-src 'self'; frame-ancestors 'none'",
),
] {
let present = response.headers().contains_key(name);
if present && matches!(name, "cache-control" | "content-security-policy") {
continue;
}
response
.headers_mut()
.insert(name, HeaderValue::from_static(value));