Handle three unwraps
This commit is contained in:
parent
31bf8c802e
commit
4f09333cd7
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -609,7 +609,7 @@ checksum = "18794a8ad5b29321f790b55d93dfba91e125cb1a9edbd4f8e3150acc771c1a5e"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libreddit"
|
name = "libreddit"
|
||||||
version = "0.13.0"
|
version = "0.13.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
|
@ -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.13.0"
|
version = "0.13.1"
|
||||||
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
|
@ -114,16 +114,19 @@ pub async fn subscriptions(req: Request<Body>) -> Result<Response<Body>, String>
|
|||||||
let mut sub_list = Preferences::new(req).subscriptions;
|
let mut sub_list = Preferences::new(req).subscriptions;
|
||||||
|
|
||||||
// Retrieve list of posts for these subreddits to extract display names
|
// Retrieve list of posts for these subreddits to extract display names
|
||||||
let display = json(format!("/r/{}/hot.json?raw_json=1", sub)).await?;
|
let posts = json(format!("/r/{}/hot.json?raw_json=1", sub)).await?;
|
||||||
let display_lookup: Vec<(String, &str)> = display["data"]["children"]
|
let display_lookup: Vec<(String, &str)> = posts["data"]["children"]
|
||||||
.as_array()
|
.as_array()
|
||||||
.unwrap()
|
.map(|list| {
|
||||||
|
list
|
||||||
.iter()
|
.iter()
|
||||||
.map(|post| {
|
.map(|post| {
|
||||||
let display_name = post["data"]["subreddit"].as_str().unwrap();
|
let display_name = post["data"]["subreddit"].as_str().unwrap_or_default();
|
||||||
(display_name.to_lowercase(), display_name)
|
(display_name.to_lowercase(), display_name)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect::<Vec<_>>()
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
// Find each subreddit name (separated by '+') in sub parameter
|
// Find each subreddit name (separated by '+') in sub parameter
|
||||||
for part in sub.split('+') {
|
for part in sub.split('+') {
|
||||||
@ -275,7 +278,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();
|
let community_icon: &str = res["data"]["community_icon"].as_str().unwrap_or_default();
|
||||||
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 {
|
||||||
|
@ -528,7 +528,7 @@ pub fn rewrite_urls(input_text: &str) -> String {
|
|||||||
match Regex::new(r"https://external-preview\.redd\.it(.*)[^?]") {
|
match Regex::new(r"https://external-preview\.redd\.it(.*)[^?]") {
|
||||||
Ok(re) => {
|
Ok(re) => {
|
||||||
if re.is_match(&text1) {
|
if re.is_match(&text1) {
|
||||||
re.replace_all(&text1, format_url(re.find(&text1).unwrap().as_str())).to_string()
|
re.replace_all(&text1, format_url(re.find(&text1).map(|x| x.as_str()).unwrap_or_default())).to_string()
|
||||||
} else {
|
} else {
|
||||||
text1
|
text1
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user