Fix gallery unwrapping

This commit is contained in:
spikecodes 2021-02-07 17:33:54 -08:00
parent 7edca18f8d
commit ac5ef89dff
No known key found for this signature in database
GPG Key ID: 004CECFF9B463BCB
2 changed files with 10 additions and 8 deletions

View File

@ -31,7 +31,9 @@ async fn pwa_logo() -> HttpResponse {
// Required for iOS App Icons // Required for iOS App Icons
async fn iphone_logo() -> HttpResponse { async fn iphone_logo() -> HttpResponse {
HttpResponse::Ok().content_type("image/png").body(include_bytes!("../static/touch-icon-iphone.png").as_ref()) HttpResponse::Ok()
.content_type("image/png")
.body(include_bytes!("../static/touch-icon-iphone.png").as_ref())
} }
async fn robots() -> HttpResponse { async fn robots() -> HttpResponse {

View File

@ -52,7 +52,7 @@ pub struct GalleryMedia {
pub width: i64, pub width: i64,
pub height: i64, pub height: i64,
pub caption: String, pub caption: String,
pub outbound_url: String, pub outbound_url: String,
} }
// Post containing content, metadata and media // Post containing content, metadata and media
@ -227,18 +227,18 @@ pub async fn media(data: &Value) -> (String, Media, Vec<GalleryMedia>) {
post_type = "self"; post_type = "self";
data["permalink"].as_str().unwrap_or_default().to_string() data["permalink"].as_str().unwrap_or_default().to_string()
} else if data["is_gallery"].as_bool().unwrap_or_default() { } else if data["is_gallery"].as_bool().unwrap_or_default() {
post_type = "gallery"; post_type = "gallery";
gallery = data["gallery_data"]["items"] gallery = data["gallery_data"]["items"]
.as_array() .as_array()
.unwrap() .unwrap_or(&Vec::<Value>::new())
.iter() .iter()
.map(|item| { .map(|item| {
let media_id = item["media_id"].as_str().unwrap_or_default(); let media_id = item["media_id"].as_str().unwrap_or_default();
let image = data["media_metadata"][media_id].as_object().unwrap(); let image = &data["media_metadata"][media_id].as_object().map(ToOwned::to_owned).unwrap_or_default()["s"];
GalleryMedia { GalleryMedia {
url: format_url(image["s"]["u"].as_str().unwrap_or_default()), url: format_url(image["u"].as_str().unwrap_or_default()),
width: image["s"]["x"].as_i64().unwrap_or_default(), width: image["x"].as_i64().unwrap_or_default(),
height: image["s"]["y"].as_i64().unwrap_or_default(), height: image["y"].as_i64().unwrap_or_default(),
caption: item["caption"].as_str().unwrap_or_default().to_string(), caption: item["caption"].as_str().unwrap_or_default().to_string(),
outbound_url: item["outbound_url"].as_str().unwrap_or_default().to_string(), outbound_url: item["outbound_url"].as_str().unwrap_or_default().to_string(),
} }