From 57d96be98cacc43d2a35214ee0f10e7959fcb212 Mon Sep 17 00:00:00 2001 From: MedzikUser Date: Thu, 16 Jun 2022 16:58:37 +0200 Subject: [PATCH] update --- server/src/fs/create_dir.rs | 3 ++- server/src/fs/delete.rs | 3 ++- server/src/fs/download.rs | 3 ++- server/src/fs/list.rs | 3 ++- server/src/fs/upload.rs | 3 ++- types/src/config/toml.rs | 2 +- types/src/database/user.rs | 2 +- types/src/errors/server.rs | 8 ++++---- 8 files changed, 16 insertions(+), 11 deletions(-) diff --git a/server/src/fs/create_dir.rs b/server/src/fs/create_dir.rs index 34b295c..bcc46df 100644 --- a/server/src/fs/create_dir.rs +++ b/server/src/fs/create_dir.rs @@ -9,9 +9,10 @@ use homedisk_types::{ errors::{FsError, ServerError}, }; -use crate::fs::validate_path; use crate::middleware::{find_user, validate_json, validate_jwt}; +use super::validate_path; + /// Handle `/fs/createdir` requests pub async fn handle( Extension(db): Extension, diff --git a/server/src/fs/delete.rs b/server/src/fs/delete.rs index 4a5a64a..a34541c 100644 --- a/server/src/fs/delete.rs +++ b/server/src/fs/delete.rs @@ -10,9 +10,10 @@ use homedisk_types::{ fs::delete::Request, }; -use crate::fs::validate_path; use crate::middleware::{find_user, validate_jwt}; +use super::validate_path; + /// Handle `/fs/delete` requests pub async fn handle( Extension(db): Extension, diff --git a/server/src/fs/download.rs b/server/src/fs/download.rs index a38a2a4..f8b73ac 100644 --- a/server/src/fs/download.rs +++ b/server/src/fs/download.rs @@ -1,6 +1,5 @@ use std::fs; -use crate::fs::validate_path; use axum::extract::Query; use axum::Extension; use axum_auth::AuthBearer; @@ -10,6 +9,8 @@ use homedisk_types::{config::Config, errors::ServerError}; use crate::middleware::{find_user, validate_jwt}; +use super::validate_path; + /// Handle `/fs/download` requests pub async fn handle( Extension(db): Extension, diff --git a/server/src/fs/list.rs b/server/src/fs/list.rs index a012c21..5d73975 100644 --- a/server/src/fs/list.rs +++ b/server/src/fs/list.rs @@ -1,7 +1,6 @@ use std::path::PathBuf; use std::{fs, io}; -use crate::fs::validate_path; use axum::{extract::rejection::JsonRejection, Extension, Json}; use axum_auth::AuthBearer; use byte_unit::Byte; @@ -15,6 +14,8 @@ use homedisk_types::{ use crate::middleware::{find_user, validate_json, validate_jwt}; +use super::validate_path; + /// Get directory size on disk (size of all files in directory). fn dir_size(path: impl Into) -> io::Result { fn dir_size(mut dir: fs::ReadDir) -> io::Result { diff --git a/server/src/fs/upload.rs b/server/src/fs/upload.rs index c3595a5..36bb836 100644 --- a/server/src/fs/upload.rs +++ b/server/src/fs/upload.rs @@ -12,9 +12,10 @@ use homedisk_types::{ fs::upload::Pagination, }; -use crate::fs::validate_path; use crate::middleware::{find_user, validate_jwt}; +use super::validate_path; + /// Handle `/fs/upload` requests pub async fn handle( Extension(db): Extension, diff --git a/types/src/config/toml.rs b/types/src/config/toml.rs index 85d35bf..8fea97c 100644 --- a/types/src/config/toml.rs +++ b/types/src/config/toml.rs @@ -8,7 +8,7 @@ use super::types::Config; impl Config { /// Parse configuration file - /// ```ignore,rust + /// ```no_run /// use homedisk_types::config::Config; /// /// let config = Config::parse().unwrap(); diff --git a/types/src/database/user.rs b/types/src/database/user.rs index ebb0b86..a3a15f7 100644 --- a/types/src/database/user.rs +++ b/types/src/database/user.rs @@ -33,7 +33,7 @@ impl User { // salting the password let password = format!("{username}${password}"); - // hash password using SHA-512 + // hash password using SHA-512 and encode it to String from Vec let password = hex::encode(CryptographicHash::hash( Algorithm::SHA512, password.as_bytes(), diff --git a/types/src/errors/server.rs b/types/src/errors/server.rs index cdecb96..bc9bd7a 100644 --- a/types/src/errors/server.rs +++ b/types/src/errors/server.rs @@ -40,10 +40,10 @@ impl axum::response::IntoResponse for Error { let status = match self { Self::AuthError(ref err) => match err { AuthError::UserNotFound => StatusCode::BAD_REQUEST, - AuthError::UserAlreadyExists => StatusCode::NOT_ACCEPTABLE, - AuthError::UsernameTooShort => StatusCode::NOT_ACCEPTABLE, - AuthError::UsernameTooLong => StatusCode::NOT_ACCEPTABLE, - AuthError::PasswordTooShort => StatusCode::NOT_ACCEPTABLE, + AuthError::UserAlreadyExists => StatusCode::BAD_REQUEST, + AuthError::UsernameTooShort => StatusCode::BAD_REQUEST, + AuthError::UsernameTooLong => StatusCode::BAD_REQUEST, + AuthError::PasswordTooShort => StatusCode::BAD_REQUEST, AuthError::TokenGenerate => StatusCode::INTERNAL_SERVER_ERROR, AuthError::InvalidToken => StatusCode::BAD_REQUEST, AuthError::Other(_) => StatusCode::INTERNAL_SERVER_ERROR,