From 8ed18a551696ba4f89d7dfbdeaa879b21e079d33 Mon Sep 17 00:00:00 2001 From: boasting-squirrel Date: Mon, 1 Apr 2019 20:36:35 +0200 Subject: Color schemes --- src/listing.rs | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) (limited to 'src/listing.rs') diff --git a/src/listing.rs b/src/listing.rs index c4daf88..0746f5c 100644 --- a/src/listing.rs +++ b/src/listing.rs @@ -11,6 +11,10 @@ use std::time::SystemTime; use crate::archive; use crate::errors; use crate::renderer; +use crate::themes; + +/// Default color scheme, when none is set through query parameters +const DEFAULT_COLORSCHEME: themes::ColorScheme = themes::ColorScheme::ArchLinux; /// Query parameters #[derive(Debug, Deserialize)] @@ -18,6 +22,7 @@ struct QueryParameters { sort: Option, order: Option, download: Option, + theme: Option, } /// Available sorting methods @@ -77,6 +82,9 @@ pub enum EntryType { /// Entry is a file File, + + /// Entry is a symlink + Symlink, } /// Entry @@ -114,9 +122,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) -> Result { @@ -138,15 +157,16 @@ pub fn directory_listing( let is_root = base.parent().is_none() || req.path() == random_route; let page_parent = base.parent().map(|p| p.display().to_string()); - let (sort_method, sort_order, download) = + let (sort_method, sort_order, download, color_scheme) = if let Ok(query) = Query::::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 = Vec::new(); @@ -174,7 +194,15 @@ pub fn directory_listing( 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, @@ -227,6 +255,8 @@ pub fn directory_listing( } } + let color_scheme = color_scheme.unwrap_or(DEFAULT_COLORSCHEME); + if let Some(compression_method) = &download { log::info!( "Creating an archive ({extension}) of {path}...", @@ -265,6 +295,7 @@ pub fn directory_listing( page_parent, sort_method, sort_order, + color_scheme, ) .into_string(), )) -- cgit v1.2.3