mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-10-01 01:36:12 -04:00
Add support for RSS media enclosures in feeds (#4442)
* Add support for RSS media enclosures in feeds * Use post.url_content_type
This commit is contained in:
parent
677d54ae57
commit
8a6a86c1bb
@ -29,6 +29,7 @@ use once_cell::sync::Lazy;
|
||||
use rss::{
|
||||
extension::{dublincore::DublinCoreExtension, ExtensionBuilder, ExtensionMap},
|
||||
Channel,
|
||||
EnclosureBuilder,
|
||||
Guid,
|
||||
Item,
|
||||
};
|
||||
@ -495,7 +496,6 @@ fn create_post_items(
|
||||
let mut items: Vec<Item> = Vec::new();
|
||||
|
||||
for p in posts {
|
||||
// TODO add images
|
||||
let post_url = format!("{}/post/{}", protocol_and_hostname, p.post.id);
|
||||
let community_url = format!(
|
||||
"{}/c/{}",
|
||||
@ -520,12 +520,21 @@ fn create_post_items(
|
||||
p.counts.comments);
|
||||
|
||||
// If its a url post, add it to the description
|
||||
let link = Some(if let Some(url) = p.post.url {
|
||||
// and see if we can parse it as a media enclosure.
|
||||
let enclosure_opt = p.post.url.map(|url| {
|
||||
let link_html = format!("<br><a href=\"{url}\">{url}</a>");
|
||||
description.push_str(&link_html);
|
||||
url.to_string()
|
||||
} else {
|
||||
post_url.clone()
|
||||
|
||||
let mime_type = p
|
||||
.post
|
||||
.url_content_type
|
||||
.unwrap_or_else(|| "application/octet-stream".to_string());
|
||||
let mut enclosure_bld = EnclosureBuilder::default();
|
||||
|
||||
enclosure_bld.url(url.as_str().to_string());
|
||||
enclosure_bld.mime_type(mime_type);
|
||||
enclosure_bld.length("0".to_string());
|
||||
enclosure_bld.build()
|
||||
});
|
||||
|
||||
if let Some(body) = p.post.body {
|
||||
@ -558,8 +567,9 @@ fn create_post_items(
|
||||
guid,
|
||||
description: Some(sanitize_xml(description)),
|
||||
dublin_core_ext,
|
||||
link,
|
||||
link: Some(post_url.clone()),
|
||||
extensions,
|
||||
enclosure: enclosure_opt,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user