Stickied Posts
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
// CRATES
|
||||
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Params, Post};
|
||||
use crate::utils::{format_num, format_url, request, val, Comment, ErrorTemplate, Flair, Flags, Params, Post};
|
||||
use actix_web::{http::StatusCode, web, HttpResponse, Result};
|
||||
|
||||
use async_recursion::async_recursion;
|
||||
@ -130,7 +130,10 @@ async fn parse_post(json: serde_json::Value) -> Result<Post, &'static str> {
|
||||
"white".to_string()
|
||||
},
|
||||
),
|
||||
nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false),
|
||||
flags: Flags {
|
||||
nsfw: post_data["data"]["over_18"].as_bool().unwrap_or(false),
|
||||
stickied: post_data["data"]["stickied"].as_bool().unwrap_or(false)
|
||||
},
|
||||
media: media.1,
|
||||
time: Utc.timestamp(unix_time, 0).format("%b %e %Y %H:%M UTC").to_string(),
|
||||
};
|
||||
|
12
src/utils.rs
12
src/utils.rs
@ -13,6 +13,11 @@ use base64::encode;
|
||||
//
|
||||
// Post flair with text, background color and foreground color
|
||||
pub struct Flair(pub String, pub String, pub String);
|
||||
// Post flags with nsfw and stickied
|
||||
pub struct Flags {
|
||||
pub nsfw: bool,
|
||||
pub stickied: bool
|
||||
}
|
||||
|
||||
// Post containing content, metadata and media
|
||||
pub struct Post {
|
||||
@ -25,7 +30,7 @@ pub struct Post {
|
||||
pub score: String,
|
||||
pub post_type: String,
|
||||
pub flair: Flair,
|
||||
pub nsfw: bool,
|
||||
pub flags: Flags,
|
||||
pub media: String,
|
||||
pub time: String,
|
||||
}
|
||||
@ -171,7 +176,10 @@ pub async fn fetch_posts(url: String, fallback_title: String) -> Result<(Vec<Pos
|
||||
"white".to_string()
|
||||
},
|
||||
),
|
||||
nsfw: post["data"]["over_18"].as_bool().unwrap_or(false),
|
||||
flags: Flags {
|
||||
nsfw: post["data"]["over_18"].as_bool().unwrap_or(false),
|
||||
stickied: post["data"]["stickied"].as_bool().unwrap_or(false)
|
||||
},
|
||||
url: val(post, "permalink").await,
|
||||
time: Utc.timestamp(unix_time, 0).format("%b %e '%y").to_string(),
|
||||
});
|
||||
|
Reference in New Issue
Block a user