aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/listing.rs23
-rw-r--r--src/renderer.rs47
2 files changed, 25 insertions, 45 deletions
diff --git a/src/listing.rs b/src/listing.rs
index b201ebb..66e541c 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -154,10 +154,7 @@ pub async fn file_handler(req: HttpRequest) -> actix_web::Result<actix_files::Na
/// List a directory and renders a HTML file accordingly
/// Adapted from https://docs.rs/actix-web/0.7.13/src/actix_web/fs.rs.html#564
-pub fn directory_listing(
- dir: &actix_files::Directory,
- req: &HttpRequest,
-) -> io::Result<ServiceResponse> {
+pub fn directory_listing(dir: &actix_files::Directory, req: &HttpRequest) -> io::Result<ServiceResponse> {
let extensions = req.extensions();
let current_user: Option<&CurrentUser> = extensions.get::<CurrentUser>();
@@ -198,8 +195,7 @@ pub fn directory_listing(
}
Component::Normal(s) => {
name = s.to_string_lossy().to_string();
- link_accumulator
- .push_str(&(utf8_percent_encode(&name, PATH_SEGMENT).to_string() + "/"));
+ link_accumulator.push_str(&(utf8_percent_encode(&name, PATH_SEGMENT).to_string() + "/"));
}
_ => name = "".to_string(),
};
@@ -223,7 +219,7 @@ pub fn directory_listing(
let res = match QrCode::with_error_correction_level(url, consts::QR_EC_LEVEL) {
Ok(qr) => HttpResponse::Ok()
.content_type(mime::TEXT_HTML_UTF_8)
- .body(renderer::qr_code_page(&qr).into_string()),
+ .body(renderer::qr_code_page(&breadcrumbs, &qr, conf).into_string()),
Err(err) => {
log::error!("URL is invalid (too long?): {:?}", err);
HttpResponse::UriTooLong().finish()
@@ -301,9 +297,9 @@ pub fn directory_listing(
}
match query_params.sort.unwrap_or(SortingMethod::Name) {
- SortingMethod::Name => entries.sort_by(|e1, e2| {
- alphanumeric_sort::compare_str(e1.name.to_lowercase(), e2.name.to_lowercase())
- }),
+ SortingMethod::Name => {
+ entries.sort_by(|e1, e2| alphanumeric_sort::compare_str(e1.name.to_lowercase(), e2.name.to_lowercase()))
+ }
SortingMethod::Size => entries.sort_by(|e1, e2| {
// If we can't get the size of the entry (directory for instance)
// let's consider it's 0b
@@ -371,10 +367,7 @@ pub fn directory_listing(
.content_type(archive_method.content_type())
.append_header(archive_method.content_encoding())
.append_header(("Content-Transfer-Encoding", "binary"))
- .append_header((
- "Content-Disposition",
- format!("attachment; filename={:?}", file_name),
- ))
+ .append_header(("Content-Disposition", format!("attachment; filename={:?}", file_name)))
.body(actix_web::body::BodyStream::new(rx)),
))
} else {
@@ -386,7 +379,7 @@ pub fn directory_listing(
readme,
is_root,
query_params,
- breadcrumbs,
+ &breadcrumbs,
&encoded_dir,
conf,
current_user,
diff --git a/src/renderer.rs b/src/renderer.rs
index 95aeb5f..0154ce0 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -18,7 +18,7 @@ pub fn page(
readme: Option<(String, String)>,
is_root: bool,
query_params: QueryParameters,
- breadcrumbs: Vec<Breadcrumb>,
+ breadcrumbs: &[Breadcrumb],
encoded_dir: &str,
conf: &MiniserveConfig,
current_user: Option<&CurrentUser>,
@@ -34,11 +34,7 @@ pub fn page(
let upload_action = build_upload_action(&upload_route, encoded_dir, sort_method, sort_order);
let mkdir_action = build_mkdir_action(&upload_route, encoded_dir);
- let title_path = breadcrumbs
- .iter()
- .map(|el| el.name.clone())
- .collect::<Vec<_>>()
- .join("/");
+ let title_path = breadcrumbs_to_path_string(breadcrumbs);
html! {
(DOCTYPE)
@@ -226,34 +222,16 @@ pub fn raw(entries: Vec<Entry>, is_root: bool) -> Markup {
}
/// Renders the QR code page
-pub fn qr_code_page(qr: &QrCode) -> Markup {
+pub fn qr_code_page(breadcrumbs: &[Breadcrumb], qr: &QrCode, conf: &MiniserveConfig) -> Markup {
use qrcode::render::svg;
+ let title = breadcrumbs_to_path_string(breadcrumbs);
+
html! {
(DOCTYPE)
- html {
- body.qr_code_page {
- // make QR code expand and fill page
- style {
- (PreEscaped("\
- html {\
- width: 100vw;\
- height: 100vh;\
- }\
- body {\
- width: 100%;\
- height: 100%;\
- margin: 0;\
- display: grid;\
- align-items: center;\
- justify-items: center;\
- }\
- svg {\
- width: 80%;\
- height: 80%;\
- }\
- "))
- }
+ html.qr_code_page {
+ (page_header(&title, false, &conf.favicon_route, &conf.css_route))
+ body {
(PreEscaped(qr.render()
.quiet_zone(false)
.dark_color(svg::Color("#000000"))
@@ -264,6 +242,15 @@ pub fn qr_code_page(qr: &QrCode) -> Markup {
}
}
+/// Build a path string from a list of breadcrumbs.
+fn breadcrumbs_to_path_string(breadcrumbs: &[Breadcrumb]) -> String {
+ breadcrumbs
+ .iter()
+ .map(|el| el.name.clone())
+ .collect::<Vec<_>>()
+ .join("/")
+}
+
// Partial: version footer
fn version_footer() -> Markup {
html! {