Merge branch 'main' into subreddit-banners

This commit is contained in:
Ayaka 2025-01-13 14:48:11 +13:00
commit 0dcda02d27
7 changed files with 25 additions and 11 deletions

View File

@ -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<Value, String> {
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" },
);

View File

@ -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);

View File

@ -12,7 +12,9 @@ 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
#[derive(Template)]
@ -461,9 +463,15 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
// 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;
// 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();
@ -483,6 +491,7 @@ async fn subreddit(sub: &str, quarantined: bool) -> Result<Subreddit, String> {
banner: format_url(&banner),
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(),
})

View File

@ -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<User, String> {
// 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);

View File

@ -588,6 +588,7 @@ pub struct Subreddit {
pub banner: String,
pub members: (String, String),
pub active: (String, String),
pub created: String,
pub wiki: bool,
pub nsfw: bool,
}

View File

@ -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;
}

View File

@ -126,9 +126,12 @@
<div id="sub_details">
<label>Members</label>
<label>Active</label>
<label>Created</label>
<div title="{{ sub.members.1 }}">{{ sub.members.0 }}</div>
<div title="{{ sub.active.1 }}">{{ sub.active.0 }}</div>
<div>{{ sub.created }}</div>
</div>
<hr>
<div id="sub_actions">
<div id="sub_subscription">
{% if prefs.subscriptions.contains(sub.name) %}