From c0898fb78cf91cf880fa17b7c112b9fa3eaca0bd Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Sun, 2 Feb 2025 23:39:01 -0800 Subject: [PATCH] RSS feed entries --- src/poll.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/poll.rs b/src/poll.rs index d4203b0..bb2a62c 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -1,5 +1,7 @@ use crate::user::AuthenticatedUser; use crate::{feed_utils::fetch_feed, Db}; +use chrono::{DateTime, Utc}; +use feed_rs::model::Text; use rocket::http::Status; use rocket::serde::uuid::Uuid; use rocket::serde::{json::Json, Serialize}; @@ -17,6 +19,10 @@ pub struct FeedPollResponse { struct Entry { id: String, title: String, + published: Option>, + updated: Option>, + summary: String, + link: Option, } #[post("/poll/")] @@ -43,18 +49,23 @@ pub async fn poll_feed( let url = url::Url::parse(&feed_url).map_err(|_| Status::InternalServerError)?; let feed_data = fetch_feed(&url).await.map_err(|_| Status::BadGateway)?; - let count = feed_data.entries.len(); + fn get(item: Option, name: &'static str) -> String { + item.map(|t| t.content.to_string()) + .unwrap_or(format!("")) + } + let entries = feed_data .entries .into_iter() .map(|feed_entry| Entry { id: feed_entry.id, - title: feed_entry - .title - .map(|t| t.content) - .unwrap_or("".to_string()), + title: get(feed_entry.title, "title"), + summary: get(feed_entry.summary, "summary"), + published: feed_entry.published, + updated: feed_entry.updated, + link: feed_entry.links.first().map(|l| l.href.clone()), }) .collect();