38 lines
1.2 KiB
Rust
38 lines
1.2 KiB
Rust
use crate::state::AppState;
|
|
use axum::{extract::State, http::HeaderMap, response::IntoResponse};
|
|
use reqwest::header;
|
|
use std::sync::Arc;
|
|
|
|
pub async fn stream_handler(State(state): State<Arc<AppState>>) -> impl IntoResponse {
|
|
state.clone().check_update().await;
|
|
|
|
let content = feed(&state.urls.read().await.to_vec());
|
|
|
|
let mut headers = HeaderMap::new();
|
|
headers.insert(header::CONTENT_TYPE, "application/rss+xml".parse().unwrap());
|
|
(headers, content)
|
|
}
|
|
|
|
fn feed(urls: &Vec<String>) -> String {
|
|
let mut ret = String::new();
|
|
ret.push_str(r#"<?xml version="1.0" encoding="UTF-8"?>"#);
|
|
ret.push_str(r#"<rss version="2.0">"#);
|
|
ret.push_str("<channel>");
|
|
ret.push_str("<title>Ö1 Morgenjournal Feed</title>");
|
|
ret.push_str("<link>https://news.hofer.link</link>");
|
|
ret.push_str("<description>Feed für Ö1 Morgenjournal. Live.</description>");
|
|
|
|
for url in urls {
|
|
ret.push_str("<item>");
|
|
ret.push_str(&format!("<title>Morgenjournal</title>"));
|
|
ret.push_str(&format!("<link>{}</link>", quick_xml::escape::escape(url)));
|
|
ret.push_str(&format!("<description>Morgenjournal</description>"));
|
|
ret.push_str("</item>");
|
|
}
|
|
|
|
ret.push_str(" </channel>");
|
|
ret.push_str("</rss>");
|
|
|
|
ret
|
|
}
|