mirror of
https://github.com/redlib-org/redlib.git
synced 2025-06-07 15:17:47 +00:00
Configure default settings using environment variables
This commit is contained in:
parent
83a667347d
commit
e4f9bd7b8d
7 changed files with 103 additions and 81 deletions
|
@ -1,6 +1,6 @@
|
|||
// CRATES
|
||||
use crate::esc;
|
||||
use crate::utils::{catch_random, cookie, error, format_num, format_url, param, redirect, rewrite_urls, template, val, Post, Preferences, Subreddit};
|
||||
use crate::utils::{catch_random, error, format_num, format_url, param, redirect, rewrite_urls, setting, template, val, Post, Preferences, Subreddit};
|
||||
use crate::{client::json, server::ResponseExt, RequestExt};
|
||||
use askama::Template;
|
||||
use cookie::Cookie;
|
||||
|
@ -31,8 +31,8 @@ struct WikiTemplate {
|
|||
// SERVICES
|
||||
pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
// Build Reddit API path
|
||||
let subscribed = cookie(&req, "subscriptions");
|
||||
let front_page = cookie(&req, "front_page");
|
||||
let subscribed = setting(&req, "subscriptions");
|
||||
let front_page = setting(&req, "front_page");
|
||||
let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string());
|
||||
let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or(post_sort));
|
||||
|
||||
|
@ -243,17 +243,22 @@ async fn moderators_list(sub: &str) -> Result<Vec<String>, String> {
|
|||
|
||||
// Retrieve response
|
||||
let response = json(path).await?["data"]["children"].clone();
|
||||
Ok(if let Some(response) = response.as_array() {
|
||||
Ok(
|
||||
// Traverse json tree and format into list of strings
|
||||
response
|
||||
.as_array()
|
||||
.unwrap_or(&Vec::new())
|
||||
.iter()
|
||||
.map(|m| m["name"].as_str().unwrap_or(""))
|
||||
.filter(|m| !m.is_empty())
|
||||
.map(std::string::ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
} else {
|
||||
vec![]
|
||||
})
|
||||
.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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue