mirror of
https://github.com/MedzikUser/HomeDisk.git
synced 2024-08-14 21:46:53 +00:00
update
This commit is contained in:
parent
8e156c4d27
commit
57d96be98c
8 changed files with 16 additions and 11 deletions
|
@ -9,9 +9,10 @@ use homedisk_types::{
|
||||||
errors::{FsError, ServerError},
|
errors::{FsError, ServerError},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::fs::validate_path;
|
|
||||||
use crate::middleware::{find_user, validate_json, validate_jwt};
|
use crate::middleware::{find_user, validate_json, validate_jwt};
|
||||||
|
|
||||||
|
use super::validate_path;
|
||||||
|
|
||||||
/// Handle `/fs/createdir` requests
|
/// Handle `/fs/createdir` requests
|
||||||
pub async fn handle(
|
pub async fn handle(
|
||||||
Extension(db): Extension<Database>,
|
Extension(db): Extension<Database>,
|
||||||
|
|
|
@ -10,9 +10,10 @@ use homedisk_types::{
|
||||||
fs::delete::Request,
|
fs::delete::Request,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::fs::validate_path;
|
|
||||||
use crate::middleware::{find_user, validate_jwt};
|
use crate::middleware::{find_user, validate_jwt};
|
||||||
|
|
||||||
|
use super::validate_path;
|
||||||
|
|
||||||
/// Handle `/fs/delete` requests
|
/// Handle `/fs/delete` requests
|
||||||
pub async fn handle(
|
pub async fn handle(
|
||||||
Extension(db): Extension<Database>,
|
Extension(db): Extension<Database>,
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
use crate::fs::validate_path;
|
|
||||||
use axum::extract::Query;
|
use axum::extract::Query;
|
||||||
use axum::Extension;
|
use axum::Extension;
|
||||||
use axum_auth::AuthBearer;
|
use axum_auth::AuthBearer;
|
||||||
|
@ -10,6 +9,8 @@ use homedisk_types::{config::Config, errors::ServerError};
|
||||||
|
|
||||||
use crate::middleware::{find_user, validate_jwt};
|
use crate::middleware::{find_user, validate_jwt};
|
||||||
|
|
||||||
|
use super::validate_path;
|
||||||
|
|
||||||
/// Handle `/fs/download` requests
|
/// Handle `/fs/download` requests
|
||||||
pub async fn handle(
|
pub async fn handle(
|
||||||
Extension(db): Extension<Database>,
|
Extension(db): Extension<Database>,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{fs, io};
|
use std::{fs, io};
|
||||||
|
|
||||||
use crate::fs::validate_path;
|
|
||||||
use axum::{extract::rejection::JsonRejection, Extension, Json};
|
use axum::{extract::rejection::JsonRejection, Extension, Json};
|
||||||
use axum_auth::AuthBearer;
|
use axum_auth::AuthBearer;
|
||||||
use byte_unit::Byte;
|
use byte_unit::Byte;
|
||||||
|
@ -15,6 +14,8 @@ use homedisk_types::{
|
||||||
|
|
||||||
use crate::middleware::{find_user, validate_json, validate_jwt};
|
use crate::middleware::{find_user, validate_json, validate_jwt};
|
||||||
|
|
||||||
|
use super::validate_path;
|
||||||
|
|
||||||
/// Get directory size on disk (size of all files in directory).
|
/// Get directory size on disk (size of all files in directory).
|
||||||
fn dir_size(path: impl Into<PathBuf>) -> io::Result<u64> {
|
fn dir_size(path: impl Into<PathBuf>) -> io::Result<u64> {
|
||||||
fn dir_size(mut dir: fs::ReadDir) -> io::Result<u64> {
|
fn dir_size(mut dir: fs::ReadDir) -> io::Result<u64> {
|
||||||
|
|
|
@ -12,9 +12,10 @@ use homedisk_types::{
|
||||||
fs::upload::Pagination,
|
fs::upload::Pagination,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::fs::validate_path;
|
|
||||||
use crate::middleware::{find_user, validate_jwt};
|
use crate::middleware::{find_user, validate_jwt};
|
||||||
|
|
||||||
|
use super::validate_path;
|
||||||
|
|
||||||
/// Handle `/fs/upload` requests
|
/// Handle `/fs/upload` requests
|
||||||
pub async fn handle(
|
pub async fn handle(
|
||||||
Extension(db): Extension<Database>,
|
Extension(db): Extension<Database>,
|
||||||
|
|
|
@ -8,7 +8,7 @@ use super::types::Config;
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
/// Parse configuration file
|
/// Parse configuration file
|
||||||
/// ```ignore,rust
|
/// ```no_run
|
||||||
/// use homedisk_types::config::Config;
|
/// use homedisk_types::config::Config;
|
||||||
///
|
///
|
||||||
/// let config = Config::parse().unwrap();
|
/// let config = Config::parse().unwrap();
|
||||||
|
|
|
@ -33,7 +33,7 @@ impl User {
|
||||||
// salting the password
|
// salting the password
|
||||||
let password = format!("{username}${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(
|
let password = hex::encode(CryptographicHash::hash(
|
||||||
Algorithm::SHA512,
|
Algorithm::SHA512,
|
||||||
password.as_bytes(),
|
password.as_bytes(),
|
||||||
|
|
|
@ -40,10 +40,10 @@ impl axum::response::IntoResponse for Error {
|
||||||
let status = match self {
|
let status = match self {
|
||||||
Self::AuthError(ref err) => match err {
|
Self::AuthError(ref err) => match err {
|
||||||
AuthError::UserNotFound => StatusCode::BAD_REQUEST,
|
AuthError::UserNotFound => StatusCode::BAD_REQUEST,
|
||||||
AuthError::UserAlreadyExists => StatusCode::NOT_ACCEPTABLE,
|
AuthError::UserAlreadyExists => StatusCode::BAD_REQUEST,
|
||||||
AuthError::UsernameTooShort => StatusCode::NOT_ACCEPTABLE,
|
AuthError::UsernameTooShort => StatusCode::BAD_REQUEST,
|
||||||
AuthError::UsernameTooLong => StatusCode::NOT_ACCEPTABLE,
|
AuthError::UsernameTooLong => StatusCode::BAD_REQUEST,
|
||||||
AuthError::PasswordTooShort => StatusCode::NOT_ACCEPTABLE,
|
AuthError::PasswordTooShort => StatusCode::BAD_REQUEST,
|
||||||
AuthError::TokenGenerate => StatusCode::INTERNAL_SERVER_ERROR,
|
AuthError::TokenGenerate => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
AuthError::InvalidToken => StatusCode::BAD_REQUEST,
|
AuthError::InvalidToken => StatusCode::BAD_REQUEST,
|
||||||
AuthError::Other(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
AuthError::Other(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
|
Loading…
Reference in a new issue