Skip to content

Commit 5e6f064

Browse files
committed
Parse videopress media details
Atomic sites (maybe all sites with Jetpack Videopress enabled) returns a `media_details` JSON object that is not compatible with the one in core. That means the `parse_as_mime_type` function does not return `VideoMediaDetails`. We want to add a dedicated function to parse the `media_details` values provide by the VideoPress plugin.
1 parent 8ead9c3 commit 5e6f064

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

wp_api/src/jetpack/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::request::endpoint::AsNamespace;
33
pub mod client;
44
pub mod connection;
55
pub mod endpoint;
6+
pub mod videopress;
67

78
pub(crate) struct JetpackNamespace();
89

wp_api/src/jetpack/videopress.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use serde::{Deserialize, Serialize};
2+
3+
use crate::media::MediaDetails;
4+
5+
#[derive(Debug, Serialize, Deserialize, uniffi::Record)]
6+
pub struct VideoPressMediaDetails {
7+
pub width: u32,
8+
pub height: u32,
9+
pub videopress: VideoPressDetails,
10+
}
11+
12+
#[derive(Debug, Serialize, Deserialize, uniffi::Record)]
13+
pub struct VideoPressDetails {
14+
pub duration: u64,
15+
pub poster: String,
16+
}
17+
18+
#[uniffi::export(with_foreign)]
19+
pub trait VideoPressMediaDetailsExtension: Send + Sync {
20+
fn parse_videopress(&self, mime_type: String) -> Option<VideoPressMediaDetails>;
21+
}
22+
23+
#[uniffi::export]
24+
impl VideoPressMediaDetailsExtension for MediaDetails {
25+
fn parse_videopress(&self, mime_type: String) -> Option<VideoPressMediaDetails> {
26+
if mime_type != "video/videopress" {
27+
return None;
28+
}
29+
30+
serde_json::from_str::<VideoPressMediaDetails>(self.payload.get()).ok()
31+
}
32+
}

wp_api/src/media.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ pub struct SparseMedia {
544544
#[derive(Debug, Serialize, Deserialize, uniffi::Object)]
545545
#[serde(transparent)]
546546
pub struct MediaDetails {
547-
payload: Box<RawValue>,
547+
pub payload: Box<RawValue>,
548548
}
549549

550550
#[uniffi::export]

0 commit comments

Comments
 (0)