Add Sub Member Count & Fix Icons
This commit is contained in:
parent
7e79a0b712
commit
1a33582966
@ -13,7 +13,7 @@ struct SubredditTemplate {
|
|||||||
sub: Subreddit,
|
sub: Subreddit,
|
||||||
posts: Vec<Post>,
|
posts: Vec<Post>,
|
||||||
sort: String,
|
sort: String,
|
||||||
ends: (String, String),
|
ends: (String, String)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
@ -60,7 +60,7 @@ pub async fn render(sub_name: String, sort: Option<String>, ends: (Option<String
|
|||||||
sub: sub,
|
sub: sub,
|
||||||
posts: items.0,
|
posts: items.0,
|
||||||
sort: sorting,
|
sort: sorting,
|
||||||
ends: (before, items.1),
|
ends: (before, items.1)
|
||||||
}
|
}
|
||||||
.render()
|
.render()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
@ -84,15 +84,16 @@ async fn subreddit(sub: &String) -> Result<Subreddit, &'static str> {
|
|||||||
// Otherwise, grab the JSON output from the request
|
// Otherwise, grab the JSON output from the request
|
||||||
let res = req.unwrap();
|
let res = req.unwrap();
|
||||||
|
|
||||||
let icon: String = String::from(res["data"]["community_icon"].as_str().unwrap()); //val(&data, "community_icon");
|
let members = res["data"]["subscribers"].as_u64().unwrap_or(0);
|
||||||
let icon_split: std::str::Split<&str> = icon.split("?");
|
let active = res["data"]["accounts_active"].as_u64().unwrap_or(0);
|
||||||
let icon_parts: Vec<&str> = icon_split.collect();
|
|
||||||
|
|
||||||
let sub = Subreddit {
|
let sub = Subreddit {
|
||||||
name: val(&res, "display_name").await,
|
name: val(&res, "display_name").await,
|
||||||
title: val(&res, "title").await,
|
title: val(&res, "title").await,
|
||||||
description: val(&res, "public_description").await,
|
description: val(&res, "public_description").await,
|
||||||
icon: String::from(icon_parts[0]),
|
icon: val(&res, "icon_img").await,
|
||||||
|
members: if members > 1000 { format!("{}k", members / 1000) } else { members.to_string() },
|
||||||
|
active: if active > 1000 { format!("{}k", active / 1000) } else { active.to_string() },
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(sub)
|
Ok(sub)
|
||||||
|
12
src/utils.rs
12
src/utils.rs
@ -21,7 +21,7 @@ pub struct Post {
|
|||||||
pub score: String,
|
pub score: String,
|
||||||
pub media: String,
|
pub media: String,
|
||||||
pub time: String,
|
pub time: String,
|
||||||
pub flair: Flair,
|
pub flair: Flair
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -30,7 +30,7 @@ pub struct Comment {
|
|||||||
pub body: String,
|
pub body: String,
|
||||||
pub author: String,
|
pub author: String,
|
||||||
pub score: String,
|
pub score: String,
|
||||||
pub time: String,
|
pub time: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -40,7 +40,7 @@ pub struct User {
|
|||||||
pub icon: String,
|
pub icon: String,
|
||||||
pub karma: i64,
|
pub karma: i64,
|
||||||
pub banner: String,
|
pub banner: String,
|
||||||
pub description: String,
|
pub description: String
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -50,6 +50,8 @@ pub struct Subreddit {
|
|||||||
pub title: String,
|
pub title: String,
|
||||||
pub description: String,
|
pub description: String,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
|
pub members: String,
|
||||||
|
pub active: String
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser for query params, used in sorting (eg. /r/rust/?sort=hot)
|
// Parser for query params, used in sorting (eg. /r/rust/?sort=hot)
|
||||||
@ -57,14 +59,14 @@ pub struct Subreddit {
|
|||||||
pub struct Params {
|
pub struct Params {
|
||||||
pub sort: Option<String>,
|
pub sort: Option<String>,
|
||||||
pub after: Option<String>,
|
pub after: Option<String>,
|
||||||
pub before: Option<String>,
|
pub before: Option<String>
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error template
|
// Error template
|
||||||
#[derive(askama::Template)]
|
#[derive(askama::Template)]
|
||||||
#[template(path = "error.html", escape = "none")]
|
#[template(path = "error.html", escape = "none")]
|
||||||
pub struct ErrorTemplate {
|
pub struct ErrorTemplate {
|
||||||
pub message: String,
|
pub message: String
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user