better file previews
This commit is contained in:
@@ -5,7 +5,7 @@ pub use file::*;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum FileType {
|
||||
File,
|
||||
@@ -17,10 +17,22 @@ pub enum FileType {
|
||||
pub struct DirectoryEntry {
|
||||
name: String,
|
||||
file_type: FileType,
|
||||
mime_type: Option<String>,
|
||||
}
|
||||
|
||||
impl DirectoryEntry {
|
||||
pub fn new(name: String, file_type: FileType) -> Self {
|
||||
Self { name, file_type }
|
||||
let mime_type = match name.split("/").last() {
|
||||
Some(last) if last.contains(".") => {
|
||||
mime_guess::from_path(&name).first_raw().map(str::to_owned)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Self {
|
||||
name,
|
||||
file_type,
|
||||
mime_type,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user