Disable dysfunctional moderator list feature

This commit is contained in:
spikecodes 2021-06-11 11:03:36 -07:00
parent f84f4c0326
commit d2002c9027
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
8 changed files with 76 additions and 95 deletions

64
Cargo.lock generated
View File

@ -127,9 +127,9 @@ dependencies = [
[[package]]
name = "bumpalo"
version = "3.6.1"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe"
checksum = "9c59e7af012c713f529e7a3ee57ce9b31ddd858d4b512923602f74608b009631"
[[package]]
name = "bytes"
@ -363,9 +363,9 @@ checksum = "acc499defb3b348f8d8f3f66415835a9131856ff7714bf10dadfc4ec4bdb29a1"
[[package]]
name = "futures-lite"
version = "1.11.3"
version = "1.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4481d0cd0de1d204a4fa55e7d45f07b1d958abcb06714b3446438e2eff695fb"
checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48"
dependencies = [
"fastrand",
"futures-core",
@ -492,9 +492,9 @@ checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440"
[[package]]
name = "hyper"
version = "0.14.8"
version = "0.14.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3f71a7eea53a3f8257a7b4795373ff886397178cd634430ea94e12d7fe4fe34"
checksum = "07d6baa1b441335f3ce5098ac421fb6547c46dda735ca1bc6d0153c838f9dd83"
dependencies = [
"bytes",
"futures-channel",
@ -506,7 +506,7 @@ dependencies = [
"httparse",
"httpdate",
"itoa",
"pin-project",
"pin-project-lite",
"socket2",
"tokio",
"tower-service",
@ -603,13 +603,13 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.95"
version = "0.2.96"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "789da6d93f1b866ffe175afc5322a4d76c038605a1c3319bb57b06967ca98a36"
checksum = "5600b4e6efc5421841a2138a6b082e07fe12f9aaa12783d50e5d13325b26b4fc"
[[package]]
name = "libreddit"
version = "0.14.6"
version = "0.14.7"
dependencies = [
"askama",
"async-recursion",
@ -761,26 +761,6 @@ version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e"
[[package]]
name = "pin-project"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7509cc106041c40a4518d2af7a61530e1eed0e6285296a3d8c5472806ccc4a4"
dependencies = [
"pin-project-internal",
]
[[package]]
name = "pin-project-internal"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48c950132583b500556b1efd71d45b319029f2b71518d979fcc208e16b42426f"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "pin-project-lite"
version = "0.2.6"
@ -944,9 +924,9 @@ dependencies = [
[[package]]
name = "security-framework"
version = "2.2.0"
version = "2.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3670b1d2fdf6084d192bc71ead7aabe6c06aa2ea3fbd9cc3ac111fa5c2b1bd84"
checksum = "23a2ac85147a3a11d77ecf1bc7166ec0b92febfa4461c37944e180f319ece467"
dependencies = [
"bitflags",
"core-foundation",
@ -957,9 +937,9 @@ dependencies = [
[[package]]
name = "security-framework-sys"
version = "2.2.0"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3676258fd3cfe2c9a0ec99ce3038798d847ce3e4bb17746373eb9f0f1ac16339"
checksum = "7e4effb91b4b8b6fb7732e670b6cee160278ff8e6bf485c7805d9e319d76e284"
dependencies = [
"core-foundation-sys",
"libc",
@ -1019,9 +999,9 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d"
[[package]]
name = "signal-hook-registry"
version = "1.3.0"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "16f1d0fef1604ba8f7a073c7e701f213e056707210e9020af4528e0101ce11a6"
checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0"
dependencies = [
"libc",
]
@ -1126,9 +1106,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "syn"
version = "1.0.72"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1e8cdbefb79a9a5a65e0db8b47b723ee907b7c7f8496c76a1770b5c310bab82"
checksum = "f71489ff30030d2ae598524f61326b902466f72a0fb1a8564c001cc63425bcc7"
dependencies = [
"proc-macro2",
"quote",
@ -1205,9 +1185,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.6.0"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd3076b5c8cc18138b8f8814895c11eb4de37114a5d127bafdc5e55798ceef37"
checksum = "0a38d31d7831c6ed7aad00aa4c12d9375fd225a6dd77da1d25b707346319a975"
dependencies = [
"autocfg",
"bytes",
@ -1302,9 +1282,9 @@ dependencies = [
[[package]]
name = "unicode-normalization"
version = "0.1.17"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef"
checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9"
dependencies = [
"tinyvec",
]

View File

@ -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.14.6"
version = "0.14.7"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018"
@ -15,11 +15,11 @@ clap = { version = "2.33.3", default-features = false }
regex = "1.5.4"
serde = { version = "1.0.126", features = ["derive"] }
cookie = "0.15.0"
futures-lite = "1.11.3"
hyper = { version = "0.14.8", features = ["full"] }
futures-lite = "1.12.0"
hyper = { version = "0.14.9", features = ["full"] }
hyper-rustls = "0.22.1"
route-recognizer = "0.3.0"
serde_json = "1.0.64"
tokio = { version = "1.6.0", features = ["full"] }
tokio = { version = "1.6.1", features = ["full"] }
time = "0.2.26"
url = "2.2.2"

View File

@ -1,7 +1,7 @@
// Global specifiers
#![forbid(unsafe_code)]
#![warn(clippy::pedantic, clippy::all)]
#![allow(clippy::needless_pass_by_value, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::find_map)]
#![allow(clippy::needless_pass_by_value, clippy::cast_possible_truncation, clippy::cast_possible_wrap, clippy::manual_find_map)]
// Reference local files
mod post;

View File

@ -53,7 +53,7 @@ pub trait ResponseExt {
impl RequestExt for Request<Body> {
fn params(&self) -> Params {
self.extensions().get::<Params>().unwrap_or(&Params::new()).to_owned()
self.extensions().get::<Params>().unwrap_or(&Params::new()).clone()
// self.extensions()
// .get::<RequestMeta>()
// .and_then(|meta| meta.route_params())
@ -171,7 +171,7 @@ impl Server {
// If a route was configured for this path
Ok(found) => {
let mut parammed = req;
parammed.set_params(found.params().to_owned());
parammed.set_params(found.params().clone());
// Run the route's function
let func = (found.handler().to_owned().to_owned())(parammed);

View File

@ -67,7 +67,7 @@ pub async fn set(req: Request<Body>) -> Result<Response<Body>, String> {
for &name in &PREFS {
match form.get(name) {
Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.to_owned())
Cookie::build(name.to_owned(), value.clone())
.path("/")
.http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52))
@ -106,7 +106,7 @@ fn set_cookies_method(req: Request<Body>, remove_cookies: bool) -> Response<Body
for name in [PREFS.to_vec(), vec!["subscriptions"]].concat() {
match form.get(name) {
Some(value) => response.insert_cookie(
Cookie::build(name.to_owned(), value.to_owned())
Cookie::build(name.to_owned(), value.clone())
.path("/")
.http_only(true)
.expires(OffsetDateTime::now_utc() + Duration::weeks(52))

View File

@ -51,10 +51,10 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
if subscribed.is_empty() {
"popular".to_string()
} else {
subscribed.to_owned()
subscribed.clone()
}
} else {
front_page.to_owned()
front_page.clone()
});
let quarantined = can_access_quarantine(&req, &sub) || root;
@ -273,11 +273,12 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
match json(path, quarantined).await {
// If success, receive JSON in response
Ok(response) => template(WikiTemplate {
wiki: format!(
"{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
rewrite_urls(&val(&response, "description_html").replace("\\", "")),
moderators(&sub, quarantined).await?.join(""),
),
wiki: rewrite_urls(&val(&response, "description_html").replace("\\", "")),
// wiki: format!(
// "{}<hr><h1>Moderators</h1><br><ul>{}</ul>",
// rewrite_urls(&val(&response, "description_html").replace("\\", "")),
// moderators(&sub, quarantined).await.unwrap_or(vec!["Could not fetch moderators".to_string()]).join(""),
// ),
sub,
page: "Sidebar".to_string(),
prefs: Preferences::new(req),
@ -292,39 +293,39 @@ pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
}
}
pub async fn moderators(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// Retrieve and format the html for the moderators list
Ok(
moderators_list(sub, quarantined)
.await?
.iter()
.map(|m| format!("<li><a style=\"color: var(--accent)\" href=\"/u/{name}\">{name}</a></li>", name = m))
.collect(),
)
}
// pub async fn moderators(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// // Retrieve and format the html for the moderators list
// Ok(
// moderators_list(sub, quarantined)
// .await?
// .iter()
// .map(|m| format!("<li><a style=\"color: var(--accent)\" href=\"/u/{name}\">{name}</a></li>", name = m))
// .collect(),
// )
// }
async fn moderators_list(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// Build the moderator list URL
let path: String = format!("/r/{}/about/moderators.json?raw_json=1", sub);
// async fn moderators_list(sub: &str, quarantined: bool) -> Result<Vec<String>, String> {
// // Build the moderator list URL
// let path: String = format!("/r/{}/about/moderators.json?raw_json=1", sub);
// Retrieve response
json(path, quarantined).await.map(|response| {
// Traverse json tree and format into list of strings
response["data"]["children"]
.as_array()
.unwrap_or(&Vec::new())
.iter()
.filter_map(|moderator| {
let name = moderator["name"].as_str().unwrap_or_default();
if name.is_empty() {
None
} else {
Some(name.to_string())
}
})
.collect::<Vec<_>>()
})
}
// // Retrieve response
// json(path, quarantined).await.map(|response| {
// // Traverse json tree and format into list of strings
// response["data"]["children"]
// .as_array()
// .unwrap_or(&Vec::new())
// .iter()
// .filter_map(|moderator| {
// let name = moderator["name"].as_str().unwrap_or_default();
// if name.is_empty() {
// None
// } else {
// Some(name.to_string())
// }
// })
// .collect::<Vec<_>>()
// })
// }
// SUBREDDIT
async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
@ -347,7 +348,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
title: esc!(&res, "title"),
description: esc!(&res, "public_description"),
info: rewrite_urls(&val(&res, "description_html").replace("\\", "")),
moderators: moderators_list(sub, quarantined).await?,
// moderators: moderators_list(sub, quarantined).await.unwrap_or_default(),
icon: format_url(&icon),
members: format_num(members),
active: format_num(active),

View File

@ -253,7 +253,7 @@ impl Post {
posts.push(Self {
id: val(post, "id"),
title: esc!(if title.is_empty() { fallback_title.to_owned() } else { title }),
title: esc!(if title.is_empty() { fallback_title.clone() } else { title }),
community: val(post, "subreddit"),
body: rewrite_urls(&val(post, "body_html")),
author: Author {
@ -362,7 +362,7 @@ pub struct Subreddit {
pub title: String,
pub description: String,
pub info: String,
pub moderators: Vec<String>,
// pub moderators: Vec<String>,
pub icon: String,
pub members: (String, String),
pub active: (String, String),
@ -424,7 +424,7 @@ pub fn param(path: &str, value: &str) -> Option<String> {
.into_owned()
.collect::<HashMap<_, _>>()
.get(value)?
.to_owned(),
.clone(),
)
}

View File

@ -105,14 +105,14 @@
<summary id="sidebar_label">Sidebar</summary>
<div id="sidebar_contents">
{{ sub.info }}
<hr>
{# <hr>
<h2>Moderators</h2>
<br>
<ul>
{% for moderator in sub.moderators %}
<li><a style="color: var(--accent)" href="/u/{{ moderator }}">{{ moderator }}</a></li>
{% endfor %}
</ul>
</ul> #}
</div>
</details>
</aside>