Allow bypassing nsfw gate for posts

On instances that are not sfw-only, the nsfw gate for posts can now be
bypassed.
This commit is contained in:
gmnsii 2023-03-22 23:18:35 -07:00
parent e25622dac2
commit e046144bf3
6 changed files with 35 additions and 18 deletions

View file

@ -97,10 +97,11 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, 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 && (setting(&req, "show_nsfw") != "on" || crate::utils::sfw_only()) {
return Ok(nsfw_landing(req).await.unwrap_or_default());
if sub.nsfw && crate::utils::should_be_nsfw_gated(&req, &req_url) {
return Ok(nsfw_landing(req, req_url).await.unwrap_or_default());
}
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub_name.clone(), sort, req.uri().query().unwrap_or_default());
@ -433,3 +434,4 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
nsfw: res["data"]["over18"].as_bool().unwrap_or_default(),
})
}