Resolve merge conflicts

This commit is contained in:
Robin 2021-01-23 10:55:11 +01:00
commit b2ad2f636c
9 changed files with 57 additions and 70 deletions

30
Cargo.lock generated
View File

@ -410,9 +410,9 @@ dependencies = [
[[package]] [[package]]
name = "backtrace" name = "backtrace"
version = "0.3.55" version = "0.3.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598" checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc"
dependencies = [ dependencies = [
"addr2line", "addr2line",
"cfg-if 1.0.0", "cfg-if 1.0.0",
@ -489,9 +489,9 @@ dependencies = [
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.4.0" version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" checksum = "f07aa6688c702439a1be0307b6a94dffe1168569e45b9500c1372bc580740d59"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -1253,9 +1253,9 @@ dependencies = [
[[package]] [[package]]
name = "object" name = "object"
version = "0.22.0" version = "0.23.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4"
[[package]] [[package]]
name = "once_cell" name = "once_cell"
@ -1576,18 +1576,18 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
[[package]] [[package]]
name = "serde" name = "serde"
version = "1.0.119" version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bdd36f49e35b61d49efd8aa7fc068fd295961fd2286d0b2ee9a4c7a14e99cc3" checksum = "166b2349061381baf54a58e4b13c89369feb0ef2eaa57198899e2312aac30aab"
dependencies = [ dependencies = [
"serde_derive", "serde_derive",
] ]
[[package]] [[package]]
name = "serde_derive" name = "serde_derive"
version = "1.0.119" version = "1.0.120"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "552954ce79a059ddd5fd68c271592374bd15cab2274970380c000118aeffe1cd" checksum = "0ca2a8cb5805ce9e3b95435e3765b7b553cecc762d938d409434338386cb5775"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1746,9 +1746,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.58" version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc60a3d73ea6594cd712d830cc1f0390fd71542d8c8cd24e70cc54cdfd5e05d5" checksum = "07cb8b1b4ebf86a89ee88cbd201b022b94138c623644d035185c84d3f41b7e66"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -1783,11 +1783,11 @@ dependencies = [
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "1.1.0" version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bb9bc092d0d51e76b2b19d9d85534ffc9ec2db959a2523cdae0697e2972cd447" checksum = "301bdd13d23c49672926be451130892d274d3ba0b410c18e00daa7990ff38d99"
dependencies = [ dependencies = [
"lazy_static", "once_cell",
] ]
[[package]] [[package]]

View File

@ -8,15 +8,15 @@ authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"
[dependencies] [dependencies]
base64 = "0.13.0" base64 = "0.13"
actix-web = { version = "3.3.2", features = ["rustls"] } actix-web = { version = "3.3", features = ["rustls"] }
futures = "0.3" futures = "0.3"
askama = "0.10.5" askama = "0.10"
ureq = "2.0.1" ureq = "2.0"
serde = { version = "1.0.118", default_features = false, features = ["derive"] } serde = { version = "1.0", default_features = false, features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
async-recursion = "0.3.1" async-recursion = "0.3"
url = "2.2.0" url = "2.2"
regex = "1.4.2" regex = "1.4"
time = "0.2.23" time = "0.2"
cached = "0.23.0" cached = "0.23.0"

View File

@ -53,15 +53,16 @@ async fn main() -> std::io::Result<()> {
.wrap_fn(move |req, srv| { .wrap_fn(move |req, srv| {
let secure = req.connection_info().scheme() == "https"; let secure = req.connection_info().scheme() == "https";
let https_url = format!("https://{}{}", req.connection_info().host(), req.uri().to_string()); let https_url = format!("https://{}{}", req.connection_info().host(), req.uri().to_string());
srv.call(req).map(move |res: Result<ServiceResponse, _>| { srv.call(req).map(move |res: Result<ServiceResponse, _>|
if force_https && !secure { if force_https && !secure {
let redirect: ServiceResponse<actix_web::dev::Body> = Ok(ServiceResponse::new(
ServiceResponse::new(res.unwrap().request().clone(), HttpResponse::Found().header("Location", https_url).finish()); res.unwrap().request().to_owned(),
Ok(redirect) HttpResponse::Found().header("Location", https_url).finish(),
))
} else { } else {
res res
} }
}) )
}) })
// Append trailing slash and remove double slashes // Append trailing slash and remove double slashes
.wrap(middleware::NormalizePath::default()) .wrap(middleware::NormalizePath::default())
@ -106,9 +107,6 @@ async fn main() -> std::io::Result<()> {
.route("/{page}/", web::get().to(subreddit::wiki)), .route("/{page}/", web::get().to(subreddit::wiki)),
), ),
) )
// Universal services
.service(
web::scope("")
// Front page // Front page
.route("/", web::get().to(subreddit::page)) .route("/", web::get().to(subreddit::page))
.route("/{sort:best|hot|new|top|rising|controversial}/", web::get().to(subreddit::page)) .route("/{sort:best|hot|new|top|rising|controversial}/", web::get().to(subreddit::page))
@ -121,8 +119,7 @@ async fn main() -> std::io::Result<()> {
// Search all of Reddit // Search all of Reddit
.route("/search/", web::get().to(search::find)) .route("/search/", web::get().to(search::find))
// Short link for post // Short link for post
.route("/{id:.{5,6}}/", web::get().to(post::item)), .route("/{id:.{5,6}}/", web::get().to(post::item))
)
}) })
.bind(&address) .bind(&address)
.unwrap_or_else(|e| panic!("Cannot bind to the address {}: {}", address, e)) .unwrap_or_else(|e| panic!("Cannot bind to the address {}: {}", address, e))

View File

@ -1,5 +1,5 @@
// CRATES // CRATES
use crate::utils::{error, fetch_posts, param, prefs, request, val, Post, Preferences}; use crate::utils::{cookie, error, fetch_posts, param, prefs, request, val, Post, Preferences};
use actix_web::{HttpRequest, HttpResponse}; use actix_web::{HttpRequest, HttpResponse};
use askama::Template; use askama::Template;
@ -33,7 +33,8 @@ struct SearchTemplate {
// SERVICES // SERVICES
pub async fn find(req: HttpRequest) -> HttpResponse { pub async fn find(req: HttpRequest) -> HttpResponse {
let path = format!("{}.json?{}", req.path(), req.query_string()); let nsfw_results = if cookie(&req, "hide_nsfw") != "on" { "&include_over_18=on" } else { "" };
let path = format!("{}.json?{}{}", req.path(), req.query_string(), nsfw_results);
let sub = req.match_info().get("sub").unwrap_or("").to_string(); let sub = req.match_info().get("sub").unwrap_or("").to_string();
let sort = if param(&path, "sort").is_empty() { let sort = if param(&path, "sort").is_empty() {

View File

@ -1,6 +1,6 @@
// CRATES // CRATES
use crate::utils::{prefs, Preferences}; use crate::utils::{prefs, Preferences};
use actix_web::{cookie::Cookie, web::Form, HttpMessage, HttpRequest, HttpResponse}; use actix_web::{cookie::Cookie, web::Form, HttpRequest, HttpResponse};
use askama::Template; use askama::Template;
use time::{Duration, OffsetDateTime}; use time::{Duration, OffsetDateTime};
@ -30,7 +30,7 @@ pub async fn get(req: HttpRequest) -> HttpResponse {
} }
// Set cookies using response "Set-Cookie" header // Set cookies using response "Set-Cookie" header
pub async fn set(req: HttpRequest, form: Form<SettingsForm>) -> HttpResponse { pub async fn set(_req: HttpRequest, form: Form<SettingsForm>) -> HttpResponse {
let mut res = HttpResponse::Found(); let mut res = HttpResponse::Found();
let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "hide_nsfw"]; let names = vec!["theme", "front_page", "layout", "wide", "comment_sort", "hide_nsfw"];
@ -45,10 +45,7 @@ pub async fn set(req: HttpRequest, form: Form<SettingsForm>) -> HttpResponse {
.expires(OffsetDateTime::now_utc() + Duration::weeks(52)) .expires(OffsetDateTime::now_utc() + Duration::weeks(52))
.finish(), .finish(),
), ),
None => match HttpMessage::cookie(&req, name.to_owned()) { None => res.del_cookie(&Cookie::named(name.to_owned())),
Some(cookie) => res.del_cookie(&cookie),
None => &mut res,
},
}; };
} }

View File

@ -98,7 +98,7 @@ async fn subreddit(sub: &str) -> Result<Subreddit, String> {
let active: i64 = res["data"]["accounts_active"].as_u64().unwrap_or_default() as i64; let active: i64 = res["data"]["accounts_active"].as_u64().unwrap_or_default() as i64;
// Fetch subreddit icon either from the community_icon or icon_img value // Fetch subreddit icon either from the community_icon or icon_img value
let community_icon: &str = res["data"]["community_icon"].as_str().unwrap_or("").split('?').collect::<Vec<&str>>()[0]; let community_icon: &str = res["data"]["community_icon"].as_str().map_or("", |s| s.split('?').collect::<Vec<&str>>()[0]);
let icon = if community_icon.is_empty() { val(&res, "icon_img") } else { community_icon.to_string() }; let icon = if community_icon.is_empty() { val(&res, "icon_img") } else { community_icon.to_string() };
let sub = Subreddit { let sub = Subreddit {

View File

@ -287,7 +287,7 @@ pub fn time(created: f64) -> (String, String) {
// val() function used to parse JSON from Reddit APIs // val() function used to parse JSON from Reddit APIs
pub fn val(j: &Value, k: &str) -> String { pub fn val(j: &Value, k: &str) -> String {
String::from(j["data"][k].as_str().unwrap_or_default()) j["data"][k].as_str().unwrap_or_default().to_string()
} }
// Fetch posts of a user or subreddit and return a vector of posts and the "after" value // Fetch posts of a user or subreddit and return a vector of posts and the "after" value

View File

@ -1,2 +0,0 @@
User-agent: *
Allow: /

View File

@ -460,7 +460,7 @@ a.search_subreddit:hover {
} }
.post_score { .post_score {
padding-top: 20px; padding-top: 16px;
font-size: 13px; font-size: 13px;
font-weight: bold; font-weight: bold;
text-align: end; text-align: end;
@ -476,7 +476,7 @@ a.search_subreddit:hover {
} }
.post_header { .post_header {
margin: 20px 20px 5px 20px; margin: 15px 20px 5px 15px;
grid-area: post_header; grid-area: post_header;
} }
@ -487,7 +487,7 @@ a.search_subreddit:hover {
.post_title { .post_title {
font-size: 16px; font-size: 16px;
line-height: 1.5; line-height: 1.5;
margin: 5px 20px; margin: 5px 15px;
grid-area: post_title; grid-area: post_title;
} }
@ -548,7 +548,7 @@ a.search_subreddit:hover {
.post_body { .post_body {
opacity: 0.9; opacity: 0.9;
font-weight: normal; font-weight: normal;
margin: 5px 20px; margin: 5px 15px;
grid-area: post_body; grid-area: post_body;
} }
@ -558,7 +558,7 @@ a.search_subreddit:hover {
opacity: 0.5; opacity: 0.5;
font-size: 14px; font-size: 14px;
grid-area: post_footer; grid-area: post_footer;
margin: 5px 20px 20px 20px; margin: 5px 20px 15px 15px;
} }
.post_comments { .post_comments {
@ -675,6 +675,7 @@ a.search_subreddit:hover {
padding: 10px 0 10px 5px; padding: 10px 0 10px 5px;
flex-grow: 1; flex-grow: 1;
flex-shrink: 1; flex-shrink: 1;
min-width: 0;
} }
.comment_data > * { .comment_data > * {
@ -924,20 +925,13 @@ td, th {
} }
.post_score { .post_score {
background-color: unset; margin: 5px 0px 20px 15px;
margin: 5px 0px 20px 20px;
padding: 0; padding: 0;
} }
.compact .post_score { .compact .post_score { padding: 0; }
background-color: unset;
margin: 2.5px 0px 15px 15px;
padding: 0;
font-size: 14px;
}
.post_score::before { content: "↑" } .post_score::before { content: "↑" }
.post:hover > .post_score { background: unset; }
.post_header { font-size: 14px; } .post_header { font-size: 14px; }
.post_footer { margin-left: 15px; } .post_footer { margin-left: 15px; }