mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
38 lines
1.1 KiB
Rust
38 lines
1.1 KiB
Rust
pub mod create_dir;
|
|
pub mod delete;
|
|
pub mod download;
|
|
pub mod list;
|
|
pub mod upload;
|
|
|
|
pub fn app() -> axum::Router {
|
|
use axum::routing::{delete, get, post};
|
|
|
|
axum::Router::new()
|
|
.route("/list", post(list::handle))
|
|
.route("/upload", post(upload::handle))
|
|
.route("/delete", delete(delete::handle))
|
|
.route("/download", get(download::handle))
|
|
.route("/createdir", post(create_dir::handle))
|
|
}
|
|
|
|
pub fn validate_path(path: &str) -> Result<(), homedisk_types::errors::ServerError> {
|
|
use homedisk_types::errors::{FsError, ServerError};
|
|
|
|
// `path` can't contain `..`
|
|
// to prevent attack attempts because by using a `..` you can access the previous folder
|
|
if path.contains("..") {
|
|
return Err(ServerError::FsError(FsError::ReadDirectory(
|
|
"the `path` must not contain `..`".to_string(),
|
|
)));
|
|
}
|
|
|
|
// `path` can't contain `~`
|
|
// to prevent attack attempts because `~` can get up a directory on `$HOME`
|
|
if path.contains('~') {
|
|
return Err(ServerError::FsError(FsError::ReadDirectory(
|
|
"the `path` must not contain `~`".to_string(),
|
|
)));
|
|
}
|
|
|
|
Ok(())
|
|
}
|