refactor(server): clean up some stuff
parent
afe73d5314
commit
bc19158747
|
@ -1,5 +1,3 @@
|
|||
use axum::response::{IntoResponse, Response};
|
||||
use axum::Json;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const DEFAULT_PAGE: u64 = 0;
|
||||
|
|
|
@ -21,7 +21,6 @@ impl fmt::Display for ServerError {
|
|||
ServerError::Axum(err) => write!(fmt, "{}", err),
|
||||
ServerError::Status(status) => write!(fmt, "{}", status),
|
||||
ServerError::Db(err) => write!(fmt, "{}", err),
|
||||
ServerError::Status(status) => write!(fmt, "{}", status),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +39,6 @@ impl IntoResponse for ServerError {
|
|||
StatusCode::NOT_FOUND.into_response()
|
||||
}
|
||||
ServerError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(),
|
||||
ServerError::Status(status) => status.into_response(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,8 @@ mod package;
|
|||
|
||||
pub use manager::RepoGroupManager;
|
||||
|
||||
use axum::body::Body;
|
||||
use crate::db::entities::{package as db_package, repo as db_repo};
|
||||
use axum::body::Body;
|
||||
use axum::extract::{BodyStream, Path, State};
|
||||
use axum::http::Request;
|
||||
use axum::http::StatusCode;
|
||||
|
@ -47,19 +47,16 @@ async fn post_package_archive(
|
|||
let path_clone = path.clone();
|
||||
let repo_clone = repo.clone();
|
||||
let res = tokio::task::spawn_blocking(move || {
|
||||
clone.write().unwrap().add_pkg_from_path(&repo_clone, &path_clone)
|
||||
clone
|
||||
.write()
|
||||
.unwrap()
|
||||
.add_pkg_from_path(&repo_clone, &path_clone)
|
||||
})
|
||||
.await?;
|
||||
|
||||
// Remove the downloaded file if the adding failed
|
||||
if let Err(err) = res {
|
||||
let _ = tokio::fs::remove_file(path).await;
|
||||
|
||||
return Err(err.into());
|
||||
}
|
||||
|
||||
let pkg = res.unwrap();
|
||||
|
||||
match res {
|
||||
// Insert the newly added package into the database
|
||||
Ok(pkg) => {
|
||||
// Query the repo for its ID, or create it if it does not already exist
|
||||
let repo_entity = db_repo::Entity::find()
|
||||
.filter(db_repo::Column::Name.eq(&repo))
|
||||
|
@ -88,6 +85,14 @@ async fn post_package_archive(
|
|||
|
||||
Ok(())
|
||||
}
|
||||
// Remove the uploaded file and return the error
|
||||
Err(err) => {
|
||||
tokio::fs::remove_file(path).await?;
|
||||
|
||||
Err(err.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Serve the package archive files and database archives. If files are requested for an
|
||||
/// architecture that does not have any explicit packages, a repository containing only "any" files
|
||||
|
|
Loading…
Reference in New Issue