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?;