use chrono::{DateTime, Local};
use serde::{Deserialize, Serialize};
use std::cmp::{Ord, Ordering};
#[derive(Debug, Eq, Serialize)]
pub struct DirectoryEntry {
pub(crate) display_name: String,
pub(crate) is_dir: bool,
pub(crate) size_bytes: u64,
pub(crate) entry_path: String,
pub(crate) date_created: Option<DateTime<Local>>,
pub(crate) date_modified: Option<DateTime<Local>>,
}
impl Ord for DirectoryEntry {
fn cmp(&self, other: &Self) -> Ordering {
if self.is_dir && other.is_dir {
return self.display_name.cmp(&other.display_name);
}
if self.is_dir && !other.is_dir {
return Ordering::Less;
}
Ordering::Greater
}
}
impl PartialOrd for DirectoryEntry {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for DirectoryEntry {
fn eq(&self, other: &Self) -> bool {
if self.is_dir && other.is_dir {
return self.display_name == other.display_name;
}
self.display_name == other.display_name
}
}
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
pub struct BreadcrumbItem {
pub(crate) entry_name: String,
pub(crate) entry_link: String,
}
#[derive(Debug, Serialize)]
pub struct DirectoryIndex {
pub(crate) entries: Vec<DirectoryEntry>,
pub(crate) breadcrumbs: Vec<BreadcrumbItem>,
pub(crate) sort: Sort,
}
#[derive(Serialize, Debug, PartialEq, Deserialize)]
pub enum Sort {
Directory,
Name,
Size,
DateCreated,
DateModified,
}