diff options
Diffstat (limited to 'src/listing.rs')
-rw-r--r-- | src/listing.rs | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/listing.rs b/src/listing.rs index 4a0927b..b7070f3 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -11,6 +11,7 @@ use std::time::SystemTime; use crate::archive; use crate::errors; use crate::renderer; +use crate::themes; /// Query parameters #[derive(Debug, Deserialize)] @@ -18,21 +19,20 @@ struct QueryParameters { sort: Option<SortingMethod>, order: Option<SortingOrder>, download: Option<archive::CompressionMethod>, + theme: Option<themes::ColorScheme>, } /// Available sorting methods #[derive(Debug, Deserialize, Clone)] +#[serde(rename_all = "lowercase")] pub enum SortingMethod { /// Sort by name - #[serde(alias = "name")] Name, /// Sort by size - #[serde(alias = "size")] Size, /// Sort by last modification date (natural sort: follows alphanumerical order) - #[serde(alias = "date")] Date, } @@ -77,6 +77,9 @@ pub enum EntryType { /// Entry is a file File, + + /// Entry is a symlink + Symlink, } /// Entry @@ -114,9 +117,20 @@ impl Entry { } } + /// Returns wether the entry is a directory pub fn is_dir(&self) -> bool { self.entry_type == EntryType::Directory } + + /// Returns wether the entry is a file + pub fn is_file(&self) -> bool { + self.entry_type == EntryType::File + } + + /// Returns wether the entry is a symlink + pub fn is_symlink(&self) -> bool { + self.entry_type == EntryType::Symlink + } } pub fn file_handler(req: &HttpRequest<crate::MiniserveConfig>) -> Result<fs::NamedFile> { @@ -132,6 +146,7 @@ pub fn directory_listing<S>( skip_symlinks: bool, file_upload: bool, random_route: Option<String>, + default_color_scheme: themes::ColorScheme, upload_route: String, ) -> Result<HttpResponse, io::Error> { let title = format!("Index of {}", req.path()); @@ -144,15 +159,16 @@ pub fn directory_listing<S>( Err(_) => base.to_path_buf(), }; - let (sort_method, sort_order, download) = + let (sort_method, sort_order, download, color_scheme) = if let Ok(query) = Query::<QueryParameters>::extract(req) { ( query.sort.clone(), query.order.clone(), query.download.clone(), + query.theme.clone(), ) } else { - (None, None, None) + (None, None, None, None) }; let mut entries: Vec<Entry> = Vec::new(); @@ -180,7 +196,15 @@ pub fn directory_listing<S>( Err(_) => None, }; - if metadata.is_dir() { + if metadata.file_type().is_symlink() { + entries.push(Entry::new( + file_name, + EntryType::Symlink, + file_url, + None, + last_modification_date, + )); + } else if metadata.is_dir() { entries.push(Entry::new( file_name, EntryType::Directory, @@ -233,6 +257,8 @@ pub fn directory_listing<S>( } } + let color_scheme = color_scheme.unwrap_or(default_color_scheme); + if let Some(compression_method) = &download { log::info!( "Creating an archive ({extension}) of {path}...", @@ -271,6 +297,7 @@ pub fn directory_listing<S>( page_parent, sort_method, sort_order, + color_scheme, file_upload, &upload_route, ¤t_dir.display().to_string(), |