From 0656756d21899b99530a5eba15ed0cd6ef900c8f Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Mon, 29 Nov 2021 22:29:41 -0800 Subject: [PATCH] Fix #196 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/client.rs | 11 +++++++---- src/search.rs | 2 +- static/style.css | 1 + 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 75e7bf2..6c74703 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -603,7 +603,7 @@ checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" [[package]] name = "libreddit" -version = "0.20.1" +version = "0.20.2" dependencies = [ "askama", "async-recursion", diff --git a/Cargo.toml b/Cargo.toml index f083a61..1d4057e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.20.1" +version = "0.20.2" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/client.rs b/src/client.rs index 8760eff..32a97e8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,7 +2,7 @@ use cached::proc_macro::cached; use futures_lite::{future::Boxed, FutureExt}; use hyper::{body::Buf, client, Body, Request, Response, Uri}; use serde_json::Value; -use std::{result::Result, str::FromStr}; +use std::result::Result; use crate::server::RequestExt; @@ -20,7 +20,7 @@ pub async fn proxy(req: Request, format: &str) -> Result, S async fn stream(url: &str, req: &Request) -> Result, String> { // First parameter is target URL (mandatory). - let url = Uri::from_str(url).map_err(|_| "Couldn't parse URL".to_string())?; + let uri = url.parse::().map_err(|_| "Couldn't parse URL".to_string())?; // Prepare the HTTPS connector. let https = hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().https_only().enable_http1().build(); @@ -28,7 +28,7 @@ async fn stream(url: &str, req: &Request) -> Result, String // Build the hyper client from the HTTPS connector. let client: client::Client<_, hyper::Body> = client::Client::builder().build(https); - let mut builder = Request::get(url); + let mut builder = Request::get(uri); // Copy useful headers from original request for &key in &["Range", "If-Modified-Since", "Cache-Control"] { @@ -89,7 +89,10 @@ fn request(url: String, quarantine: bool) -> Boxed, String response .headers() .get("Location") - .map(|val| val.to_str().unwrap_or_default()) + .map(|val| { + let new_url = val.to_str().unwrap_or_default(); + format!("{}{}raw_json=1", new_url, if new_url.contains("?") { "&" } else { "?" }) + }) .unwrap_or_default() .to_string(), quarantine, diff --git a/src/search.rs b/src/search.rs index 0eef077..fc91e58 100644 --- a/src/search.rs +++ b/src/search.rs @@ -47,7 +47,7 @@ struct SearchTemplate { // SERVICES pub async fn find(req: Request) -> Result, String> { let nsfw_results = if setting(&req, "show_nsfw") == "on" { "&include_over_18=on" } else { "" }; - let path = format!("{}.json?{}{}", req.uri().path(), req.uri().query().unwrap_or_default(), nsfw_results); + let path = format!("{}.json?{}{}&raw_json=1", req.uri().path(), req.uri().query().unwrap_or_default(), nsfw_results); let query = param(&path, "q").unwrap_or_default(); if query.is_empty() { diff --git a/static/style.css b/static/style.css index 3b6d20b..682cf76 100644 --- a/static/style.css +++ b/static/style.css @@ -465,6 +465,7 @@ aside { #wiki { background: var(--foreground); padding: 35px; + overflow-wrap: anywhere; } #top {