browsr-types 0.4.0

Shared data models and schemas for Browsr browser automation flows.
Documentation
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
#[serde(rename_all = "snake_case", tag = "type")]
pub enum FileType {
    Bytes {
        bytes: String,
        mime_type: String,
        name: Option<String>,
    },
    Url {
        url: String,
        mime_type: String,
        name: Option<String>,
    },
}

impl FileType {
    pub fn as_image_url(&self) -> Option<String> {
        match self {
            FileType::Url { url, .. } => Some(url.clone()),
            FileType::Bytes {
                bytes, mime_type, ..
            } => Some(format!("data:{};base64,{}", mime_type, bytes)),
        }
    }
}