From ecfdd29ae761dfa1c22db861eb48695a6797dd6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 28 Oct 2026 12:25:51 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20unknown=20service=20healt?= =?UTF-8?q?h=20parses,=20full=20directory=20read=20only=20after=20resync?= =?UTF-8?q?=20or=20error,=20photo=20ETag=20must=20match=20the=20asked=20ve?= =?UTF-8?q?rsion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/in-web/src/directory.rs | 11 +++++++---- crates/in-web/src/family.rs | 9 ++++++--- crates/in-web/src/pages/photo.rs | 9 +++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/crates/in-web/src/directory.rs b/crates/in-web/src/directory.rs index c622bda..2310f35 100644 --- a/crates/in-web/src/directory.rs +++ b/crates/in-web/src/directory.rs @@ -204,7 +204,7 @@ pub async fn run(state: AppState, mut stop: watch::Receiver) { if *stop.borrow() { return; } - let pause = match round(&state, &oidc, needs_full, &mut stop).await { + let pause = match round(&state, &oidc, &mut needs_full, &mut stop).await { Ok(Ended::Resync) => { needs_full = true; backoff = BACKOFF_FIRST; @@ -234,15 +234,18 @@ pub async fn run(state: AppState, mut stop: watch::Receiver) { } } -/// One round: a full fetch when one is due, then the stream from the stored cursor. +/// One round: a full fetch when one is due, then the stream from the stored cursor. The flag is cleared +/// once the full fetch has applied, so a plain reconnect resumes from the cursor without reading the +/// whole listing again. async fn round( state: &AppState, oidc: &OidcClient, - needs_full: bool, + needs_full: &mut bool, stop: &mut watch::Receiver, ) -> Result { - if needs_full { + if *needs_full { full_sync(state, oidc).await?; + *needs_full = false; } follow(state, oidc, stop).await } diff --git a/crates/in-web/src/family.rs b/crates/in-web/src/family.rs index 4f51d28..0093f9a 100644 --- a/crates/in-web/src/family.rs +++ b/crates/in-web/src/family.rs @@ -33,9 +33,10 @@ pub struct FamilyLink { pub name: String, /// The origin the switcher opens. pub url: String, - /// Whether `im`'s last probe of the service passed. + /// Whether `im`'s last probe of the service passed. `None` when `im` has not probed it yet: it sends + /// `null` (or leaves the field out) before the first probe, and that is shown as unknown. #[serde(default)] - pub healthy: bool, + pub healthy: Option, } /// The body of `GET /api/v1/family`. Unknown fields are ignored. @@ -135,11 +136,13 @@ mod tests { {"key":"in","name":"Files","url":"https://in.example.com"}, {"key":"bad","name":"Bad","url":"javascript:alert(1)"}, {"key":"space","name":"S","url":"https://a.example/ x"}, - {"key":"iz","name":"Board","url":"https://iz.example.com"} + {"key":"iz","name":"Board","url":"https://iz.example.com","healthy":null,"checked_at":null} ]}"#; let links = parse_listing(body).unwrap(); let keys: Vec<&str> = links.iter().map(|l| l.key.as_str()).collect(); assert_eq!(keys, ["im", "iz"]); + assert_eq!(links[0].healthy, Some(true)); + assert_eq!(links[1].healthy, None, "a null probe result is unknown"); assert_eq!( links[1].name, "Board", "the name is kept and escaped when rendered" diff --git a/crates/in-web/src/pages/photo.rs b/crates/in-web/src/pages/photo.rs index aaa9269..787ac96 100644 --- a/crates/in-web/src/pages/photo.rs +++ b/crates/in-web/src/pages/photo.rs @@ -136,6 +136,15 @@ async fn fetch_photo( let Some(content_type) = content_type else { return Ok(None); }; + // `im` answers with its newest photo when the version asked for is older than its own. Such bytes + // must not be cached under the older version, so a mismatch is a retry, not a photo. + let answered = response + .headers() + .get(ETAG) + .and_then(|value| value.to_str().ok()); + if answered != Some(format!("\"p{version}\"").as_str()) { + return Err(unavailable()); + } // The size is checked while the body is read, so an oversized photo is never held whole. let bytes = match read_limited(response, MAX_PHOTO_BYTES).await { Ok(Some(bytes)) => bytes,