From dad01749e6f03ec8ab0a1fb90565e4783aced84a Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Fri, 25 Dec 2020 18:06:33 -0800 Subject: [PATCH] Replace Responsive Feature with Secure --- README.md | 4 ++-- src/subreddit.rs | 2 ++ src/utils.rs | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6037f61..6780e18 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,8 @@ Libre + Reddit = [Libreddit](https://libredd.it) - 🚀 Fast: written in Rust for blazing fast speeds and safety - ☁️ Light: no JavaScript, no ads, no tracking - 🕵 Private: all requests are proxied through the server, including media -- 🔒 Safe: does not rely on Reddit OAuth or require a Reddit API Key -- 📱 Responsive: works great on mobile! +- 🦺 Safe: does not rely on Reddit OAuth or require a Reddit API Key +- 🔒 Secure: strong [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) prevents browser requests to Reddit Like [Invidious](https://github.com/iv-org/invidious) but for Reddit. Browse the coldest takes of [r/unpopularopinion](https://libredd.it/r/unpopularopinion) without being [tracked](#reddit). diff --git a/src/subreddit.rs b/src/subreddit.rs index 8847c47..6cfbb56 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -86,9 +86,11 @@ async fn subreddit(sub: &String) -> Result { // Otherwise, grab the JSON output from the request let res = req.unwrap(); + // Metadata regarding the subreddit let members = res["data"]["subscribers"].as_u64().unwrap_or(0); let active = res["data"]["accounts_active"].as_u64().unwrap_or(0); + // Fetch subreddit icon either from the community_icon or icon_img value let community_icon: &str = res["data"]["community_icon"].as_str().unwrap().split("?").collect::>()[0]; let icon = if community_icon.is_empty() { val(&res, "icon_img").await diff --git a/src/utils.rs b/src/utils.rs index d3bc102..ff9d535 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -80,6 +80,7 @@ pub struct ErrorTemplate { // FORMATTING // +// Direct urls to proxy if proxy is enabled pub async fn format_url(url: String) -> String { if url.is_empty() { return String::new(); @@ -92,6 +93,7 @@ pub async fn format_url(url: String) -> String { return url.to_string(); } +// Append `m` and `k` for millions and thousands respectively pub fn format_num(num: i64) -> String { if num > 1000000 { format!("{}m", num / 1000000) @@ -116,6 +118,7 @@ pub async fn nested_val(j: &serde_json::Value, n: &str, k: &str) -> String { String::from(j["data"][n][k].as_str().unwrap()) } +// Fetch posts of a user or subreddit pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec, String), &'static str> { // Send a request to the url, receive JSON in response let req = request(url).await;