This commit is contained in:
spikecodes 2021-03-11 20:15:26 -08:00
parent b2ae5e486f
commit 4173362ce1
No known key found for this signature in database
GPG key ID: 004CECFF9B463BCB
5 changed files with 41 additions and 16 deletions

View file

@ -1,4 +1,5 @@
// CRATES
use crate::esc;
use crate::utils::{error, format_url, param, request, template, Post, Preferences, User};
use askama::Template;
use tide::Request;
@ -57,17 +58,17 @@ async fn user(name: &str) -> Result<User, String> {
// Grab creation date as unix timestamp
let created: i64 = res["data"]["created"].as_f64().unwrap_or(0.0).round() as i64;
// nested_val function used to parse JSON from Reddit APIs
// Closure used to parse JSON from Reddit APIs
let about = |item| res["data"]["subreddit"][item].as_str().unwrap_or_default().to_string();
// Parse the JSON output into a User struct
Ok(User {
name: name.to_string(),
title: about("title"),
title: esc!(about("title")),
icon: format_url(&about("icon_img")),
karma: res["data"]["total_karma"].as_i64().unwrap_or(0),
created: OffsetDateTime::from_unix_timestamp(created).format("%b %d '%y"),
banner: about("banner_img"),
banner: esc!(about("banner_img")),
description: about("public_description"),
})
}