use bytes::Bytes;
use serde_json::Value;
use std::path::PathBuf;
#[derive(Clone, Debug)]
pub enum ResourceSource {
Bytes(Bytes),
Path(PathBuf),
Url(String),
}
#[derive(Clone, Debug, Default)]
pub struct ResourceRef {
pub id: Option<String>,
pub url: Option<String>,
pub raw: Value,
}
#[derive(Clone, Debug, Default)]
pub struct Media {
pub source: Option<ResourceSource>,
pub recv: Option<ResourceRef>,
pub width: Option<u32>,
pub height: Option<u32>,
pub duration: Option<u32>,
pub summary: Option<String>,
}
impl ResourceSource {
pub fn bytes(b: impl Into<Bytes>) -> Self {
ResourceSource::Bytes(b.into())
}
pub fn url(u: impl Into<String>) -> Self {
ResourceSource::Url(u.into())
}
pub fn path(p: impl Into<PathBuf>) -> Self {
ResourceSource::Path(p.into())
}
}
impl Media {
pub fn from_source(source: ResourceSource) -> Self {
Media { source: Some(source), ..Default::default() }
}
pub fn from_recv(recv: ResourceRef) -> Self {
Media { recv: Some(recv), ..Default::default() }
}
}