From 38ebc7b02bdcff2a55910cce8c7a313fe29f0293 Mon Sep 17 00:00:00 2001 From: rays Date: Fri, 2 Oct 2026 13:35:51 +0000 Subject: [PATCH] Move old items' http artwork to https too, for hosts the feed no longer names (#110) The first pass only asked the hosts the feed's current body names. IGN's feed kept five 2009 items with artwork on assets1/assets2.ignimgs.com, which its feed no longer mentions, so they stayed on http. A scan now also asks, once per host, the hosts of the feed's stored http artwork (Db::http_images). Co-Authored-By: Claude Opus 5.5 --- src/db.rs | 17 +++++++++++++++++ src/main.rs | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/db.rs b/src/db.rs index 884ce81..efcdf36 100644 --- a/src/db.rs +++ b/src/db.rs @@ -791,6 +791,20 @@ impl Db { Ok(()) } + /// A feed's stored artwork still on http, items' and its own: hosts a feed no longer names + /// keep their old items' artwork on http otherwise (IGN's 2009 items, #110). + pub async fn http_images(&self, feed_id: &str) -> Result> { + self.rows( + "SELECT DISTINCT image FROM entries WHERE feed_id = $1 AND image LIKE 'http://%' + UNION SELECT image FROM feeds WHERE id = $1 AND image LIKE 'http://%'", + vec![feed_id.into()], + ) + .await? + .iter() + .map(|r| Ok(r.try_get("", "image")?)) + .collect() + } + /// Rewrites a feed's stored artwork on `host` from http to https, once the host is known to /// serve it there (`feed::prefer_https`), for the items a scan does not write again. pub async fn secure_images(&self, feed_id: &str, host: &str) -> Result<()> { @@ -2056,6 +2070,9 @@ mod tests { ('f','1',0,'http://a.example/1.jpg'),('f','2',0,'http://b.example/2.jpg'),('g','3',0,'http://a.example/3.jpg');", ).await .unwrap(); + let mut old = db.http_images("f").await.unwrap(); + old.sort(); + assert_eq!(old, ["http://a.example/1.jpg", "http://a.example/logo.png", "http://b.example/2.jpg"]); db.secure_images("f", "a.example").await.unwrap(); assert_eq!(db.feed_summary("f").await.unwrap().image.as_deref(), Some("https://a.example/logo.png")); assert!(db.names_image("https://a.example/1.jpg").await.unwrap()); diff --git a/src/main.rs b/src/main.rs index 0e5422f..7c71730 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1430,7 +1430,11 @@ async fn scan_one( if let Some(art) = &parsed.image { parsed.image = Some(feed::prefer_https(&ctx.client, art, &mut secure).await); } - // Items stored before, which a scan does not write again, move with their host. + // Items stored before, which a scan does not write again, move with their host, and a host + // only they still name is asked too. + for art in ctx.db.http_images(id).await? { + feed::prefer_https(&ctx.client, &art, &mut secure).await; + } for (host, ok) in &secure { if *ok { ctx.db.secure_images(id, host).await?;