From 364c29c4d590ce0a2dfdab5f5b9d60c5607571f0 Mon Sep 17 00:00:00 2001 From: spikecodes <19519553+spikecodes@users.noreply.github.com> Date: Sun, 28 Nov 2021 14:47:50 -0800 Subject: [PATCH] Use resized icons for awards. Fixes #346 --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- README.md | 22 +++++++++++----------- src/main.rs | 4 ++++ src/utils.rs | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 73e65ef..75e7bf2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -603,7 +603,7 @@ checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" [[package]] name = "libreddit" -version = "0.19.1" +version = "0.20.1" dependencies = [ "askama", "async-recursion", @@ -888,9 +888,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568" [[package]] name = "schannel" diff --git a/Cargo.toml b/Cargo.toml index fd49f6e..f083a61 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.0" +version = "0.20.1" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/README.md b/README.md index c6862b0..92e687a 100644 --- a/README.md +++ b/README.md @@ -224,17 +224,17 @@ libreddit Assign a default value for each setting by passing environment variables to Libreddit in the format `LIBREDDIT_DEFAULT_{X}`. Replace `{X}` with the setting name (see list below) in capital letters. -| Name | Possible values | Default value | -|-------------------------|------------------------------------------------------------------------------------------|---------------| -| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold"]` | `system` | -| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` | -| `LAYOUT` | `["card", "clean", "compact"]` | `card` | -| `WIDE` | `["on", "off"]` | `off` | -| `COMMENT_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` | -| `POST_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` | -| `SHOW_NSFW` | `["on", "off"]` | `off` | -| `USE_HLS` | `["on", "off"]` | `off` | -| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` | +| Name | Possible values | Default value | +|-------------------------|-----------------------------------------------------------------------------------------------------|---------------| +| `THEME` | `["system", "light", "dark", "black", "dracula", "nord", "laserwave", "violet", "gold", "rosebox"]` | `system` | +| `FRONT_PAGE` | `["default", "popular", "all"]` | `default` | +| `LAYOUT` | `["card", "clean", "compact"]` | `card` | +| `WIDE` | `["on", "off"]` | `off` | +| `COMMENT_SORT` | `["hot", "new", "top", "rising", "controversial"]` | `hot` | +| `POST_SORT` | `["confidence", "top", "new", "controversial", "old"]` | `confidence` | +| `SHOW_NSFW` | `["on", "off"]` | `off` | +| `USE_HLS` | `["on", "off"]` | `off` | +| `HIDE_HLS_NOTIFICATION` | `["on", "off"]` | `off` | ### Examples diff --git a/src/main.rs b/src/main.rs index fa772be..7cf5344 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,6 +70,7 @@ async fn font() -> Result, String> { Response::builder() .status(200) .header("content-type", "font/woff2") + .header("Cache-Control", "public, max-age=1209600, s-maxage=86400") .body(include_bytes!("../static/Inter.var.woff2").as_ref().into()) .unwrap_or_default(), ) @@ -183,6 +184,9 @@ async fn main() { app.at("/img/*path").get(|r| proxy(r, "https://i.redd.it/{path}").boxed()); app.at("/thumb/:point/:id").get(|r| proxy(r, "https://{point}.thumbs.redditmedia.com/{id}").boxed()); app.at("/emoji/:id/:name").get(|r| proxy(r, "https://emoji.redditmedia.com/{id}/{name}").boxed()); + app + .at("/preview/:loc/award_images/:fullname/:id") + .get(|r| proxy(r, "https://{loc}view.redd.it/award_images/{fullname}/{id}").boxed()); app.at("/preview/:loc/:id").get(|r| proxy(r, "https://{loc}view.redd.it/{id}").boxed()); app.at("/style/*path").get(|r| proxy(r, "https://styles.redditmedia.com/{path}").boxed()); app.at("/static/*path").get(|r| proxy(r, "https://www.redditstatic.com/{path}").boxed()); diff --git a/src/utils.rs b/src/utils.rs index dad2e99..58ae870 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -384,7 +384,7 @@ impl Awards { pub fn parse(items: &Value) -> Self { let parsed = items.as_array().unwrap_or(&Vec::new()).iter().fold(Vec::new(), |mut awards, item| { let name = item["name"].as_str().unwrap_or_default().to_string(); - let icon_url = format_url(&item["icon_url"].as_str().unwrap_or_default().to_string()); + let icon_url = format_url(item["resized_icons"][0]["url"].as_str().unwrap_or_default()); let description = item["description"].as_str().unwrap_or_default().to_string(); let count: i64 = i64::from_str(&item["count"].to_string()).unwrap_or(1);