aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/file_op.rs21
-rw-r--r--src/listing.rs13
-rw-r--r--src/renderer.rs4
3 files changed, 20 insertions, 18 deletions
diff --git a/src/file_op.rs b/src/file_op.rs
index df71be5..901c1d6 100644
--- a/src/file_op.rs
+++ b/src/file_op.rs
@@ -5,11 +5,12 @@ use std::{
path::{Component, Path, PathBuf},
};
-use actix_web::{http::header, HttpRequest, HttpResponse};
+use actix_web::{http::header, web, HttpRequest, HttpResponse};
use futures::TryStreamExt;
+use serde::Deserialize;
+use crate::file_utils::contains_symlink;
use crate::{errors::ContextualError, file_utils::sanitize_path};
-use crate::{file_utils::contains_symlink, listing};
/// Saves file data from a multipart form field (`field`) to `file_path`, optionally overwriting
/// existing file.
@@ -158,6 +159,12 @@ async fn handle_multipart(
save_file(field, path.join(filename_path), overwrite_files).await
}
+/// Query parameters used by upload and rm APIs
+#[derive(Deserialize, Default)]
+pub struct FileOpQueryParameters {
+ path: PathBuf,
+}
+
/// Handle incoming request to upload a file or create a directory.
/// Target file path is expected as path parameter in URI and is interpreted as relative from
/// server root directory. Any path which will go outside of this directory is considered
@@ -165,7 +172,8 @@ async fn handle_multipart(
/// This method returns future.
pub async fn upload_file(
req: HttpRequest,
- payload: actix_web::web::Payload,
+ query: web::Query<FileOpQueryParameters>,
+ payload: web::Payload,
) -> Result<HttpResponse, ContextualError> {
let conf = req.app_data::<crate::MiniserveConfig>().unwrap();
let return_path = if let Some(header) = req.headers().get(header::REFERER) {
@@ -174,14 +182,9 @@ pub async fn upload_file(
"/".to_string()
};
- let query_params = listing::extract_query_parameters(&req);
- let upload_path = query_params.path.as_ref().ok_or_else(|| {
- ContextualError::InvalidHttpRequestError("Missing query parameter 'path'".to_string())
- })?;
- let upload_path = sanitize_path(upload_path, conf.show_hidden).ok_or_else(|| {
+ let upload_path = sanitize_path(&query.path, conf.show_hidden).ok_or_else(|| {
ContextualError::InvalidPathError("Invalid value for 'path' parameter".to_string())
})?;
-
let app_root_dir = conf.path.canonicalize().map_err(|e| {
ContextualError::IoError("Failed to resolve path served by miniserve".to_string(), e)
})?;
diff --git a/src/listing.rs b/src/listing.rs
index e360368..a8feeb4 100644
--- a/src/listing.rs
+++ b/src/listing.rs
@@ -1,6 +1,6 @@
#![allow(clippy::format_push_string)]
use std::io;
-use std::path::{Component, Path, PathBuf};
+use std::path::{Component, Path};
use std::time::SystemTime;
use actix_web::{dev::ServiceResponse, web::Query, HttpMessage, HttpRequest, HttpResponse};
@@ -28,10 +28,9 @@ mod percent_encode_sets {
pub const PATH_SEGMENT: &AsciiSet = &PATH.add(b'/').add(b'\\');
}
-/// Query parameters
+/// Query parameters used by listing APIs
#[derive(Deserialize, Default)]
-pub struct QueryParameters {
- pub path: Option<PathBuf>,
+pub struct ListingQueryParameters {
pub sort: Option<SortingMethod>,
pub order: Option<SortingOrder>,
pub raw: Option<bool>,
@@ -393,13 +392,13 @@ pub fn directory_listing(
}
}
-pub fn extract_query_parameters(req: &HttpRequest) -> QueryParameters {
- match Query::<QueryParameters>::from_query(req.query_string()) {
+pub fn extract_query_parameters(req: &HttpRequest) -> ListingQueryParameters {
+ match Query::<ListingQueryParameters>::from_query(req.query_string()) {
Ok(Query(query_params)) => query_params,
Err(e) => {
let err = ContextualError::ParseError("query parameters".to_string(), e.to_string());
errors::log_error_chain(err.to_string());
- QueryParameters::default()
+ ListingQueryParameters::default()
}
}
}
diff --git a/src/renderer.rs b/src/renderer.rs
index 1257a67..b94817d 100644
--- a/src/renderer.rs
+++ b/src/renderer.rs
@@ -15,7 +15,7 @@ use strum::{Display, IntoEnumIterator};
use crate::auth::CurrentUser;
use crate::consts;
-use crate::listing::{Breadcrumb, Entry, QueryParameters, SortingMethod, SortingOrder};
+use crate::listing::{Breadcrumb, Entry, ListingQueryParameters, SortingMethod, SortingOrder};
use crate::{archive::ArchiveMethod, MiniserveConfig};
#[allow(clippy::too_many_arguments)]
@@ -25,7 +25,7 @@ pub fn page(
readme: Option<(String, String)>,
abs_uri: &Uri,
is_root: bool,
- query_params: QueryParameters,
+ query_params: ListingQueryParameters,
breadcrumbs: &[Breadcrumb],
encoded_dir: &str,
conf: &MiniserveConfig,