RSS feed entries
This commit is contained in:
parent
18f51ed741
commit
c0898fb78c
21
src/poll.rs
21
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<DateTime<Utc>>,
|
||||
updated: Option<DateTime<Utc>>,
|
||||
summary: String,
|
||||
link: Option<String>,
|
||||
}
|
||||
|
||||
#[post("/poll/<feed_id>")]
|
||||
@ -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<Text>, name: &'static str) -> String {
|
||||
item.map(|t| t.content.to_string())
|
||||
.unwrap_or(format!("<no {name}>"))
|
||||
}
|
||||
|
||||
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("<no title>".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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user