1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::schema::SCHEMA_IMAGE;

/// Specifies the type of a media file
///
#[derive(Debug, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum MediaType {
    Image,
}

pub fn get_media_type_relation_type(mt: &MediaType) -> &'static str {
    match mt {
        MediaType::Image => SCHEMA_IMAGE,
    }
}

pub fn get_media_type(filename: &str) -> Option<MediaType> {
    if filename.ends_with("png")
        | filename.ends_with("jpg")
        | filename.ends_with("jpeg")
        | filename.ends_with("bmp")
    {
        Some(MediaType::Image)
    } else {
        None
    }
}