Added support for quarantined subreddits (#219)

* Added support for quarantined subreddits

* Added confirmation wall for quarantined subreddits

* Added quarantine walls to other routes and fixed case issue

* Correct obsolete use of cookie()

* Refactor param() and quarantine()

Co-authored-by: Spike <19519553+spikecodes@users.noreply.github.com>
This commit is contained in:
curlpipe 2021-05-16 16:53:39 +01:00 committed by GitHub
parent ed05f5a092
commit 8bb247af3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 174 additions and 70 deletions

View file

@ -29,11 +29,11 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
);
// Retrieve other variables from Libreddit request
let sort = param(&path, "sort");
let sort = param(&path, "sort").unwrap_or_default();
let username = req.param("name").unwrap_or_default();
// Request user posts/comments from Reddit
let posts = Post::fetch(&path, "Comment".to_string()).await;
let posts = Post::fetch(&path, "Comment".to_string(), false).await;
let url = String::from(req.uri().path_and_query().map_or("", |val| val.as_str()));
match posts {
@ -44,8 +44,8 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
template(UserTemplate {
user,
posts,
sort: (sort, param(&path, "t")),
ends: (param(&path, "after"), after),
sort: (sort, param(&path, "t").unwrap_or_default()),
ends: (param(&path, "after").unwrap_or_default(), after),
prefs: Preferences::new(req),
url,
})
@ -61,7 +61,7 @@ async fn user(name: &str) -> Result<User, String> {
let path: String = format!("/user/{}/about.json?raw_json=1", name);
// Send a request to the url
match json(path).await {
match json(path, false).await {
// If success, receive JSON in response
Ok(res) => {
// Grab creation date as unix timestamp