From 3dece7422bf63c60d37e94dc0176d47cb4e293a9 Mon Sep 17 00:00:00 2001 From: osteo-striga Date: Sun, 26 Jul 2026 14:43:44 -0700 Subject: [PATCH] feat(rss) apply image enclosure to user rss feeds as well --- src/subreddit.rs | 2 +- src/user.rs | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/subreddit.rs b/src/subreddit.rs index 34877250..a28bee84 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -649,7 +649,7 @@ pub async fn rss(req: Request) -> Result, String> { } // Set enclosure image for RSS feed item -fn apply_enclosure(item: &mut Item, post: &Post) { +pub fn apply_enclosure(item: &mut Item, post: &Post) { item.set_enclosure(get_rss_image(&post)); // Embed the number of gallery images in description and content since diff --git a/src/user.rs b/src/user.rs index 36a06c44..961fdd51 100644 --- a/src/user.rs +++ b/src/user.rs @@ -136,6 +136,7 @@ pub async fn rss(req: Request) -> Result, String> { if config::get_setting("REDLIB_ENABLE_RSS").is_none() { return Ok(error(req, "RSS is disabled on this instance.").await.unwrap_or_default()); } + use crate::subreddit::apply_enclosure; use crate::utils::rewrite_urls; use hyper::header::CONTENT_TYPE; use rss::{ChannelBuilder, Item}; @@ -148,6 +149,8 @@ pub async fn rss(req: Request) -> Result, String> { // Get path let path = format!("/user/{user_str}/{listing}.json?{}&raw_json=1", req.uri().query().unwrap_or_default(),); + let user_link: String = format!("{}/user/{user_str}", config::get_setting("REDLIB_FULL_URL").unwrap_or_default()); + // Get user let user_obj = user(&user_str).await.unwrap_or_default(); @@ -158,16 +161,22 @@ pub async fn rss(req: Request) -> Result, String> { let channel = ChannelBuilder::default() .title(user_str) .description(user_obj.description) + .link(&user_link) .items( posts .into_iter() - .map(|post| Item { - title: Some(post.title.to_string()), - link: Some(format_url(&utils::get_post_url(&post))), - author: Some(post.author.name), - pub_date: Some(DateTime::from_timestamp(post.created_ts as i64, 0).unwrap_or_default().to_rfc2822()), - content: Some(rewrite_urls(&decode_html(&post.body).unwrap_or_else(|_| post.body.clone()))), - ..Default::default() + .map(|post| { + let mut item = Item { + title: Some(post.title.to_string()), + link: Some(format_url(&utils::get_post_url(&post))), + author: Some(post.author.name.to_string()), + pub_date: Some(DateTime::from_timestamp(post.created_ts as i64, 0).unwrap_or_default().to_rfc2822()), + content: Some(rewrite_urls(&decode_html(&post.body).unwrap_or_else(|_| post.body.clone()))), + ..Default::default() + }; + + apply_enclosure(&mut item, &post); + item }) .collect::>(), )