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 <noreply@anthropic.com>
This commit is contained in:
17
src/db.rs
17
src/db.rs
@@ -791,6 +791,20 @@ impl Db {
|
|||||||
Ok(())
|
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<Vec<String>> {
|
||||||
|
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
|
/// 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.
|
/// 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<()> {
|
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');",
|
('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
|
).await
|
||||||
.unwrap();
|
.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();
|
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_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());
|
assert!(db.names_image("https://a.example/1.jpg").await.unwrap());
|
||||||
|
|||||||
@@ -1430,7 +1430,11 @@ async fn scan_one(
|
|||||||
if let Some(art) = &parsed.image {
|
if let Some(art) = &parsed.image {
|
||||||
parsed.image = Some(feed::prefer_https(&ctx.client, art, &mut secure).await);
|
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 {
|
for (host, ok) in &secure {
|
||||||
if *ok {
|
if *ok {
|
||||||
ctx.db.secure_images(id, host).await?;
|
ctx.db.secure_images(id, host).await?;
|
||||||
|
|||||||
Reference in New Issue
Block a user