mirror of
https://codeberg.org/icewind/rss-webhook-trigger.git
synced 2026-11-30 04:00:49 +01:00
update rss/atom parsing libs
This commit is contained in:
parent
82aaf985ef
commit
8ed96b1064
4 changed files with 75 additions and 426 deletions
|
|
@ -6,7 +6,7 @@ use ureq::http::StatusCode;
|
|||
#[derive(Debug, Error)]
|
||||
pub enum ParseFeedError {
|
||||
#[error("{0}")]
|
||||
Parse(<syndication::Feed as FromStr>::Err),
|
||||
Parse(<crate::Feed as FromStr>::Err),
|
||||
#[error("Empty feed")]
|
||||
Empty,
|
||||
#[error("No guid, pubDate or link set on feed item")]
|
||||
|
|
|
|||
22
src/main.rs
22
src/main.rs
|
|
@ -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)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue