aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/archive.rs36
-rw-r--r--src/listing.rs18
-rw-r--r--src/main.rs1
-rw-r--r--src/renderer.rs16
4 files changed, 36 insertions, 35 deletions
diff --git a/src/archive.rs b/src/archive.rs
index e53aea8..b5a0eda 100644
--- a/src/archive.rs
+++ b/src/archive.rs
@@ -11,11 +11,11 @@ use zip::{write, ZipWriter};
use crate::errors::ContextualError;
-/// Available compression methods
+/// Available archive methods
#[derive(Deserialize, Clone, Copy, EnumIter, EnumString, Display)]
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
-pub enum CompressionMethod {
+pub enum ArchiveMethod {
/// Gzipped tarball
TarGz,
@@ -26,38 +26,38 @@ pub enum CompressionMethod {
Zip,
}
-impl CompressionMethod {
+impl ArchiveMethod {
pub fn extension(self) -> String {
match self {
- CompressionMethod::TarGz => "tar.gz",
- CompressionMethod::Tar => "tar",
- CompressionMethod::Zip => "zip",
+ ArchiveMethod::TarGz => "tar.gz",
+ ArchiveMethod::Tar => "tar",
+ ArchiveMethod::Zip => "zip",
}
.to_string()
}
pub fn content_type(self) -> String {
match self {
- CompressionMethod::TarGz => "application/gzip",
- CompressionMethod::Tar => "application/tar",
- CompressionMethod::Zip => "application/zip",
+ ArchiveMethod::TarGz => "application/gzip",
+ ArchiveMethod::Tar => "application/tar",
+ ArchiveMethod::Zip => "application/zip",
}
.to_string()
}
pub fn content_encoding(self) -> ContentEncoding {
match self {
- CompressionMethod::TarGz => ContentEncoding::Gzip,
- CompressionMethod::Tar => ContentEncoding::Identity,
- CompressionMethod::Zip => ContentEncoding::Identity,
+ ArchiveMethod::TarGz => ContentEncoding::Gzip,
+ ArchiveMethod::Tar => ContentEncoding::Identity,
+ ArchiveMethod::Zip => ContentEncoding::Identity,
}
}
pub fn is_enabled(self, tar_enabled: bool, tar_gz_enabled: bool, zip_enabled: bool) -> bool {
match self {
- CompressionMethod::TarGz => tar_gz_enabled,
- CompressionMethod::Tar => tar_enabled,
- CompressionMethod::Zip => zip_enabled,
+ ArchiveMethod::TarGz => tar_gz_enabled,
+ ArchiveMethod::Tar => tar_enabled,
+ ArchiveMethod::Zip => zip_enabled,
}
}
@@ -78,9 +78,9 @@ impl CompressionMethod {
{
let dir = dir.as_ref();
match self {
- CompressionMethod::TarGz => tar_gz(dir, skip_symlinks, out),
- CompressionMethod::Tar => tar_dir(dir, skip_symlinks, out),
- CompressionMethod::Zip => zip_dir(dir, skip_symlinks, out),
+ ArchiveMethod::TarGz => tar_gz(dir, skip_symlinks, out),
+ ArchiveMethod::Tar => tar_dir(dir, skip_symlinks, out),
+ ArchiveMethod::Zip => zip_dir(dir, skip_symlinks, out),
}
}
}
diff --git a/src/listing.rs b/src/listing.rs
index 79a4172..43cfb0e 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -12,7 +12,7 @@ use std::path::{Component, Path, PathBuf};
use std::time::SystemTime;
use strum_macros::{Display, EnumString};
-use crate::archive::CompressionMethod;
+use crate::archive::ArchiveMethod;
use crate::errors::{self, ContextualError};
use crate::renderer;
use percent_encode_sets::PATH_SEGMENT;
@@ -34,7 +34,7 @@ pub struct QueryParameters {
pub sort: Option<SortingMethod>,
pub order: Option<SortingOrder>,
qrcode: Option<String>,
- download: Option<CompressionMethod>,
+ download: Option<ArchiveMethod>,
}
/// Available sorting methods
@@ -336,8 +336,8 @@ pub fn directory_listing(
entries.sort_by_key(|e| !e.is_dir());
}
- if let Some(compression_method) = query_params.download {
- if !compression_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) {
+ if let Some(archive_method) = query_params.download {
+ if !archive_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) {
return Ok(ServiceResponse::new(
req.clone(),
HttpResponse::Forbidden()
@@ -363,14 +363,14 @@ pub fn directory_listing(
}
log::info!(
"Creating an archive ({extension}) of {path}...",
- extension = compression_method.extension(),
+ extension = archive_method.extension(),
path = &dir.path.display().to_string()
);
let file_name = format!(
"{}.{}",
dir.path.file_name().unwrap().to_str().unwrap(),
- compression_method.extension()
+ archive_method.extension()
);
// We will create the archive in a separate thread, and stream the content using a pipe.
@@ -382,7 +382,7 @@ pub fn directory_listing(
// Start the actual archive creation in a separate thread.
let dir = dir.path.to_path_buf();
std::thread::spawn(move || {
- if let Err(err) = compression_method.create_archive(dir, skip_symlinks, pipe) {
+ if let Err(err) = archive_method.create_archive(dir, skip_symlinks, pipe) {
log::error!("Error during archive creation: {:?}", err);
}
});
@@ -390,8 +390,8 @@ pub fn directory_listing(
Ok(ServiceResponse::new(
req.clone(),
HttpResponse::Ok()
- .content_type(compression_method.content_type())
- .encoding(compression_method.content_encoding())
+ .content_type(archive_method.content_type())
+ .encoding(archive_method.content_encoding())
.header("Content-Transfer-Encoding", "binary")
.header(
"Content-Disposition",
diff --git a/src/main.rs b/src/main.rs
index f174d57..b6dd856 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -465,6 +465,7 @@ fn configure_app(app: &mut web::ServiceConfig, conf: &MiniserveConfig) {
title.clone(),
)
})
+ .prefer_utf8(true)
.default_handler(web::to(error_404));
Some(files)
}
diff --git a/src/renderer.rs b/src/renderer.rs
index 1f57164..d2beda3 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -6,7 +6,7 @@ use std::time::SystemTime;
use structopt::clap::{crate_name, crate_version};
use strum::IntoEnumIterator;
-use crate::archive::CompressionMethod;
+use crate::archive::ArchiveMethod;
use crate::listing::{Breadcrumb, Entry, SortingMethod, SortingOrder};
/// Renders the file listing
@@ -97,9 +97,9 @@ pub fn page(
div.toolbar {
@if tar_enabled || tar_gz_enabled || zip_enabled {
div.download {
- @for compression_method in CompressionMethod::iter() {
- @if compression_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) {
- (archive_button(compression_method, sort_method, sort_order))
+ @for archive_method in ArchiveMethod::iter() {
+ @if archive_method.is_enabled(tar_enabled, tar_gz_enabled, zip_enabled) {
+ (archive_button(archive_method, sort_method, sort_order))
}
}
}
@@ -230,21 +230,21 @@ fn color_scheme_link(color_scheme: &(&str, &str)) -> Markup {
/// Partial: archive button
fn archive_button(
- compress_method: CompressionMethod,
+ archive_method: ArchiveMethod,
sort_method: Option<SortingMethod>,
sort_order: Option<SortingOrder>,
) -> Markup {
let link = if sort_method.is_none() && sort_order.is_none() {
- format!("?download={}", compress_method)
+ format!("?download={}", archive_method)
} else {
format!(
"{}&download={}",
parametrized_link("", sort_method, sort_order,),
- compress_method
+ archive_method
)
};
- let text = format!("Download .{}", compress_method.extension());
+ let text = format!("Download .{}", archive_method.extension());
html! {
a href=(link) {