Fix clippy errors
This commit is contained in:
parent
14f9ac4ca7
commit
66ac72beab
7
.github/workflows/rust.yml
vendored
7
.github/workflows/rust.yml
vendored
@ -21,6 +21,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: cargo build --release
|
run: cargo build --release
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v2.2.1
|
||||||
|
name: Upload a Build Artifact
|
||||||
|
with:
|
||||||
|
name: libreddit
|
||||||
|
path: target/release/libreddit
|
||||||
|
|
||||||
- name: Versions
|
- name: Versions
|
||||||
id: version
|
id: version
|
||||||
@ -35,7 +41,6 @@ jobs:
|
|||||||
name: ${{ steps.version.outputs.version }} - NAME
|
name: ${{ steps.version.outputs.version }} - NAME
|
||||||
draft: true
|
draft: true
|
||||||
files: target/release/libreddit
|
files: target/release/libreddit
|
||||||
fail_on_unmatched_files: true
|
|
||||||
body: |
|
body: |
|
||||||
- CHANGES
|
- CHANGES
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ name = "libreddit"
|
|||||||
description = " Alternative private front-end to Reddit"
|
description = " Alternative private front-end to Reddit"
|
||||||
license = "AGPL-3.0"
|
license = "AGPL-3.0"
|
||||||
repository = "https://github.com/spikecodes/libreddit"
|
repository = "https://github.com/spikecodes/libreddit"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ regex = "1.4.5"
|
|||||||
serde = { version = "1.0.125", features = ["derive"] }
|
serde = { version = "1.0.125", features = ["derive"] }
|
||||||
cookie = "0.15.0"
|
cookie = "0.15.0"
|
||||||
futures-lite = "1.11.3"
|
futures-lite = "1.11.3"
|
||||||
hyper = { version = "0.14.4", features = ["full"] }
|
hyper = { version = "0.14.5", features = ["full"] }
|
||||||
hyper-rustls = "0.22.1"
|
hyper-rustls = "0.22.1"
|
||||||
route-recognizer = "0.3.0"
|
route-recognizer = "0.3.0"
|
||||||
serde_json = "1.0.64"
|
serde_json = "1.0.64"
|
||||||
|
14
README.md
14
README.md
@ -21,20 +21,6 @@
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Jump to...
|
|
||||||
- [About](#about)
|
|
||||||
- [Teddit Comparison](#how-does-it-compare-to-teddit)
|
|
||||||
- [Comparison](#comparison)
|
|
||||||
- [Installation](#installation)
|
|
||||||
- [Cargo](#1-cargo)
|
|
||||||
- [Docker](#2-docker)
|
|
||||||
- [AUR](#3-aur)
|
|
||||||
- [GitHub Releases](#4-github-releases)
|
|
||||||
- [Replit](#5-replit)
|
|
||||||
- [Deployment](#deployment)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Instances
|
# Instances
|
||||||
|
|
||||||
Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new) to have your [selfhosted instance](#deployment) listed here!
|
Feel free to [open an issue](https://github.com/spikecodes/libreddit/issues/new) to have your [selfhosted instance](#deployment) listed here!
|
||||||
|
@ -134,6 +134,6 @@ pub async fn json(path: String) -> Result<Value, String> {
|
|||||||
Err(e) => err("Failed receiving body from Reddit", e.to_string()),
|
Err(e) => err("Failed receiving body from Reddit", e.to_string()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => err("Couldn't send request to Reddit", e.to_string()),
|
Err(e) => err("Couldn't send request to Reddit", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,8 @@
|
|||||||
clippy::match_wildcard_for_single_variants,
|
clippy::match_wildcard_for_single_variants,
|
||||||
clippy::cast_possible_truncation,
|
clippy::cast_possible_truncation,
|
||||||
clippy::similar_names,
|
clippy::similar_names,
|
||||||
clippy::cast_possible_wrap
|
clippy::cast_possible_wrap,
|
||||||
|
clippy::find_map
|
||||||
)]
|
)]
|
||||||
|
|
||||||
// Reference local files
|
// Reference local files
|
||||||
|
@ -61,7 +61,7 @@ impl RequestExt for Request<Body> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn param(&self, name: &str) -> Option<String> {
|
fn param(&self, name: &str) -> Option<String> {
|
||||||
self.params().find(name).map(|s| s.to_owned())
|
self.params().find(name).map(std::borrow::ToOwned::to_owned)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_params(&mut self, params: Params) -> Option<Params> {
|
fn set_params(&mut self, params: Params) -> Option<Params> {
|
||||||
@ -72,14 +72,14 @@ impl RequestExt for Request<Body> {
|
|||||||
let mut cookies = Vec::new();
|
let mut cookies = Vec::new();
|
||||||
if let Some(header) = self.headers().get("Cookie") {
|
if let Some(header) = self.headers().get("Cookie") {
|
||||||
for cookie in header.to_str().unwrap_or_default().split("; ") {
|
for cookie in header.to_str().unwrap_or_default().split("; ") {
|
||||||
cookies.push(Cookie::parse(cookie).unwrap_or(Cookie::named("")));
|
cookies.push(Cookie::parse(cookie).unwrap_or_else(|_| Cookie::named("")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cookies
|
cookies
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cookie(&self, name: &str) -> Option<Cookie> {
|
fn cookie(&self, name: &str) -> Option<Cookie> {
|
||||||
self.cookies().iter().find(|c| c.name() == name).map(|c| c.to_owned())
|
self.cookies().iter().find(|c| c.name() == name).map(std::borrow::ToOwned::to_owned)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,18 +32,21 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
// Build Reddit API path
|
// Build Reddit API path
|
||||||
let subscribed = cookie(&req, "subscriptions");
|
let subscribed = cookie(&req, "subscriptions");
|
||||||
let front_page = cookie(&req, "front_page");
|
let front_page = cookie(&req, "front_page");
|
||||||
let post_sort = req.cookie("post_sort").map(|c| c.value().to_string()).unwrap_or("hot".to_string());
|
let post_sort = req.cookie("post_sort").map_or_else(|| "hot".to_string(), |c| c.value().to_string());
|
||||||
let sort = req.param("sort").unwrap_or(req.param("id").unwrap_or(post_sort));
|
let sort = req.param("sort").unwrap_or_else(|| req.param("id").unwrap_or(post_sort));
|
||||||
|
|
||||||
let sub = req.param("sub").map(String::from).unwrap_or(if front_page == "default" || front_page.is_empty() {
|
let sub = req.param("sub").map_or(
|
||||||
if subscribed.is_empty() {
|
if front_page == "default" || front_page.is_empty() {
|
||||||
"popular".to_string()
|
if subscribed.is_empty() {
|
||||||
|
"popular".to_string()
|
||||||
|
} else {
|
||||||
|
subscribed.to_owned()
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
subscribed.to_owned()
|
front_page.to_owned()
|
||||||
}
|
},
|
||||||
} else {
|
String::from,
|
||||||
front_page.to_owned()
|
);
|
||||||
});
|
|
||||||
|
|
||||||
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub, sort, req.uri().query().unwrap_or_default());
|
let path = format!("/r/{}/{}.json?{}&raw_json=1", sub, sort, req.uri().query().unwrap_or_default());
|
||||||
|
|
||||||
@ -89,7 +92,7 @@ pub async fn community(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
|
|
||||||
// Sub or unsub by setting subscription cookie using response "Set-Cookie" header
|
// Sub or unsub by setting subscription cookie using response "Set-Cookie" header
|
||||||
pub async fn subscriptions(req: Request<Body>) -> Result<Response<Body>, String> {
|
pub async fn subscriptions(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
let sub = req.param("sub").unwrap_or_default().to_string();
|
let sub = req.param("sub").unwrap_or_default();
|
||||||
let query = req.uri().query().unwrap_or_default().to_string();
|
let query = req.uri().query().unwrap_or_default().to_string();
|
||||||
let action: Vec<String> = req.uri().path().split('/').map(String::from).collect();
|
let action: Vec<String> = req.uri().path().split('/').map(String::from).collect();
|
||||||
|
|
||||||
@ -137,8 +140,8 @@ pub async fn subscriptions(req: Request<Body>) -> Result<Response<Body>, String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
|
pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
let sub = req.param("sub").unwrap_or("reddit.com".to_string());
|
let sub = req.param("sub").unwrap_or_else(|| "reddit.com".to_string());
|
||||||
let page = req.param("page").unwrap_or("index".to_string());
|
let page = req.param("page").unwrap_or_else(|| "index".to_string());
|
||||||
let path: String = format!("/r/{}/wiki/{}.json?raw_json=1", sub, page);
|
let path: String = format!("/r/{}/wiki/{}.json?raw_json=1", sub, page);
|
||||||
|
|
||||||
match json(path).await {
|
match json(path).await {
|
||||||
@ -153,7 +156,7 @@ pub async fn wiki(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
|
pub async fn sidebar(req: Request<Body>) -> Result<Response<Body>, String> {
|
||||||
let sub = req.param("sub").unwrap_or("reddit.com".to_string());
|
let sub = req.param("sub").unwrap_or_else(|| "reddit.com".to_string());
|
||||||
|
|
||||||
// Build the Reddit JSON API url
|
// Build the Reddit JSON API url
|
||||||
let path: String = format!("/r/{}/about.json?raw_json=1", sub);
|
let path: String = format!("/r/{}/about.json?raw_json=1", sub);
|
||||||
|
@ -23,7 +23,7 @@ pub async fn profile(req: Request<Body>) -> Result<Response<Body>, String> {
|
|||||||
// Build the Reddit JSON API path
|
// Build the Reddit JSON API path
|
||||||
let path = format!(
|
let path = format!(
|
||||||
"/user/{}.json?{}&raw_json=1",
|
"/user/{}.json?{}&raw_json=1",
|
||||||
req.param("name").unwrap_or("reddit".to_string()),
|
req.param("name").unwrap_or_else(|| "reddit".to_string()),
|
||||||
req.uri().query().unwrap_or_default()
|
req.uri().query().unwrap_or_default()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user