Fix gallery unwrapping
This commit is contained in:
parent
7edca18f8d
commit
ac5ef89dff
@ -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 {
|
||||||
|
10
src/utils.rs
10
src/utils.rs
@ -230,15 +230,15 @@ pub async fn media(data: &Value) -> (String, Media, Vec<GalleryMedia>) {
|
|||||||
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(),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user