diff --git a/Cargo.toml b/Cargo.toml index 7b63994..6ae4f33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,12 +42,9 @@ fastrand = "2.0.1" log = "0.4.20" pretty_env_logger = "0.5.0" dotenvy = "0.15.7" -rss = { version = "2.0.7", optional = true } +rss = "2.0.7" arc-swap = "1.7.1" -[features] -enable_rss = ["rss"] - [dev-dependencies] lipsum = "0.9.0" diff --git a/README.md b/README.md index 533b628..92f25de 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,7 @@ Assign a default value for each instance-specific setting by passing environment | `ROBOTS_DISABLE_INDEXING` | `["on", "off"]` | `off` | Disables indexing of the instance by search engines. | | `PUSHSHIFT_FRONTEND` | String | `undelete.pullpush.io` | Allows the server to set the Pushshift frontend to be used with "removed" links. | | `PORT` | Integer 0-65535 | `8080` | The **internal** port Redlib listens on. | - +| `ENABLE_RSS` | `["on", "off"]` | `off` | Enables RSS feed generation. | ## Default user settings Assign a default value for each user-modifiable setting by passing environment variables to Redlib in the format `REDLIB_DEFAULT_{Y}`. Replace `{Y}` with the setting name (see list below) in capital letters. diff --git a/app.json b/app.json index d73780c..b08b1fa 100644 --- a/app.json +++ b/app.json @@ -56,8 +56,8 @@ "REDLIB_BANNER": { "required": false }, - "REDLIB_ROBOTS_DISABLE_INDEXING": { - "required": false + "REDLIB_ROBOTS_DISABLE_INDEXING": { + "required": false }, "REDLIB_DEFAULT_SUBSCRIPTIONS": { "required": false @@ -70,6 +70,9 @@ }, "REDLIB_PUSHSHIFT_FRONTEND": { "required": false + }, + "REDLIB_ENABLE_RSS": { + "required": false } } } diff --git a/src/config.rs b/src/config.rs index 2b8c752..f220f48 100644 --- a/src/config.rs +++ b/src/config.rs @@ -103,6 +103,9 @@ pub struct Config { #[serde(rename = "REDLIB_PUSHSHIFT_FRONTEND")] #[serde(alias = "LIBREDDIT_PUSHSHIFT_FRONTEND")] pub(crate) pushshift: Option, + + #[serde(rename = "REDLIB_ENABLE_RSS")] + pub(crate) enable_rss: Option, } impl Config { @@ -148,6 +151,7 @@ impl Config { banner: parse("REDLIB_BANNER"), robots_disable_indexing: parse("REDLIB_ROBOTS_DISABLE_INDEXING"), pushshift: parse("REDLIB_PUSHSHIFT_FRONTEND"), + enable_rss: parse("REDLIB_ENABLE_RSS"), } } } @@ -175,6 +179,7 @@ fn get_setting_from_config(name: &str, config: &Config) -> Option { "REDLIB_BANNER" => config.banner.clone(), "REDLIB_ROBOTS_DISABLE_INDEXING" => config.robots_disable_indexing.clone(), "REDLIB_PUSHSHIFT_FRONTEND" => config.pushshift.clone(), + "REDLIB_ENABLE_RSS" => config.enable_rss.clone(), _ => None, } } diff --git a/src/instance_info.rs b/src/instance_info.rs index 20ffc6d..98e897d 100644 --- a/src/instance_info.rs +++ b/src/instance_info.rs @@ -181,7 +181,8 @@ impl InstanceInfo { Default use HLS: {:?}\n Default hide HLS notification: {:?}\n Default subscriptions: {:?}\n - Default filters: {:?}\n", + Default filters: {:?}\n + RSS enabled: {:?}\n", self.package_name, self.crate_version, self.git_commit, @@ -206,6 +207,7 @@ impl InstanceInfo { self.config.default_hide_hls_notification, self.config.default_subscriptions, self.config.default_filters, + self.config.enable_rss, ) } StringType::Html => self.to_table(), diff --git a/src/main.rs b/src/main.rs index a12f655..406a0d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -254,7 +254,6 @@ async fn main() { app.at("/u/:name/comments/:id/:title/:comment_id").get(|r| post::item(r).boxed()); app.at("/user/[deleted]").get(|req| error(req, "User has deleted their account").boxed()); - #[cfg(feature = "enable_rss")] app.at("/user/:name.rss").get(|r| user::rss(r).boxed()); app.at("/user/:name").get(|r| user::profile(r).boxed()); app.at("/user/:name/:listing").get(|r| user::profile(r).boxed()); @@ -268,7 +267,6 @@ async fn main() { app.at("/settings/update").get(|r| settings::update(r).boxed()); // RSS Subscriptions - #[cfg(feature = "enable_rss")] app.at("/r/:sub.rss").get(|r| subreddit::rss(r).boxed()); // Subreddit services diff --git a/src/subreddit.rs b/src/subreddit.rs index 35cfaac..c038c43 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -1,3 +1,4 @@ +use crate::config; // CRATES use crate::utils::{ catch_random, error, filter_posts, format_num, format_url, get_filters, nsfw_landing, param, redirect, rewrite_urls, setting, template, val, Post, Preferences, Subreddit, @@ -459,8 +460,11 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { }) } -#[cfg(feature = "enable_rss")] 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 hyper::header::CONTENT_TYPE; use rss::{ChannelBuilder, Item}; diff --git a/src/user.rs b/src/user.rs index e13f64c..47d0dd4 100644 --- a/src/user.rs +++ b/src/user.rs @@ -1,5 +1,6 @@ // CRATES use crate::client::json; +use crate::config; use crate::server::RequestExt; use crate::utils::{error, filter_posts, format_url, get_filters, nsfw_landing, param, setting, template, Post, Preferences, User}; use askama::Template; @@ -129,8 +130,10 @@ async fn user(name: &str) -> Result { }) } -#[cfg(feature = "enable_rss")] 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::utils::rewrite_urls; use hyper::header::CONTENT_TYPE; use rss::{ChannelBuilder, Item};