Add websockets URL to parsing

This commit is contained in:
Matthew Esposito 2024-01-03 20:06:08 -05:00
parent 89ba46e15d
commit c597a20311
No known key found for this signature in database

View File

@ -311,6 +311,7 @@ pub struct Post {
pub gallery: Vec<GalleryMedia>, pub gallery: Vec<GalleryMedia>,
pub awards: Awards, pub awards: Awards,
pub nsfw: bool, pub nsfw: bool,
pub ws_url: String,
} }
impl Post { impl Post {
@ -413,6 +414,7 @@ impl Post {
gallery, gallery,
awards, awards,
nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(), nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(),
ws_url: val(post, "websocket_url"),
}); });
} }
@ -739,6 +741,7 @@ pub async fn parse_post(post: &serde_json::Value) -> Post {
gallery, gallery,
awards, awards,
nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(), nsfw: post["data"]["over_18"].as_bool().unwrap_or_default(),
ws_url: val(post, "websocket_url"),
} }
} }
@ -1138,3 +1141,12 @@ async fn test_fetching_nsfw_subreddit() {
assert!(subreddit.is_ok()); assert!(subreddit.is_ok());
assert!(!subreddit.unwrap().0.is_empty()); assert!(!subreddit.unwrap().0.is_empty());
} }
#[tokio::test(flavor = "multi_thread")]
async fn test_fetching_ws() {
let subreddit = Post::fetch("/r/popular", false).await;
assert!(subreddit.is_ok());
for post in subreddit.unwrap().0 {
assert!(post.ws_url.starts_with("wss://k8s-lb.wss.redditmedia.com/link/"));
}
}