From 43ed9756dc8984f35d43a794b24cda8e79024208 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sun, 16 May 2021 09:11:38 -0700 Subject: [PATCH] Upgrade to v0.14 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/post.rs | 6 +++--- src/search.rs | 4 ++-- src/subreddit.rs | 9 +++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 36de61c..195a7dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,7 +609,7 @@ checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e" [[package]] name = "libreddit" -version = "0.13.1" +version = "0.14.0" dependencies = [ "askama", "async-recursion", diff --git a/Cargo.toml b/Cargo.toml index 9ee060d..8e66061 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.13.1" +version = "0.14.0" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/post.rs b/src/post.rs index f6f3226..0cbf0b8 100644 --- a/src/post.rs +++ b/src/post.rs @@ -34,11 +34,11 @@ pub async fn item(req: Request) -> Result, String> { let default_sort = setting(&req, "comment_sort"); // If there's no sort query but there's a default sort, set sort to default_sort - if !default_sort.is_empty() { + if default_sort.is_empty() { + String::new() + } else { path = format!("{}.json?{}&sort={}&raw_json=1", req.uri().path(), req.uri().query().unwrap_or_default(), default_sort); default_sort - } else { - String::new() } }); diff --git a/src/search.rs b/src/search.rs index c0a7e99..edf4e3c 100644 --- a/src/search.rs +++ b/src/search.rs @@ -50,11 +50,11 @@ pub async fn find(req: Request) -> Result, String> { } let query = param(&path, "q").unwrap_or_default(); - let sort = param(&path, "sort").unwrap_or("relevance".to_string()); + let sort = param(&path, "sort").unwrap_or_else(|| "relevance".to_string()); let subreddits = match param(&path, "restrict_sr") { None => search_subreddits(&query).await, - Some(_) => Vec::new() + Some(_) => Vec::new(), }; let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str())); diff --git a/src/subreddit.rs b/src/subreddit.rs index 0477eb2..192daed 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -133,7 +133,7 @@ pub fn quarantine(req: Request, sub: String) -> Result, Str pub async fn add_quarantine_exception(req: Request) -> Result, String> { let subreddit = req.param("sub").ok_or("Invalid URL")?; let redir = param(&format!("?{}", req.uri().query().unwrap_or_default()), "redir").ok_or("Invalid URL")?; - let mut res = redirect(redir.to_owned()); + let mut res = redirect(redir); res.insert_cookie( Cookie::build(&format!("allow_quaran_{}", subreddit.to_lowercase()), "true") .path("/") @@ -205,9 +205,10 @@ pub async fn subscriptions(req: Request) -> Result, String> // Redirect back to subreddit // check for redirect parameter if unsubscribing from outside sidebar - let path = match param(&format!("?{}", query), "redirect") { - Some(redirect_path) => format!("/{}/", redirect_path), - None => format!("/r/{}", sub) + let path = if let Some(redirect_path) = param(&format!("?{}", query), "redirect") { + format!("/{}/", redirect_path) + } else { + format!("/r/{}", sub) }; let mut res = redirect(path);