From 138172b365d445e814ba46513a51b90040430556 Mon Sep 17 00:00:00 2001 From: ayaka Date: Mon, 13 Jan 2025 14:18:05 +1300 Subject: [PATCH 1/2] unnecessary log generation --- src/client.rs | 4 ++-- src/oauth.rs | 4 ++-- src/subreddit.rs | 3 +++ src/user.rs | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/client.rs b/src/client.rs index 248fc88..ff3b580 100644 --- a/src/client.rs +++ b/src/client.rs @@ -7,7 +7,7 @@ use hyper::header::HeaderValue; use hyper::{body, body::Buf, header, Body, Client, Method, Request, Response, Uri}; use hyper_rustls::HttpsConnector; use libflate::gzip; -use log::{error, trace, warn}; +use log::{error, debug, warn}; use once_cell::sync::Lazy; use percent_encoding::{percent_encode, CONTROLS}; use serde_json::Value; @@ -396,7 +396,7 @@ pub async fn json(path: String, quarantine: bool) -> Result { response.headers().get("x-ratelimit-reset").and_then(|val| val.to_str().ok().map(|s| s.to_string())), response.headers().get("x-ratelimit-used").and_then(|val| val.to_str().ok().map(|s| s.to_string())), ) { - trace!( + debug!( "Ratelimit remaining: Header says {remaining}, we have {current_rate_limit}. Resets in {reset}. Rollover: {}. Ratelimit used: {used}", if is_rolling_over { "yes" } else { "no" }, ); diff --git a/src/oauth.rs b/src/oauth.rs index 80bf318..c68e50a 100644 --- a/src/oauth.rs +++ b/src/oauth.rs @@ -6,7 +6,7 @@ use crate::{ }; use base64::{engine::general_purpose, Engine as _}; use hyper::{client, Body, Method, Request}; -use log::{error, info, trace}; +use log::{error, info, debug, trace}; use serde_json::json; use tokio::time::{error::Elapsed, timeout}; @@ -160,7 +160,7 @@ pub async fn force_refresh_token() { return; } - trace!("Rolling over refresh token. Current rate limit: {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)); + debug!("Rolling over refresh token. Current rate limit: {}", OAUTH_RATELIMIT_REMAINING.load(Ordering::SeqCst)); let new_client = Oauth::new().await; OAUTH_CLIENT.swap(new_client.into()); OAUTH_RATELIMIT_REMAINING.store(99, Ordering::SeqCst); diff --git a/src/subreddit.rs b/src/subreddit.rs index 5f964ef..1ae90d3 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -13,6 +13,7 @@ use rinja::Template; use once_cell::sync::Lazy; use regex::Regex; use time::{Duration, OffsetDateTime}; +use log::trace; // STRUCTS #[derive(Template)] @@ -461,6 +462,8 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { // Send a request to the url let res = json(path, quarantined).await?; + trace!("Subreddit info from r/{} : {}",sub,res["data"]); + // Metadata regarding the subreddit let members: i64 = res["data"]["subscribers"].as_u64().unwrap_or_default() as i64; let active: i64 = res["data"]["accounts_active"].as_u64().unwrap_or_default() as i64; diff --git a/src/user.rs b/src/user.rs index 50a4daa..5e8bfd7 100644 --- a/src/user.rs +++ b/src/user.rs @@ -8,6 +8,7 @@ use crate::{config, utils}; use hyper::{Body, Request, Response}; use rinja::Template; use time::{macros::format_description, OffsetDateTime}; +use log::trace; // STRUCTS #[derive(Template)] @@ -111,6 +112,7 @@ async fn user(name: &str) -> Result { // Send a request to the url json(path, false).await.map(|res| { + trace!("User info from r/{} : {}",name,res["data"]); // Grab creation date as unix timestamp let created_unix = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64; let created = OffsetDateTime::from_unix_timestamp(created_unix).unwrap_or(OffsetDateTime::UNIX_EPOCH); From 49afd83ad3d99c10f33a7fada861dcd55e09798a Mon Sep 17 00:00:00 2001 From: ayaka Date: Mon, 13 Jan 2025 14:41:49 +1300 Subject: [PATCH 2/2] subreddit-created-date --- src/subreddit.rs | 8 +++++++- src/utils.rs | 1 + static/style.css | 11 +++++------ templates/subreddit.html | 3 +++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/subreddit.rs b/src/subreddit.rs index 1ae90d3..f12bbb1 100644 --- a/src/subreddit.rs +++ b/src/subreddit.rs @@ -12,7 +12,8 @@ use rinja::Template; use once_cell::sync::Lazy; use regex::Regex; -use time::{Duration, OffsetDateTime}; +use time::{Duration, OffsetDateTime,macros::format_description}; + use log::trace; // STRUCTS @@ -467,6 +468,10 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { // Metadata regarding the subreddit let members: i64 = res["data"]["subscribers"].as_u64().unwrap_or_default() as i64; let active: i64 = res["data"]["accounts_active"].as_u64().unwrap_or_default() as i64; + + // Grab creation date as unix timestamp + let created_unix = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64; + let created = OffsetDateTime::from_unix_timestamp(created_unix).unwrap_or(OffsetDateTime::UNIX_EPOCH); // Fetch subreddit icon either from the community_icon or icon_img value let community_icon: &str = res["data"]["community_icon"].as_str().unwrap_or_default(); @@ -481,6 +486,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result { icon: format_url(&icon), members: format_num(members), active: format_num(active), + created: created.format(format_description!("[month repr:short] [day] '[year repr:last_two]")).unwrap_or_default(), wiki: res["data"]["wiki_enabled"].as_bool().unwrap_or_default(), nsfw: res["data"]["over18"].as_bool().unwrap_or_default(), }) diff --git a/src/utils.rs b/src/utils.rs index b8105c3..dd8014e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -587,6 +587,7 @@ pub struct Subreddit { pub icon: String, pub members: (String, String), pub active: (String, String), + pub created: String, pub wiki: bool, pub nsfw: bool, } diff --git a/static/style.css b/static/style.css index 9567a81..b37d7e2 100644 --- a/static/style.css +++ b/static/style.css @@ -531,11 +531,14 @@ aside { grid-template-columns: auto 4fr 1fr; } -#user_details, -#sub_details { +#user_details { display: grid; grid-template-columns: repeat(2, 1fr); } +#sub_details { + display: grid; + grid-template-columns: repeat(3, 1fr); +} @media screen and (max-width: 279px) { #sub_actions { display: unset; } } @@ -547,13 +550,9 @@ aside { /* Subscriptions */ -#sub_subscription, #user_subscription, -#sub_filter, #user_filter, -#sub_quicklist, #user_quicklist, -#sub_rss, #user_rss { margin-top: 20px; } diff --git a/templates/subreddit.html b/templates/subreddit.html index 5584863..8856fcd 100644 --- a/templates/subreddit.html +++ b/templates/subreddit.html @@ -120,9 +120,12 @@
+
{{ sub.members.0 }}
{{ sub.active.0 }}
+
{{ sub.created }}
+
{% if prefs.subscriptions.contains(sub.name) %}