update rss/atom parsing libs

This commit is contained in:
Robin Appelman 2026-10-14 00:23:21 +02:00
commit 8ed96b1064
4 changed files with 75 additions and 426 deletions

View file

@ -13,7 +13,6 @@ use std::hash::{Hash, Hasher};
use std::str::FromStr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::thread::sleep;
use syndication::Feed;
use std::time::{Duration, Instant};
use tracing::{debug, error, info, instrument, warn};
use ureq::http::header::{HeaderValue, USER_AGENT};
@ -222,6 +221,27 @@ impl FeedFetcher {
}
}
/// Taken from the `syndication`, which hasn't seen a release in 6 years, has outdated dependencies, but it also *just* this one `enum`.
#[derive(Clone)]
pub enum Feed {
Atom(atom_syndication::Feed),
RSS(rss::Channel),
}
impl FromStr for Feed {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match atom_syndication::Feed::from_str(s) {
Ok(feed) => Ok(Feed::Atom(feed)),
_ => match rss::Channel::from_str(s) {
Ok(feed) => Ok(Feed::RSS(feed)),
_ => Err("Could not parse XML as Atom or RSS from input"),
},
}
}
}
fn parse_rss_response(response: Response<Body>) -> Result<u64, FetchFeedError> {
let content = response.into_body().read_to_string()?;
let channel = Feed::from_str(&content).map_err(ParseFeedError::Parse)?;