Skip to main content

browsr_types/
file.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, PartialEq)]
5#[serde(rename_all = "snake_case", tag = "type")]
6pub enum FileType {
7    Bytes {
8        bytes: String,
9        mime_type: String,
10        name: Option<String>,
11    },
12    Url {
13        url: String,
14        mime_type: String,
15        name: Option<String>,
16    },
17}
18
19impl FileType {
20    pub fn as_image_url(&self) -> Option<String> {
21        match self {
22            FileType::Url { url, .. } => Some(url.clone()),
23            FileType::Bytes {
24                bytes, mime_type, ..
25            } => Some(format!("data:{};base64,{}", mime_type, bytes)),
26        }
27    }
28}