fix(server) `fs/download` handle panic
This commit is contained in:
parent
c745b9db96
commit
cca7dd3efd
|
@ -3,6 +3,7 @@ use std::fs;
|
||||||
use axum::{extract::Query, Extension};
|
use axum::{extract::Query, Extension};
|
||||||
use axum_auth::AuthBearer;
|
use axum_auth::AuthBearer;
|
||||||
use homedisk_database::Database;
|
use homedisk_database::Database;
|
||||||
|
use homedisk_types::errors::FsError;
|
||||||
use homedisk_types::fs::upload::Pagination;
|
use homedisk_types::fs::upload::Pagination;
|
||||||
use homedisk_types::{config::Config, errors::ServerError};
|
use homedisk_types::{config::Config, errors::ServerError};
|
||||||
|
|
||||||
|
@ -33,7 +34,8 @@ pub async fn handle(
|
||||||
);
|
);
|
||||||
|
|
||||||
// read file content
|
// read file content
|
||||||
let content = fs::read(path).unwrap();
|
let content =
|
||||||
|
fs::read(path).map_err(|err| ServerError::FsError(FsError::ReadFile(err.to_string())))?;
|
||||||
|
|
||||||
// send file content in Response
|
// send file content in Response
|
||||||
Ok(content)
|
Ok(content)
|
||||||
|
|
|
@ -23,6 +23,8 @@ pub enum Error {
|
||||||
Base64(String),
|
Base64(String),
|
||||||
#[error("failed to read directory: {0}")]
|
#[error("failed to read directory: {0}")]
|
||||||
ReadDirectory(String),
|
ReadDirectory(String),
|
||||||
|
#[error("failed to read file content: {0}")]
|
||||||
|
ReadFile(String),
|
||||||
#[error("other error - {0}")]
|
#[error("other error - {0}")]
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue