Skip to main content

rss_proxy/plugin/builtin/
nop.rs

1use crate::model::Feed;
2use crate::plugin::Plugin;
3use async_trait::async_trait;
4use tracing::warn;
5
6pub struct NopHandlerPlugin;
7
8impl NopHandlerPlugin {
9    pub fn new() -> Self {
10        Self
11    }
12
13    pub fn make_nop_feed(url: &str, title: &str, reason: &str) -> Feed {
14        Feed {
15            title: format!("{} [NOP]", title),
16            link: url.to_string(),
17            description: format!("Feed marked as NOP: {}", reason),
18            language: Some("en".to_string()),
19            items: Vec::new(),
20        }
21    }
22}
23
24impl Default for NopHandlerPlugin {
25    fn default() -> Self {
26        Self::new()
27    }
28}
29
30#[async_trait]
31impl Plugin for NopHandlerPlugin {
32    fn name(&self) -> &str {
33        "NopHandlerPlugin"
34    }
35
36    async fn on_fetch_error(&self, url: &str, title: &str, error: &anyhow::Error) -> Option<Feed> {
37        let reason = error.to_string();
38        warn!(
39            "Feed '{}' failed upstream fetch ({}). Serving NOP fallback feed.",
40            title, reason
41        );
42        Some(Self::make_nop_feed(url, title, &reason))
43    }
44}