This commit is contained in:
MedzikUser 2022-06-16 16:58:37 +02:00
parent 8e156c4d27
commit 57d96be98c
No known key found for this signature in database
GPG Key ID: A5FAC1E185C112DB
8 changed files with 16 additions and 11 deletions

View File

@ -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<Database>,

View File

@ -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<Database>,

View File

@ -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<Database>,

View File

@ -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<PathBuf>) -> io::Result<u64> {
fn dir_size(mut dir: fs::ReadDir) -> io::Result<u64> {

View File

@ -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<Database>,

View File

@ -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();

View File

@ -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<u8>
let password = hex::encode(CryptographicHash::hash(
Algorithm::SHA512,
password.as_bytes(),

View File

@ -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,