Optimize Sequencing

This commit is contained in:
spikecodes 2021-01-02 11:09:26 -08:00
parent 4ec529cdb8
commit f49bff9853
6 changed files with 33 additions and 33 deletions

38
Cargo.lock generated
View File

@ -93,7 +93,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655" checksum = "b4ca8ce00b267af8ccebbd647de0d61e0674b6e61185cc7a592ff88772bed655"
dependencies = [ dependencies = [
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -267,7 +267,7 @@ checksum = "ad26f77093333e0e7c6ffe54ebe3582d908a104e448723eec6d43d08b07143fb"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -346,7 +346,7 @@ checksum = "e5444eec77a9ec2bfe4524139e09195862e981400c4358d3b760cae634e4c4ee"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -357,7 +357,7 @@ checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -562,7 +562,7 @@ checksum = "41cb0e6161ad61ed084a36ba71fbba9e3ac5aee3606fb607fe08da6acbcf3d8c"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -604,7 +604,7 @@ dependencies = [
"heck", "heck",
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -696,7 +696,7 @@ dependencies = [
"proc-macro-hack", "proc-macro-hack",
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1006,7 +1006,7 @@ checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]] [[package]]
name = "libreddit" name = "libreddit"
version = "0.2.4" version = "0.2.5"
dependencies = [ dependencies = [
"actix-web", "actix-web",
"askama", "askama",
@ -1264,7 +1264,7 @@ checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1275,7 +1275,7 @@ checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1564,7 +1564,7 @@ checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1680,7 +1680,7 @@ dependencies = [
"quote 1.0.8", "quote 1.0.8",
"serde", "serde",
"serde_derive", "serde_derive",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1696,7 +1696,7 @@ dependencies = [
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"sha1", "sha1",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1718,9 +1718,9 @@ dependencies = [
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.56" version = "1.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9802ddde94170d186eeee5005b798d9c159fa970403f1be19976d0cfb939b72" checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
@ -1744,7 +1744,7 @@ checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -1811,7 +1811,7 @@ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"standback", "standback",
"syn 1.0.56", "syn 1.0.57",
] ]
[[package]] [[package]]
@ -2094,7 +2094,7 @@ dependencies = [
"log", "log",
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]
@ -2128,7 +2128,7 @@ checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549"
dependencies = [ dependencies = [
"proc-macro2 1.0.24", "proc-macro2 1.0.24",
"quote 1.0.8", "quote 1.0.8",
"syn 1.0.56", "syn 1.0.57",
"wasm-bindgen-backend", "wasm-bindgen-backend",
"wasm-bindgen-shared", "wasm-bindgen-shared",
] ]

View File

@ -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.2.4" version = "0.2.5"
authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"]
edition = "2018" edition = "2018"

View File

@ -47,13 +47,13 @@ async fn media(data: &serde_json::Value) -> (String, String) {
let post_type: &str; let post_type: &str;
let url = if !data["preview"]["reddit_video_preview"]["fallback_url"].is_null() { let url = if !data["preview"]["reddit_video_preview"]["fallback_url"].is_null() {
post_type = "video"; post_type = "video";
format_url(data["preview"]["reddit_video_preview"]["fallback_url"].as_str().unwrap().to_string()).await format_url(data["preview"]["reddit_video_preview"]["fallback_url"].as_str().unwrap().to_string())
} else if !data["secure_media"]["reddit_video"]["fallback_url"].is_null() { } else if !data["secure_media"]["reddit_video"]["fallback_url"].is_null() {
post_type = "video"; post_type = "video";
format_url(data["secure_media"]["reddit_video"]["fallback_url"].as_str().unwrap().to_string()).await format_url(data["secure_media"]["reddit_video"]["fallback_url"].as_str().unwrap().to_string())
} else if data["post_hint"].as_str().unwrap_or("") == "image" { } else if data["post_hint"].as_str().unwrap_or("") == "image" {
post_type = "image"; post_type = "image";
format_url(data["preview"]["images"][0]["source"]["url"].as_str().unwrap().to_string()).await format_url(data["preview"]["images"][0]["source"]["url"].as_str().unwrap().to_string())
} else { } else {
post_type = "link"; post_type = "link";
data["url"].as_str().unwrap().to_string() data["url"].as_str().unwrap().to_string()
@ -79,7 +79,7 @@ async fn parse_post(json: &serde_json::Value) -> Result<Post, &'static str> {
let post = Post { let post = Post {
title: val(post_data, "title"), title: val(post_data, "title"),
community: val(post_data, "subreddit"), community: val(post_data, "subreddit"),
body: rewrite_url(&val(post_data, "selftext_html")).await, body: rewrite_url(&val(post_data, "selftext_html")),
author: val(post_data, "author"), author: val(post_data, "author"),
author_flair: Flair( author_flair: Flair(
val(post_data, "author_flair_text"), val(post_data, "author_flair_text"),
@ -125,7 +125,7 @@ async fn parse_comments(json: &serde_json::Value) -> Result<Vec<Comment>, &'stat
} }
let score = comment["data"]["score"].as_i64().unwrap_or(0); let score = comment["data"]["score"].as_i64().unwrap_or(0);
let body = rewrite_url(&val(comment, "body_html")).await; let body = rewrite_url(&val(comment, "body_html"));
let replies: Vec<Comment> = if comment["data"]["replies"].is_object() { let replies: Vec<Comment> = if comment["data"]["replies"].is_object() {
parse_comments(&comment["data"]["replies"]).await.unwrap_or_default() parse_comments(&comment["data"]["replies"]).await.unwrap_or_default()

View File

@ -58,7 +58,7 @@ pub async fn wiki(req: HttpRequest) -> Result<HttpResponse> {
Ok(res) => { Ok(res) => {
let s = WikiTemplate { let s = WikiTemplate {
sub: sub.to_string(), sub: sub.to_string(),
wiki: rewrite_url(res["data"]["content_html"].as_str().unwrap()).await, wiki: rewrite_url(res["data"]["content_html"].as_str().unwrap()),
page: page.to_string(), page: page.to_string(),
} }
.render() .render()
@ -90,8 +90,8 @@ async fn subreddit(sub: &str) -> Result<Subreddit, &'static str> {
name: val(&res, "display_name"), name: val(&res, "display_name"),
title: val(&res, "title"), title: val(&res, "title"),
description: val(&res, "public_description"), description: val(&res, "public_description"),
info: rewrite_url(&val(&res, "description_html").replace("\\", "")).await, info: rewrite_url(&val(&res, "description_html").replace("\\", "")),
icon: format_url(icon).await, icon: format_url(icon),
members: format_num(members), members: format_num(members),
active: format_num(active), active: format_num(active),
wiki: res["data"]["wiki_enabled"].as_bool().unwrap_or_default(), wiki: res["data"]["wiki_enabled"].as_bool().unwrap_or_default(),

View File

@ -67,7 +67,7 @@ async fn user(name: &str) -> Result<User, &'static str> {
Ok(User { Ok(User {
name: name.to_string(), name: name.to_string(),
title: nested_val(&res, "subreddit", "title"), title: nested_val(&res, "subreddit", "title"),
icon: format_url(nested_val(&res, "subreddit", "icon_img")).await, icon: format_url(nested_val(&res, "subreddit", "icon_img")),
karma: res["data"]["total_karma"].as_i64().unwrap(), karma: res["data"]["total_karma"].as_i64().unwrap(),
created: Utc.timestamp(created, 0).format("%b %e, %Y").to_string(), created: Utc.timestamp(created, 0).format("%b %e, %Y").to_string(),
banner: nested_val(&res, "subreddit", "banner_img"), banner: nested_val(&res, "subreddit", "banner_img"),

View File

@ -103,7 +103,7 @@ pub fn param(path: &str, value: &str) -> String {
} }
// Direct urls to proxy if proxy is enabled // Direct urls to proxy if proxy is enabled
pub async fn format_url(url: String) -> String { pub fn format_url(url: String) -> String {
if url.is_empty() { if url.is_empty() {
return String::new(); return String::new();
}; };
@ -116,7 +116,7 @@ pub async fn format_url(url: String) -> String {
} }
// Rewrite Reddit links to Libreddit in body of text // Rewrite Reddit links to Libreddit in body of text
pub async fn rewrite_url(text: &str) -> String { pub fn rewrite_url(text: &str) -> String {
let re = Regex::new(r#"href="(https://|http://|)(www.|)(reddit).(com)/"#).unwrap(); let re = Regex::new(r#"href="(https://|http://|)(www.|)(reddit).(com)/"#).unwrap();
re.replace_all(text, r#"href="/"#).to_string() re.replace_all(text, r#"href="/"#).to_string()
} }
@ -171,7 +171,7 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
for post in post_list { for post in post_list {
let img = if val(post, "thumbnail").starts_with("https:/") { let img = if val(post, "thumbnail").starts_with("https:/") {
format_url(val(post, "thumbnail")).await format_url(val(post, "thumbnail"))
} else { } else {
String::new() String::new()
}; };
@ -182,7 +182,7 @@ pub async fn fetch_posts(path: &str, fallback_title: String) -> Result<(Vec<Post
posts.push(Post { posts.push(Post {
title: if title.is_empty() { fallback_title.to_owned() } else { title }, title: if title.is_empty() { fallback_title.to_owned() } else { title },
community: val(post, "subreddit"), community: val(post, "subreddit"),
body: rewrite_url(&val(post, "body_html")).await, body: rewrite_url(&val(post, "body_html")),
author: val(post, "author"), author: val(post, "author"),
author_flair: Flair( author_flair: Flair(
val(post, "author_flair_text"), val(post, "author_flair_text"),