Change the bypass message and format code
The bypass message now indicates that the bypass is only temporary.
This commit is contained in:
parent
e046144bf3
commit
a0726c5903
4
build.rs
4
build.rs
@ -1,6 +1,4 @@
|
||||
use std::{
|
||||
process::{Command, ExitStatus, Output},
|
||||
};
|
||||
use std::process::{Command, ExitStatus, Output};
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
use std::os::unix::process::ExitStatusExt;
|
||||
|
@ -67,12 +67,12 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
Ok(response) => {
|
||||
let post = parse_post(&response[0]["data"]["children"][0]).await;
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this Reddit deems this post
|
||||
// NSFW, but we have also disabled the display of NSFW content
|
||||
// or if the instance is SFW-only
|
||||
if post.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
|
||||
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
|
||||
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
|
||||
}
|
||||
|
||||
let filters = get_filters(&req);
|
||||
@ -234,4 +234,3 @@ async fn parse_duplicates(json: &serde_json::Value, filters: &HashSet<String>) -
|
||||
let (num_posts_filtered, all_posts_filtered) = filter_posts(&mut duplicates, filters);
|
||||
(duplicates, num_posts_filtered, all_posts_filtered)
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ pub async fn item(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
// Parse the JSON into Post and Comment structs
|
||||
let post = parse_post(&response[0]["data"]["children"][0]).await;
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this Reddit deems this post
|
||||
// NSFW, but we have also disabled the display of NSFW content
|
||||
// or if the instance is SFW-only.
|
||||
@ -190,4 +190,3 @@ fn parse_comments(json: &serde_json::Value, post_link: &str, post_author: &str,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
}
|
||||
};
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this is NSFW community but the user
|
||||
// has disabled the display of NSFW content or if the instance is SFW-only.
|
||||
if sub.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
|
||||
@ -434,4 +434,3 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
|
||||
nsfw: res["data"]["over18"].as_bool().unwrap_or_default(),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||
// Retrieve info from user about page.
|
||||
let user = user(&username).await.unwrap_or_default();
|
||||
|
||||
let req_url = req.uri().to_string();
|
||||
let req_url = req.uri().to_string();
|
||||
// Return landing page if this post if this Reddit deems this user NSFW,
|
||||
// but we have also disabled the display of NSFW content or if the instance
|
||||
// is SFW-only.
|
||||
|
10
src/utils.rs
10
src/utils.rs
@ -895,13 +895,13 @@ pub fn sfw_only() -> bool {
|
||||
|
||||
// Determines if a request shoud redirect to a nsfw landing gate.
|
||||
pub fn should_be_nsfw_gated(req: &Request<Body>, req_url: &String) -> bool {
|
||||
let sfw_instance = sfw_only();
|
||||
let gate_nsfw = (setting(&req, "show_nsfw") != "on") || sfw_instance;
|
||||
let sfw_instance = sfw_only();
|
||||
let gate_nsfw = (setting(&req, "show_nsfw") != "on") || sfw_instance;
|
||||
|
||||
// Nsfw landing gate should not be bypassed on a sfw only instance,
|
||||
let bypass_gate = !sfw_instance && req_url.ends_with("&bypass_nsfw_landing");
|
||||
// Nsfw landing gate should not be bypassed on a sfw only instance,
|
||||
let bypass_gate = !sfw_instance && req_url.ends_with("&bypass_nsfw_landing");
|
||||
|
||||
gate_nsfw && !bypass_gate
|
||||
gate_nsfw && !bypass_gate
|
||||
}
|
||||
|
||||
/// Renders the landing page for NSFW content when the user has not enabled
|
||||
|
@ -20,7 +20,7 @@
|
||||
This instance of Libreddit is SFW-only.</p>
|
||||
{% else %}
|
||||
Enable "Show NSFW posts" in <a href="/settings">settings</a> to view this {% if res_type == crate::utils::ResourceType::Subreddit %}subreddit{% else if res_type == crate::utils::ResourceType::User %}user's posts or comments{% else if res_type == crate::utils::ResourceType::Post %}post{% endif %}. <br>
|
||||
{% if res_type == crate::utils::ResourceType::Post %} You can also bypass this gate by clicking on this <a href="{{url}}&bypass_nsfw_landing">link</a>.{% endif %}
|
||||
{% if res_type == crate::utils::ResourceType::Post %} You can also temporarily bypass this gate and view the post by clicking on this <a href="{{url}}&bypass_nsfw_landing">link</a>.{% endif %}
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user