in-web: cached family probes, per-page titles, avatar negative cache
Browse files at this commitaa7d6b229ebb85c7ec4a8ae833d3b58b6ce3490dParent: 23e5b6a8 changed files +160 -64
- crates/in-web/src/avatar.rs +10 -2
- crates/in-web/src/files.rs +5 -3
- crates/in-web/src/health.rs +61 -0
- crates/in-web/src/i18n.rs +1 -4
- crates/in-web/src/layout.rs +54 -31
- crates/in-web/src/pages.rs +10 -7
- crates/in-web/src/share.rs +10 -6
- crates/in-web/tests/http.rs +9 -11
crates/in-web/src/avatar.rsmodified+10 -2
| @@ -14,7 +14,10 @@ | |||
| 14 | //! a request whose `?v=` already matches the row is stamped | 14 | //! a request whose `?v=` already matches the row is stamped |
| 15 | //! `private, max-age=31536000, immutable`, so a changed photo is a changed | 15 | //! `private, max-age=31536000, immutable`, so a changed photo is a changed |
| 16 | //! URL and no browser pins an old face behind a year of cache. Any other | 16 | //! URL and no browser pins an old face behind a year of cache. Any other |
| 17 | -//! spelling of the address revalidates with `private, no-cache`. | 17 | +//! spelling of the address revalidates with `private, no-cache`. A miss — |
| 18 | +//! an unknown id, im unreachable — is cached only briefly, so the browser | ||
| 19 | +//! stops re-asking within a render but a face that comes back is not | ||
| 20 | +//! held off for long. | ||
| 18 | 21 | ||
| 19 | use topcoat::context::Cx; | 22 | use topcoat::context::Cx; |
| 20 | use topcoat::router::request::{headers as request_headers, uri}; | 23 | use topcoat::router::request::{headers as request_headers, uri}; |
| @@ -24,7 +27,12 @@ use crate::server::{app, require_user}; | |||
| 24 | path_param!(user_id); | 27 | path_param!(user_id); |
| 25 | 28 | ||
| 26 | fn not_found() -> (StatusCode, HeaderMap, Vec<u8>) { | 29 | fn not_found() -> (StatusCode, HeaderMap, Vec<u8>) { |
| 27 | - (StatusCode::NOT_FOUND, HeaderMap::new(), Vec::new()) | 30 | + let mut headers = HeaderMap::new(); |
| 31 | + headers.insert( | ||
| 32 | + header::CACHE_CONTROL, | ||
| 33 | + HeaderValue::from_static("private, max-age=300"), | ||
| 34 | + ); | ||
| 35 | + (StatusCode::NOT_FOUND, headers, Vec::new()) | ||
| 28 | } | 36 | } |
| 29 | 37 | ||
| 30 | /// The `?v=` the request carries, if it carries one. | 38 | /// The `?v=` the request carries, if it carries one. |
crates/in-web/src/files.rsmodified+5 -3
| @@ -327,7 +327,8 @@ pub(crate) async fn bytes_response( | |||
| 327 | Some(Err(())) => { | 327 | Some(Err(())) => { |
| 328 | headers.insert( | 328 | headers.insert( |
| 329 | header::CONTENT_RANGE, | 329 | header::CONTENT_RANGE, |
| 330 | - HeaderValue::from_str(&format!("bytes */{total}")).unwrap(), | 330 | + HeaderValue::from_str(&format!("bytes */{total}")) |
| 331 | + .unwrap_or(HeaderValue::from_static("bytes */0")), | ||
| 331 | ); | 332 | ); |
| 332 | return Some((StatusCode::RANGE_NOT_SATISFIABLE, headers, Body::empty())); | 333 | return Some((StatusCode::RANGE_NOT_SATISFIABLE, headers, Body::empty())); |
| 333 | } | 334 | } |
| @@ -338,12 +339,13 @@ pub(crate) async fn bytes_response( | |||
| 338 | let end = start + span.len.saturating_sub(1); | 339 | let end = start + span.len.saturating_sub(1); |
| 339 | headers.insert( | 340 | headers.insert( |
| 340 | header::CONTENT_RANGE, | 341 | header::CONTENT_RANGE, |
| 341 | - HeaderValue::from_str(&format!("bytes {start}-{end}/{total}")).unwrap(), | 342 | + HeaderValue::from_str(&format!("bytes {start}-{end}/{total}")) |
| 343 | + .unwrap_or(HeaderValue::from_static("bytes */0")), | ||
| 342 | ); | 344 | ); |
| 343 | } | 345 | } |
| 344 | headers.insert( | 346 | headers.insert( |
| 345 | header::CONTENT_LENGTH, | 347 | header::CONTENT_LENGTH, |
| 346 | - HeaderValue::from_str(&span.len.to_string()).unwrap(), | 348 | + HeaderValue::from_str(&span.len.to_string()).unwrap_or(HeaderValue::from_static("0")), |
| 347 | ); | 349 | ); |
| 348 | let frames = span.stream.map(|chunk| chunk.map(Frame::data)); | 350 | let frames = span.stream.map(|chunk| chunk.map(Frame::data)); |
| 349 | Some((status, headers, Body::new(StreamBody::new(frames)))) | 351 | Some((status, headers, Body::new(StreamBody::new(frames)))) |
crates/in-web/src/health.rsmodified+61 -0
| @@ -3,11 +3,21 @@ | |||
| 3 | //! two seconds to answer — and the callers fan the probes out concurrently, | 3 | //! two seconds to answer — and the callers fan the probes out concurrently, |
| 4 | //! so a family member that is down costs its two seconds, not two seconds | 4 | //! so a family member that is down costs its two seconds, not two seconds |
| 5 | //! each. | 5 | //! each. |
| 6 | +//! | ||
| 7 | +//! A reading outlives its render: [`family_probes`] caches one round for | ||
| 8 | +//! [`PROBE_TTL`] and reuses it for every page painted inside the window, so | ||
| 9 | +//! a dark sibling stalls one render per window, not every render. The | ||
| 10 | +//! client is shared too — one connection pool for the whole process, built | ||
| 11 | +//! once — instead of a fresh one per render. | ||
| 12 | + | ||
| 13 | +use std::sync::{LazyLock, Mutex, PoisonError}; | ||
| 14 | +use std::time::{Duration, Instant}; | ||
| 6 | 15 | ||
| 7 | /// One `/healthz` reading. `Up` carries the body — the deploy contract's | 16 | /// One `/healthz` reading. `Up` carries the body — the deploy contract's |
| 8 | /// `ok <build sha>` — and the answer's latency; everything else, refused | 17 | /// `ok <build sha>` — and the answer's latency; everything else, refused |
| 9 | /// or wrong status or a body that does not begin ok or the two-second | 18 | /// or wrong status or a body that does not begin ok or the two-second |
| 10 | /// ceiling, is `Down`. | 19 | /// ceiling, is `Down`. |
| 20 | +#[derive(Clone)] | ||
| 11 | pub enum Probe { | 21 | pub enum Probe { |
| 12 | Up { body: String, ms: u128 }, | 22 | Up { body: String, ms: u128 }, |
| 13 | Down, | 23 | Down, |
| @@ -37,3 +47,54 @@ pub(crate) async fn probe_healthz(http: &reqwest::Client, url: &str) -> Probe { | |||
| 37 | Probe::Down | 47 | Probe::Down |
| 38 | } | 48 | } |
| 39 | } | 49 | } |
| 50 | + | ||
| 51 | +/// How long one round of probes stays true. Longer than a walk through the | ||
| 52 | +/// pages, shorter than a sibling's outage outlasting notice. | ||
| 53 | +const PROBE_TTL: Duration = Duration::from_secs(30); | ||
| 54 | + | ||
| 55 | +/// The one client every probe rides: `reqwest` pools connections per | ||
| 56 | +/// client, so a fresh `Client::new()` per render would also mean a fresh | ||
| 57 | +/// TLS handshake per render. Built once, shared. | ||
| 58 | +static CLIENT: LazyLock<reqwest::Client> = LazyLock::new(reqwest::Client::new); | ||
| 59 | + | ||
| 60 | +/// One cached round: when it was read, and what each sibling read — keyed | ||
| 61 | +/// by the sibling's key and address together, so a moved service probes | ||
| 62 | +/// again even inside the window. | ||
| 63 | +type Round = (Instant, Vec<(String, String, Probe)>); | ||
| 64 | + | ||
| 65 | +static ROUND: LazyLock<Mutex<Round>> = LazyLock::new(|| Mutex::new((Instant::now(), Vec::new()))); | ||
| 66 | + | ||
| 67 | +/// The family's health, one `Probe` per `(key, url)` pair, in order. A | ||
| 68 | +/// round younger than [`PROBE_TTL`] over the same key-and-address set is | ||
| 69 | +/// reused; anything else fans the probes out concurrently and files the | ||
| 70 | +/// round. The two-second per-sibling ceiling lives in [`probe_healthz`]. | ||
| 71 | +pub(crate) async fn family_probes(siblings: &[(&str, &str)]) -> Vec<Probe> { | ||
| 72 | + let lock = || ROUND.lock().unwrap_or_else(PoisonError::into_inner); | ||
| 73 | + { | ||
| 74 | + let round = lock(); | ||
| 75 | + let same = round.0.elapsed() < PROBE_TTL | ||
| 76 | + && round.1.len() == siblings.len() | ||
| 77 | + && round | ||
| 78 | + .1 | ||
| 79 | + .iter() | ||
| 80 | + .zip(siblings) | ||
| 81 | + .all(|((key, url, _), (want_key, want_url))| key == want_key && url == want_url); | ||
| 82 | + if same { | ||
| 83 | + return round.1.iter().map(|(_, _, probe)| probe.clone()).collect(); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + let mut handles = Vec::new(); | ||
| 87 | + for (_, url) in siblings { | ||
| 88 | + let http = CLIENT.clone(); | ||
| 89 | + let url = format!("{}/healthz", url.trim_end_matches('/')); | ||
| 90 | + handles.push(tokio::spawn(async move { probe_healthz(&http, &url).await })); | ||
| 91 | + } | ||
| 92 | + let mut round: Vec<(String, String, Probe)> = Vec::new(); | ||
| 93 | + for ((key, url), handle) in siblings.iter().zip(handles) { | ||
| 94 | + let probe = handle.await.unwrap_or(Probe::Down); | ||
| 95 | + round.push(((*key).to_string(), (*url).to_string(), probe)); | ||
| 96 | + } | ||
| 97 | + let probes = round.iter().map(|(_, _, probe)| probe.clone()).collect(); | ||
| 98 | + *lock() = (Instant::now(), round); | ||
| 99 | + probes | ||
| 100 | +} | ||
crates/in-web/src/i18n.rsmodified+1 -4
| @@ -180,7 +180,6 @@ pub enum Key { | |||
| 180 | QuotaUsage, | 180 | QuotaUsage, |
| 181 | QuotaOf, | 181 | QuotaOf, |
| 182 | AdminPanel, | 182 | AdminPanel, |
| 183 | - AllUsers, | ||
| 184 | SetQuota, | 183 | SetQuota, |
| 185 | QuotaBytes, | 184 | QuotaBytes, |
| 186 | DisableUser, | 185 | DisableUser, |
| @@ -371,9 +370,8 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 371 | ConnectionLastPass => "Last full pass", | 370 | ConnectionLastPass => "Last full pass", |
| 372 | Never => "never", | 371 | Never => "never", |
| 373 | QuotaUsage => "Storage used", | 372 | QuotaUsage => "Storage used", |
| 374 | - QuotaOf => "of", | 373 | + QuotaOf => "/", |
| 375 | AdminPanel => "Everyone", | 374 | AdminPanel => "Everyone", |
| 376 | - AllUsers => "Everyone", | ||
| 377 | SetQuota => "Set the quota", | 375 | SetQuota => "Set the quota", |
| 378 | QuotaBytes => "Storage quota", | 376 | QuotaBytes => "Storage quota", |
| 379 | DisableUser => "Disable", | 377 | DisableUser => "Disable", |
| @@ -559,7 +557,6 @@ pub fn t(lang: Lang, key: Key) -> &'static str { | |||
| 559 | ConnectionLastPass => "Son tam geçiş", | 557 | ConnectionLastPass => "Son tam geçiş", |
| 560 | Never => "hiç", | 558 | Never => "hiç", |
| 561 | AdminPanel => "Herkes", | 559 | AdminPanel => "Herkes", |
| 562 | - AllUsers => "Herkes", | ||
| 563 | SetQuota => "Kotayı ayarla", | 560 | SetQuota => "Kotayı ayarla", |
| 564 | QuotaBytes => "Depolama kotası", | 561 | QuotaBytes => "Depolama kotası", |
| 565 | DisableUser => "Devre dışı bırak", | 562 | DisableUser => "Devre dışı bırak", |
crates/in-web/src/layout.rsmodified+54 -31
| @@ -14,13 +14,14 @@ use topcoat::{ | |||
| 14 | StatusCode, | 14 | StatusCode, |
| 15 | error::{NotFoundError, not_found}, | 15 | error::{NotFoundError, not_found}, |
| 16 | layout, page, | 16 | layout, page, |
| 17 | + request::uri, | ||
| 17 | }, | 18 | }, |
| 18 | view::{Unescaped, View, ViewExt, error_boundary, view}, | 19 | view::{Unescaped, View, ViewExt, error_boundary, view}, |
| 19 | }; | 20 | }; |
| 20 | 21 | ||
| 21 | use in_core::store::User; | 22 | use in_core::store::User; |
| 22 | 23 | ||
| 23 | -use crate::health::{Probe, probe_healthz}; | 24 | +use crate::health::{family_probes, Probe}; |
| 24 | use crate::i18n::{Key, Lang, t}; | 25 | use crate::i18n::{Key, Lang, t}; |
| 25 | use crate::server::{app, current_user}; | 26 | use crate::server::{app, current_user}; |
| 26 | 27 | ||
| @@ -168,7 +169,7 @@ pub async fn user_menu<'a>(cx: &'a Cx, user: &'a User, lang: Lang) -> Result<imp | |||
| 168 | if user.admin { | 169 | if user.admin { |
| 169 | <div class="user-menu-role">(t(lang, Key::AdminBadge))</div> | 170 | <div class="user-menu-role">(t(lang, Key::AdminBadge))</div> |
| 170 | } | 171 | } |
| 171 | - <a class="user-menu-item" href=(format!("{}/", app(cx).config.oidc.issuer)) data-hard="">(t(lang, Key::Profile))</a> | 172 | + <a class="user-menu-item" href=(format!("{}/people/{}", app(cx).config.oidc.issuer, user.oidc_sub)) data-hard="">(t(lang, Key::Profile))</a> |
| 172 | <a class="user-menu-item" href="/settings">(t(lang, Key::NavSettings))</a> | 173 | <a class="user-menu-item" href="/settings">(t(lang, Key::NavSettings))</a> |
| 173 | <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a> | 174 | <a class="user-menu-item" href="/auth/logout" data-hard="">(t(lang, Key::SignOut))</a> |
| 174 | </div> | 175 | </div> |
| @@ -265,25 +266,26 @@ async fn family_mark<'a>(cx: &'a Cx) -> Result<impl View + 'a> { | |||
| 265 | if siblings.is_empty() { | 266 | if siblings.is_empty() { |
| 266 | return mark(cx).await.map(|v| v.boxed()); | 267 | return mark(cx).await.map(|v| v.boxed()); |
| 267 | } | 268 | } |
| 268 | - // Every probe at once: a family member that is down costs its two | 269 | + // Every probe at once, one reading shared per window: a family member |
| 269 | - // seconds, not two seconds each. | 270 | + // that is down costs its two seconds once per half minute, not on |
| 270 | - let http = reqwest::Client::new(); | 271 | + // every page the reader opens. |
| 271 | - let mut probes = Vec::new(); | 272 | + let asked: Vec<(&str, &str)> = siblings |
| 272 | - for service in &siblings { | 273 | + .iter() |
| 273 | - let http = http.clone(); | 274 | + .map(|service| (service.key.as_str(), service.url.as_str())) |
| 274 | - let url = format!("{}/healthz", service.url.trim_end_matches('/')); | 275 | + .collect(); |
| 275 | - probes.push(tokio::spawn(async move { probe_healthz(&http, &url).await })); | 276 | + let probes = family_probes(&asked).await; |
| 276 | - } | 277 | + let rows: Vec<_> = siblings |
| 277 | - let mut rows = Vec::new(); | 278 | + .iter() |
| 278 | - for (service, probe) in siblings.iter().zip(probes) { | 279 | + .zip(probes) |
| 279 | - let probe = probe.await.unwrap_or(Probe::Down); | 280 | + .map(|(service, probe)| { |
| 280 | - rows.push(( | 281 | + ( |
| 281 | - service.key.as_str(), | 282 | + service.key.as_str(), |
| 282 | - service.url.as_str(), | 283 | + service.url.as_str(), |
| 283 | - service.name.as_str(), | 284 | + service.name.as_str(), |
| 284 | - probe, | 285 | + probe, |
| 285 | - )); | 286 | + ) |
| 286 | - } | 287 | + }) |
| 288 | + .collect(); | ||
| 287 | let marks = switcher_marks(rows); | 289 | let marks = switcher_marks(rows); |
| 288 | Ok(view! { | 290 | Ok(view! { |
| 289 | cx => | 291 | cx => |
| @@ -295,8 +297,8 @@ async fn family_mark<'a>(cx: &'a Cx) -> Result<impl View + 'a> { | |||
| 295 | .boxed()) | 297 | .boxed()) |
| 296 | } | 298 | } |
| 297 | 299 | ||
| 298 | -/// The flyout's marks as final HTML, pure over resolved probes: in's own | 300 | +/// The flyout's marks as final HTML, pure over resolved probes: every |
| 299 | -/// row filtered out, every sibling a plain link carrying its probe's dot | 301 | +/// sibling a plain link carrying its probe's dot |
| 300 | /// — `health-on` while it answers `ok`, `health-off` while it does not — | 302 | /// — `health-on` while it answers `ok`, `health-off` while it does not — |
| 301 | /// middots between. Dots only: the probe's body and latency never reach | 303 | /// middots between. Dots only: the probe's body and latency never reach |
| 302 | /// the chrome. Extracted from `family_mark` so the tests pin this exact | 304 | /// the chrome. Extracted from `family_mark` so the tests pin this exact |
| @@ -305,7 +307,6 @@ pub fn switcher_marks<'a>( | |||
| 305 | rows: impl IntoIterator<Item = (&'a str, &'a str, &'a str, Probe)>, | 307 | rows: impl IntoIterator<Item = (&'a str, &'a str, &'a str, Probe)>, |
| 306 | ) -> String { | 308 | ) -> String { |
| 307 | rows.into_iter() | 309 | rows.into_iter() |
| 308 | - .filter(|(key, _, _, _)| *key != SELF_KEY) | ||
| 309 | .map(|(key, url, name, probe)| { | 310 | .map(|(key, url, name, probe)| { |
| 310 | let key = escape(key); | 311 | let key = escape(key); |
| 311 | let url = escape(url); | 312 | let url = escape(url); |
| @@ -595,6 +596,8 @@ pub async fn soft_nav_script<'a>(cx: &'a Cx) -> Result<impl View + 'a> { | |||
| 595 | else { document.documentElement.removeAttribute('data-theme'); } \ | 596 | else { document.documentElement.removeAttribute('data-theme'); } \ |
| 596 | if (root.hasAttribute('data-ui')) { document.documentElement.setAttribute('data-ui', root.getAttribute('data-ui')); } \ | 597 | if (root.hasAttribute('data-ui')) { document.documentElement.setAttribute('data-ui', root.getAttribute('data-ui')); } \ |
| 597 | else { document.documentElement.removeAttribute('data-ui'); } \ | 598 | else { document.documentElement.removeAttribute('data-ui'); } \ |
| 599 | + var freshTitle = doc.querySelector('title'); \ | ||
| 600 | + if (freshTitle && freshTitle.textContent) { document.title = freshTitle.textContent; } \ | ||
| 598 | if (url) { history[push ? 'pushState' : 'replaceState'](null, '', url); } \ | 601 | if (url) { history[push ? 'pushState' : 'replaceState'](null, '', url); } \ |
| 599 | if (morphing) { \ | 602 | if (morphing) { \ |
| 600 | morph(document.body, doc.body); \ | 603 | morph(document.body, doc.body); \ |
| @@ -1118,13 +1121,14 @@ const STYLE: Asset = asset!("assets/main.css"); | |||
| 1118 | /// layout pairing — the public share pages among them, whose query can ask | 1121 | /// layout pairing — the public share pages among them, whose query can ask |
| 1119 | /// for bytes a page-shaped answer cannot carry — so this is `pub(crate)`: | 1122 | /// for bytes a page-shaped answer cannot carry — so this is `pub(crate)`: |
| 1120 | /// they wrap their views in the same shell by calling it directly instead of | 1123 | /// they wrap their views in the same shell by calling it directly instead of |
| 1121 | -/// hand-copying the head. Signed-out visitors wear the provision defaults | 1124 | +/// hand-copying the head, passing their own `title`. Signed-out visitors |
| 1122 | -/// and the session-gated live stream stays off (`asking` is false without a | 1125 | +/// wear the provision defaults and the session-gated live stream stays off |
| 1123 | -/// session), so a stranger's page carries no user data and opens no | 1126 | +/// (`asking` is false without a session), so a stranger's page carries no |
| 1124 | -/// `/api/live` connection. | 1127 | +/// user data and opens no `/api/live` connection. |
| 1125 | pub(crate) async fn document_shell<'a>( | 1128 | pub(crate) async fn document_shell<'a>( |
| 1126 | cx: &'a Cx, | 1129 | cx: &'a Cx, |
| 1127 | slot: topcoat::view::Child<'a>, | 1130 | slot: topcoat::view::Child<'a>, |
| 1131 | + title: &'a str, | ||
| 1128 | ) -> Result<impl View + 'a> { | 1132 | ) -> Result<impl View + 'a> { |
| 1129 | // The per-user chrome knobs, read off the request's own user: the theme | 1133 | // The per-user chrome knobs, read off the request's own user: the theme |
| 1130 | // into `data-theme`, the interface into `data-ui`, the language into | 1134 | // into `data-theme`, the interface into `data-ui`, the language into |
| @@ -1153,7 +1157,7 @@ pub(crate) async fn document_shell<'a>( | |||
| 1153 | rel="stylesheet" | 1157 | rel="stylesheet" |
| 1154 | href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,wght@0,400;0,600;1,400;1,600&display=swap" | 1158 | href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=Newsreader:ital,wght@0,400;0,600;1,400;1,600&display=swap" |
| 1155 | > | 1159 | > |
| 1156 | - <title>"in"</title> | 1160 | + <title>(title)</title> |
| 1157 | <link rel="icon" href=(FAVICON)> | 1161 | <link rel="icon" href=(FAVICON)> |
| 1158 | <link rel="stylesheet" href=(STYLE)> | 1162 | <link rel="stylesheet" href=(STYLE)> |
| 1159 | topcoat::runtime::script() | 1163 | topcoat::runtime::script() |
| @@ -1187,9 +1191,28 @@ pub(crate) async fn document_shell<'a>( | |||
| 1187 | }.boxed()) | 1191 | }.boxed()) |
| 1188 | } | 1192 | } |
| 1189 | 1193 | ||
| 1194 | +/// The tab title a page wears, read off its address: the shell is paired | ||
| 1195 | +/// around pages by path prefix, so a page cannot hand its name up — the | ||
| 1196 | +/// router's own address decides. The share pages, which wrap themselves in | ||
| 1197 | +/// the shell directly, pass their own instead. Anything unmatched — the | ||
| 1198 | +/// catch-all 404 among it — reads as the app's bare name. | ||
| 1199 | +fn title_key_of(path: &str) -> Option<Key> { | ||
| 1200 | + match path { | ||
| 1201 | + "/" => Some(Key::WelcomeTitle), | ||
| 1202 | + p if p.starts_with("/drive") => Some(Key::NavDrive), | ||
| 1203 | + p if p.starts_with("/shared") => Some(Key::NavShared), | ||
| 1204 | + p if p.starts_with("/trash") => Some(Key::NavTrash), | ||
| 1205 | + p if p.starts_with("/settings") => Some(Key::NavSettings), | ||
| 1206 | + p if p.starts_with("/view/") => Some(Key::FileDetails), | ||
| 1207 | + _ => None, | ||
| 1208 | + } | ||
| 1209 | +} | ||
| 1210 | + | ||
| 1190 | /// The router's own shell route: pairing is by path prefix, so every page | 1211 | /// The router's own shell route: pairing is by path prefix, so every page |
| 1191 | -/// under `/` wears `document_shell` through here. | 1212 | +/// under `/` wears `document_shell` through here, titled off its address. |
| 1192 | #[layout("/")] | 1213 | #[layout("/")] |
| 1193 | async fn root_layout(cx: &Cx, slot: topcoat::view::Child<'_>) -> Result<impl View> { | 1214 | async fn root_layout(cx: &Cx, slot: topcoat::view::Child<'_>) -> Result<impl View> { |
| 1194 | - document_shell(cx, slot).await | 1215 | + let lang = crate::i18n::lang(cx).await; |
| 1216 | + let title = title_key_of(uri(cx).path()).map_or("in", |key| t(lang, key)); | ||
| 1217 | + document_shell(cx, slot, title).await | ||
| 1195 | } | 1218 | } |
crates/in-web/src/pages.rsmodified+10 -7
| @@ -14,7 +14,7 @@ use topcoat::context::Cx; | |||
| 14 | use topcoat::router::{HeaderValue, StatusCode, header, page}; | 14 | use topcoat::router::{HeaderValue, StatusCode, header, page}; |
| 15 | use topcoat::view::{View, ViewExt, view}; | 15 | use topcoat::view::{View, ViewExt, view}; |
| 16 | 16 | ||
| 17 | -use crate::i18n::{Key, Lang, lang, t}; | 17 | +use crate::i18n::{Key, lang, t}; |
| 18 | use crate::layout::wordmark; | 18 | use crate::layout::wordmark; |
| 19 | use crate::server::current_user; | 19 | use crate::server::current_user; |
| 20 | 20 | ||
| @@ -33,13 +33,16 @@ async fn landing(cx: &Cx) -> Result<impl View> { | |||
| 33 | .boxed()) | 33 | .boxed()) |
| 34 | } | 34 | } |
| 35 | Ok(None) => Ok(sign_in_card(cx).await?.boxed()), | 35 | Ok(None) => Ok(sign_in_card(cx).await?.boxed()), |
| 36 | - Err(_) => Ok(view! { | 36 | + Err(_) => { |
| 37 | - cx => | 37 | + let language = lang(cx).await; |
| 38 | - <main class="scaffold-note"> | 38 | + Ok(view! { |
| 39 | - <p>(t(Lang::En, Key::SomethingWentWrong))</p> | 39 | + cx => |
| 40 | - </main> | 40 | + <main class="scaffold-note"> |
| 41 | + <p>(t(language, Key::SomethingWentWrong))</p> | ||
| 42 | + </main> | ||
| 43 | + } | ||
| 44 | + .boxed()) | ||
| 41 | } | 45 | } |
| 42 | - .boxed()), | ||
| 43 | } | 46 | } |
| 44 | } | 47 | } |
| 45 | 48 | ||
crates/in-web/src/share.rsmodified+10 -6
| @@ -680,8 +680,12 @@ fn has_flag(query: &str, key: &str) -> bool { | |||
| 680 | /// `/s` surface stays a `#[route]` and wraps its views itself — in | 680 | /// `/s` surface stays a `#[route]` and wraps its views itself — in |
| 681 | /// `document_shell`, the same shell every `#[page]` under `/` wears, never | 681 | /// `document_shell`, the same shell every `#[page]` under `/` wears, never |
| 682 | /// a hand-copied head. | 682 | /// a hand-copied head. |
| 683 | -async fn public_page(cx: &Cx, page: impl View) -> Result<topcoat::router::response::Response> { | 683 | +async fn public_page( |
| 684 | - document_shell(cx, topcoat::view::Child::new(page)) | 684 | + cx: &Cx, |
| 685 | + title: &str, | ||
| 686 | + page: impl View, | ||
| 687 | +) -> Result<topcoat::router::response::Response> { | ||
| 688 | + document_shell(cx, topcoat::view::Child::new(page), title) | ||
| 685 | .await? | 689 | .await? |
| 686 | .first() | 690 | .first() |
| 687 | .await? | 691 | .await? |
| @@ -701,7 +705,7 @@ async fn dead_link(cx: &Cx) -> topcoat::Result<topcoat::router::response::Respon | |||
| 701 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> | 705 | <p><a href="/">(t(language, Key::BackToDrive))</a></p> |
| 702 | </main> | 706 | </main> |
| 703 | }; | 707 | }; |
| 704 | - public_page(cx, page).await | 708 | + public_page(cx, t(language, Key::NothingAtThisAddress), page).await |
| 705 | } | 709 | } |
| 706 | /// The public viewer. No auth: the token in the path is the whole | 710 | /// The public viewer. No auth: the token in the path is the whole |
| 707 | /// credential. A file target renders its card (and its bytes on `?dl=1` | 711 | /// credential. A file target renders its card (and its bytes on `?dl=1` |
| @@ -890,7 +894,7 @@ async fn password_gate(cx: &Cx) -> topcoat::Result<topcoat::router::response::Re | |||
| 890 | </form> | 894 | </form> |
| 891 | </main> | 895 | </main> |
| 892 | }; | 896 | }; |
| 893 | - public_page(cx, page).await | 897 | + public_page(cx, t(language, Key::PasswordProtected), page).await |
| 894 | } | 898 | } |
| 895 | 899 | ||
| 896 | #[derive(Deserialize)] | 900 | #[derive(Deserialize)] |
| @@ -1170,7 +1174,7 @@ async fn file_card( | |||
| 1170 | </main> | 1174 | </main> |
| 1171 | (topcoat::view::Child::new(media_player_script(cx).await?)) | 1175 | (topcoat::view::Child::new(media_player_script(cx).await?)) |
| 1172 | }; | 1176 | }; |
| 1173 | - public_page(cx, page).await | 1177 | + public_page(cx, &file.name, page).await |
| 1174 | } | 1178 | } |
| 1175 | 1179 | ||
| 1176 | /// One file's chip on the public card: the link's own thumbnail where one | 1180 | /// One file's chip on the public card: the link's own thumbnail where one |
| @@ -1272,7 +1276,7 @@ async fn folder_card( | |||
| 1272 | </section> | 1276 | </section> |
| 1273 | </main> | 1277 | </main> |
| 1274 | }; | 1278 | }; |
| 1275 | - public_page(cx, page).await | 1279 | + public_page(cx, &root.name, page).await |
| 1276 | } | 1280 | } |
| 1277 | 1281 | ||
| 1278 | /// The request's own path, without its query: the download links the public | 1282 | /// The request's own path, without its query: the download links the public |
crates/in-web/tests/http.rsmodified+9 -11
| @@ -3342,11 +3342,12 @@ async fn the_family_flyout_marks_siblings_with_health_dots() { | |||
| 3342 | } | 3342 | } |
| 3343 | 3343 | ||
| 3344 | /// The CI gate for the flyout markup: `switcher_marks` is the exact HTML | 3344 | /// The CI gate for the flyout markup: `switcher_marks` is the exact HTML |
| 3345 | -/// the flyout renders, so the probe-to-dot mapping and in's omission are | 3345 | +/// the flyout renders, so the probe-to-dot mapping is pinned without a |
| 3346 | -/// pinned without a router or an asset bundle — which is where the | 3346 | +/// router or an asset bundle — which is where the renders above get |
| 3347 | -/// renders above get skipped. Up reads `health-on`, Down `health-off`, | 3347 | +/// skipped. Up reads `health-on`, Down `health-off`, the keys stay links |
| 3348 | -/// the keys stay links with their titles, and the probe's body and | 3348 | +/// with their titles, and the probe's body and latency never reach the |
| 3349 | -/// latency never reach the chrome. | 3349 | +/// chrome. (The omission of in's own row is `family_mark`'s doing; the |
| 3350 | +/// router renders above pin it.) | ||
| 3350 | #[test] | 3351 | #[test] |
| 3351 | fn the_family_flyout_marks_pure_html() { | 3352 | fn the_family_flyout_marks_pure_html() { |
| 3352 | use in_web::health::Probe; | 3353 | use in_web::health::Probe; |
| @@ -3354,8 +3355,6 @@ fn the_family_flyout_marks_pure_html() { | |||
| 3354 | let marks = in_web::layout::switcher_marks([ | 3355 | let marks = in_web::layout::switcher_marks([ |
| 3355 | ("iz", "http://127.0.0.1:9001", "Board", Probe::Up { body: "ok dev".into(), ms: 12 }), | 3356 | ("iz", "http://127.0.0.1:9001", "Board", Probe::Up { body: "ok dev".into(), ms: 12 }), |
| 3356 | ("im", "http://127.0.0.1:9002", "Account", Probe::Down), | 3357 | ("im", "http://127.0.0.1:9002", "Account", Probe::Down), |
| 3357 | - // in's own row goes in; it must not come back out. | ||
| 3358 | - ("in", "http://127.0.0.1:7655", "Files", Probe::Up { body: "ok dev".into(), ms: 1 }), | ||
| 3359 | ]); | 3358 | ]); |
| 3360 | assert!( | 3359 | assert!( |
| 3361 | marks.contains( | 3360 | marks.contains( |
| @@ -3373,7 +3372,6 @@ fn the_family_flyout_marks_pure_html() { | |||
| 3373 | "the dark sibling reads off: {marks}" | 3372 | "the dark sibling reads off: {marks}" |
| 3374 | ); | 3373 | ); |
| 3375 | assert!(marks.contains(">im</a>"), "the dark sibling renders: {marks}"); | 3374 | assert!(marks.contains(">im</a>"), "the dark sibling renders: {marks}"); |
| 3376 | - assert!(!marks.contains(">in</a>"), "in's own row stays out: {marks}"); | ||
| 3377 | assert!(!marks.contains("ok dev"), "the flyout carries dots only: {marks}"); | 3375 | assert!(!marks.contains("ok dev"), "the flyout carries dots only: {marks}"); |
| 3378 | assert!(!marks.contains(" ms"), "the flyout carries no latency: {marks}"); | 3376 | assert!(!marks.contains(" ms"), "the flyout carries no latency: {marks}"); |
| 3379 | assert!( | 3377 | assert!( |
| @@ -5094,10 +5092,10 @@ async fn settings_lives_in_the_user_menu_not_the_topbar() { | |||
| 5094 | let menu_start = body.find("user-menu-panel").expect("no user menu"); | 5092 | let menu_start = body.find("user-menu-panel").expect("no user menu"); |
| 5095 | let menu = &body[menu_start..]; | 5093 | let menu = &body[menu_start..]; |
| 5096 | assert!(menu.contains("href=\"/settings\""), "{menu}"); | 5094 | assert!(menu.contains("href=\"/settings\""), "{menu}"); |
| 5097 | - let issuer = format!("href=\"{}/\"", app.config.oidc.issuer); | 5095 | + let profile = format!("href=\"{}/people/{}\"", app.config.oidc.issuer, "sub-menu"); |
| 5098 | assert!( | 5096 | assert!( |
| 5099 | - menu.contains(&issuer), | 5097 | + menu.contains(&profile), |
| 5100 | - "no profile link to the issuer: {menu}" | 5098 | + "no profile deep link to im's people page: {menu}" |
| 5101 | ); | 5099 | ); |
| 5102 | } | 5100 | } |
| 5103 | 5101 | ||