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};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub const DEFAULT_PAGE: u64 = 0;
|
pub const DEFAULT_PAGE: u64 = 0;
|
||||||
|
|
|
@ -21,7 +21,6 @@ impl fmt::Display for ServerError {
|
||||||
ServerError::Axum(err) => write!(fmt, "{}", err),
|
ServerError::Axum(err) => write!(fmt, "{}", err),
|
||||||
ServerError::Status(status) => write!(fmt, "{}", status),
|
ServerError::Status(status) => write!(fmt, "{}", status),
|
||||||
ServerError::Db(err) => write!(fmt, "{}", err),
|
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()
|
StatusCode::NOT_FOUND.into_response()
|
||||||
}
|
}
|
||||||
ServerError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR.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;
|
pub use manager::RepoGroupManager;
|
||||||
|
|
||||||
use axum::body::Body;
|
|
||||||
use crate::db::entities::{package as db_package, repo as db_repo};
|
use crate::db::entities::{package as db_package, repo as db_repo};
|
||||||
|
use axum::body::Body;
|
||||||
use axum::extract::{BodyStream, Path, State};
|
use axum::extract::{BodyStream, Path, State};
|
||||||
use axum::http::Request;
|
use axum::http::Request;
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
|
@ -47,19 +47,16 @@ async fn post_package_archive(
|
||||||
let path_clone = path.clone();
|
let path_clone = path.clone();
|
||||||
let repo_clone = repo.clone();
|
let repo_clone = repo.clone();
|
||||||
let res = tokio::task::spawn_blocking(move || {
|
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?;
|
.await?;
|
||||||
|
|
||||||
// Remove the downloaded file if the adding failed
|
match res {
|
||||||
if let Err(err) = res {
|
// Insert the newly added package into the database
|
||||||
let _ = tokio::fs::remove_file(path).await;
|
Ok(pkg) => {
|
||||||
|
|
||||||
return Err(err.into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let pkg = res.unwrap();
|
|
||||||
|
|
||||||
// Query the repo for its ID, or create it if it does not already exist
|
// Query the repo for its ID, or create it if it does not already exist
|
||||||
let repo_entity = db_repo::Entity::find()
|
let repo_entity = db_repo::Entity::find()
|
||||||
.filter(db_repo::Column::Name.eq(&repo))
|
.filter(db_repo::Column::Name.eq(&repo))
|
||||||
|
@ -87,6 +84,14 @@ async fn post_package_archive(
|
||||||
model.insert(&global.db).await?;
|
model.insert(&global.db).await?;
|
||||||
|
|
||||||
Ok(())
|
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
|
/// Serve the package archive files and database archives. If files are requested for an
|
||||||
|
|
Loading…
Reference in New Issue