diff --git a/Cargo.lock b/Cargo.lock index 8dc4c6e..18750b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,7 +98,7 @@ dependencies = [ "mime_guess", "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -124,20 +124,20 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] name = "atom_syndication" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571832dcff775e26562e8e6930cd483de5587301d40d3a3b85d532b6383e15a7" +checksum = "f2f34613907f31c9dbef0240156db3c9263f34842b6e1a8999d2304ea62c8a30" dependencies = [ "chrono", - "derive_builder", + "derive_builder 0.20.0", "diligent-date-parser", "never", - "quick-xml", + "quick-xml 0.31.0", ] [[package]] @@ -249,10 +249,10 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771aa57f3b17da6c8bcacb187bb9ec9bc81c8160e72342e67c329e0e1651a669" dependencies = [ - "darling", + "darling 0.20.9", "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -275,9 +275,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "num-traits", ] @@ -370,14 +370,38 @@ dependencies = [ "typenum", ] +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core 0.14.4", + "darling_macro 0.14.4", +] + [[package]] name = "darling" version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "83b2eb4d90d12bdda5ed17de686c2acb4c57914f8f921b8da7e112b5a36f3fe1" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.20.9", + "darling_macro 0.20.9", +] + +[[package]] +name = "darling_core" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.10.0", + "syn 1.0.109", ] [[package]] @@ -390,8 +414,19 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", - "syn", + "strsim 0.11.1", + "syn 2.0.68", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core 0.14.4", + "quote", + "syn 1.0.109", ] [[package]] @@ -400,9 +435,9 @@ version = "0.20.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ - "darling_core", + "darling_core 0.20.9", "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -426,7 +461,16 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" dependencies = [ - "derive_builder_macro", + "derive_builder_macro 0.12.0", +] + +[[package]] +name = "derive_builder" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" +dependencies = [ + "derive_builder_macro 0.20.0", ] [[package]] @@ -435,22 +479,44 @@ version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" dependencies = [ - "darling", + "darling 0.14.4", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "derive_builder_core" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" +dependencies = [ + "darling 0.20.9", + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "derive_builder_macro" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" dependencies = [ - "derive_builder_core", + "derive_builder_core 0.12.0", "syn 1.0.109", ] +[[package]] +name = "derive_builder_macro" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" +dependencies = [ + "derive_builder_core 0.20.0", + "syn 2.0.68", +] + [[package]] name = "digest" version = "0.10.7" @@ -957,9 +1023,9 @@ checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -1098,6 +1164,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "quick-xml" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33" +dependencies = [ + "encoding_rs", + "memchr", +] + [[package]] name = "quote" version = "1.0.36" @@ -1242,9 +1318,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7b2c77eb4450d7d5f98df52c381cd6c4e19b75dad9209a9530b85a44510219a" dependencies = [ "atom_syndication", - "derive_builder", + "derive_builder 0.12.0", "never", - "quick-xml", + "quick-xml 0.30.0", ] [[package]] @@ -1267,7 +1343,7 @@ dependencies = [ "proc-macro2", "quote", "rust-embed-utils", - "syn", + "syn 2.0.68", "walkdir", ] @@ -1416,7 +1492,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77253fb2d4451418d07025826028bcb96ee42d3e58859689a70ce62908009db6" dependencies = [ "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -1459,7 +1535,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -1546,6 +1622,12 @@ version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strsim" version = "0.11.1" @@ -1558,6 +1640,17 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.68" @@ -1607,7 +1700,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -1685,7 +1778,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] @@ -2059,7 +2152,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.68", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 880c021..7b63994 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,9 +42,13 @@ fastrand = "2.0.1" log = "0.4.20" pretty_env_logger = "0.5.0" dotenvy = "0.15.7" -rss = "2.0.7" +rss = { version = "2.0.7", optional = true } arc-swap = "1.7.1" +[features] +enable_rss = ["rss"] + + [dev-dependencies] lipsum = "0.9.0" sealed_test = "1.0.0" diff --git a/src/main.rs b/src/main.rs index 406a0d3..a12f655 100644 --- a/src/main.rs +++ b/src/main.rs @@ -254,6 +254,7 @@ 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()); @@ -267,6 +268,7 @@ 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 b6dafca..35cfaac 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -5,7 +5,6 @@ use crate::utils::{ use crate::{client::json, server::ResponseExt, RequestExt}; use askama::Template; use cookie::Cookie; -use hyper::header::CONTENT_TYPE; use hyper::{Body, Request, Response}; use once_cell::sync::Lazy; @@ -460,9 +459,11 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { }) } -use rss::{ChannelBuilder, Item}; - +#[cfg(feature = "enable_rss")] pub async fn rss(req: Request) -> Result, String> { + use hyper::header::CONTENT_TYPE; + use rss::{ChannelBuilder, Item}; + // Get subreddit let sub = req.param("sub").unwrap_or_default(); let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string()); diff --git a/src/user.rs b/src/user.rs index 6bd4c13..e13f64c 100644 --- a/src/user.rs +++ b/src/user.rs @@ -1,9 +1,8 @@ // CRATES use crate::client::json; use crate::server::RequestExt; -use crate::utils::{error, filter_posts, format_url, get_filters, nsfw_landing, param, rewrite_urls, setting, template, Post, Preferences, User}; +use crate::utils::{error, filter_posts, format_url, get_filters, nsfw_landing, param, setting, template, Post, Preferences, User}; use askama::Template; -use hyper::header::CONTENT_TYPE; use hyper::{Body, Request, Response}; use time::{macros::format_description, OffsetDateTime}; @@ -130,9 +129,12 @@ async fn user(name: &str) -> Result { }) } -use rss::{ChannelBuilder, Item}; - +#[cfg(feature = "enable_rss")] pub async fn rss(req: Request) -> Result, String> { + use crate::utils::rewrite_urls; + use hyper::header::CONTENT_TYPE; + use rss::{ChannelBuilder, Item}; + // Get user let user_str = req.param("name").unwrap_or_default();