encode url
All checks were successful
CI/CD Pipeline / test (push) Successful in 1m42s
CI/CD Pipeline / deploy (push) Successful in 1m44s

This commit is contained in:
Philipp Hofer
2025-10-13 09:57:59 +02:00
parent d6f22b4de7
commit 30cd6d2c97
3 changed files with 37 additions and 10 deletions

10
Cargo.lock generated
View File

@@ -820,6 +820,7 @@ dependencies = [
"axum", "axum",
"bytes", "bytes",
"chrono", "chrono",
"quick-xml",
"reqwest", "reqwest",
"serde_json", "serde_json",
"stream-download", "stream-download",
@@ -855,6 +856,15 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "quick-xml"
version = "0.38.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "quinn" name = "quinn"
version = "0.11.8" version = "0.11.8"

View File

@@ -14,3 +14,4 @@ serde_json = "1"
stream-download = "0.22" stream-download = "0.22"
chrono = "0.4" chrono = "0.4"
tokio-cron-scheduler = "0.14" tokio-cron-scheduler = "0.14"
quick-xml = "0.38"

View File

@@ -16,21 +16,37 @@ pub async fn stream_handler(State(state): State<Arc<AppState>>) -> impl IntoResp
fn feed(urls: &Vec<String>) -> String { fn feed(urls: &Vec<String>) -> String {
let mut ret = String::new(); let mut ret = String::new();
ret.push_str(r#"<?xml version="1.0" encoding="UTF-8"?>"#); ret.push_str(r#"<?xml version="1.0" encoding="UTF-8"?>"#);
ret.push('\n');
ret.push_str(r#"<rss version="2.0">"#); ret.push_str(r#"<rss version="2.0">"#);
ret.push_str("<channel>"); ret.push('\n');
ret.push_str("<title>Ö1 Morgenjournal Feed</title>"); ret.push_str(" <channel>");
ret.push_str("<link>https://news.hofer.link</link>"); ret.push('\n');
ret.push_str("<description>Feed für Ö1 Morgenjournal. Live.</description>"); ret.push_str(" <title>Ö1 Morgenjournal Feed</title>");
ret.push('\n');
ret.push_str(" <link>https://news.hofer.link</link>");
ret.push('\n');
ret.push_str(" <description>Feed für Ö1 Morgenjournal. Live.</description>");
ret.push('\n');
for url in urls { for url in urls {
ret.push_str("<item>"); ret.push_str(" <item>");
ret.push_str(&format!("<title>Morgenjournal DATE</title>")); ret.push('\n');
ret.push_str(&format!("<link>{url}</link>")); ret.push_str(&format!(" <title>Morgenjournal DATE</title>"));
ret.push_str(&format!("<description>{url}</description>")); ret.push('\n');
ret.push_str("</item>"); ret.push_str(&format!(
" <link>{}</link>",
quick_xml::escape::escape(url)
));
ret.push('\n');
ret.push_str(&format!(" <description>my desc</description>"));
ret.push('\n');
ret.push_str(" </item>");
ret.push('\n');
} }
ret.push_str("</channel>"); ret.push_str(" </channel>");
ret.push('\n');
ret.push_str("</rss>");
ret ret
} }