diff --git a/server/src/db/entities/distro.rs b/server/src/db/entities/distro.rs index 835cba5..1d96872 100644 --- a/server/src/db/entities/distro.rs +++ b/server/src/db/entities/distro.rs @@ -7,7 +7,6 @@ use serde::{Deserialize, Serialize}; #[sea_orm(table_name = "distro")] pub struct Model { #[sea_orm(primary_key)] - #[serde(skip_deserializing)] pub id: i32, #[sea_orm(unique)] pub slug: String, diff --git a/server/src/db/query/distro.rs b/server/src/db/query/distro.rs index 1913f99..2d4d1c6 100644 --- a/server/src/db/query/distro.rs +++ b/server/src/db/query/distro.rs @@ -43,10 +43,4 @@ impl DistroQuery { Distro::insert(model).exec(&self.conn).await } - - pub async fn insert_model(&self, model: distro::Model) -> Result { - let mut model: distro::ActiveModel = model.into(); - model.id = NotSet; - model.insert(&self.conn).await - } } diff --git a/server/src/error.rs b/server/src/error.rs index 723e944..4fbb7c4 100644 --- a/server/src/error.rs +++ b/server/src/error.rs @@ -35,12 +35,10 @@ impl IntoResponse for ServerError { ServerError::IO(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), ServerError::Axum(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), ServerError::Status(status) => status.into_response(), - ServerError::Db(err) => match err { - sea_orm::DbErr::RecordNotFound(_) => StatusCode::NOT_FOUND, - sea_orm::DbErr::Query(_) => StatusCode::BAD_REQUEST, - _ => StatusCode::INTERNAL_SERVER_ERROR, + ServerError::Db(sea_orm::DbErr::RecordNotFound(_)) => { + StatusCode::NOT_FOUND.into_response() } - .into_response(), + ServerError::Db(_) => StatusCode::INTERNAL_SERVER_ERROR.into_response(), } } } diff --git a/server/src/repo/manager.rs b/server/src/repo/manager.rs index 1c5556e..c288f30 100644 --- a/server/src/repo/manager.rs +++ b/server/src/repo/manager.rs @@ -5,6 +5,8 @@ use std::fs; use std::io; use std::path::{Path, PathBuf}; +pub const ANY_ARCH: &str = "any"; + /// Overarching abstraction that orchestrates updating the repositories stored on the server pub struct RepoGroupManager { repo_dir: PathBuf, @@ -46,9 +48,9 @@ impl RepoGroupManager { // All architectures should also include the "any" architecture, except for the "any" // architecture itself. - let repo_any_dir = self.repo_dir.join(repo).join(super::ANY_ARCH); + let repo_any_dir = self.repo_dir.join(repo).join(ANY_ARCH); - let any_entries_iter = if arch != super::ANY_ARCH && repo_any_dir.try_exists()? { + let any_entries_iter = if arch != ANY_ARCH && repo_any_dir.try_exists()? { Some(repo_any_dir.read_dir()?) } else { None @@ -157,7 +159,7 @@ impl RepoGroupManager { pkg.write_files(&mut files_file)?; // If a package of type "any" is added, we need to update every existing database - if pkg.info.arch == super::ANY_ARCH { + if pkg.info.arch == ANY_ARCH { self.sync_all(repo)?; } else { self.sync(repo, &pkg.info.arch)?; @@ -191,7 +193,7 @@ impl RepoGroupManager { fs::remove_dir_all(self.pkg_dir.join(sub_path))?; // Removing the "any" architecture updates all other repositories - if arch == super::ANY_ARCH { + if arch == ANY_ARCH { self.sync_all(repo)?; } @@ -248,7 +250,7 @@ impl RepoGroupManager { })?; if sync { - if arch == super::ANY_ARCH { + if arch == ANY_ARCH { self.sync_all(repo)?; } else { self.sync(repo, arch)?; @@ -286,7 +288,7 @@ impl RepoGroupManager { fs::remove_dir_all(self.repo_dir.join(repo).join(arch).join(metadata_dir_name))?; if sync { - if arch == super::ANY_ARCH { + if arch == ANY_ARCH { self.sync_all(&repo.to_string_lossy())?; } else { self.sync(&repo.to_string_lossy(), arch)?; diff --git a/server/src/repo/mod.rs b/server/src/repo/mod.rs index 958420e..44f0e10 100644 --- a/server/src/repo/mod.rs +++ b/server/src/repo/mod.rs @@ -2,6 +2,3 @@ pub mod manager; pub mod package; pub use manager::RepoGroupManager; - -pub const DB_FILE_EXTS: [&str; 4] = [".db", ".files", ".db.tar.gz", ".files.tar.gz"]; -pub const ANY_ARCH: &str = "any"; diff --git a/server/src/web/api/distros.rs b/server/src/web/api/distros.rs index d846398..feb3679 100644 --- a/server/src/web/api/distros.rs +++ b/server/src/web/api/distros.rs @@ -9,7 +9,7 @@ use crate::db; pub fn router() -> Router { Router::new() - .route("/", get(get_distros).post(post_distro)) + .route("/", get(get_distros)) .route("/:id", get(get_single_distro)) } @@ -41,10 +41,3 @@ async fn get_single_distro( Ok(Json(repo)) } - -async fn post_distro( - State(global): State, - Json(model): Json, -) -> crate::Result> { - Ok(Json(global.db.distro.insert_model(model).await?)) -} diff --git a/server/src/web/repo.rs b/server/src/web/repo.rs index 9466af5..f8c3d65 100644 --- a/server/src/web/repo.rs +++ b/server/src/web/repo.rs @@ -16,6 +16,8 @@ use tower_http::services::{ServeDir, ServeFile}; use tower_http::validate_request::ValidateRequestHeaderLayer; use uuid::Uuid; +const DB_FILE_EXTS: [&str; 4] = [".db", ".files", ".db.tar.gz", ".files.tar.gz"]; + pub fn router(api_key: &str) -> Router { Router::new() .route( @@ -49,10 +51,7 @@ async fn get_file( let repo_dir = global.config.repo_dir.join(&repo).join(&arch); let repo_exists = tokio::fs::try_exists(&repo_dir).await?; - let res = if crate::repo::DB_FILE_EXTS - .iter() - .any(|ext| file_name.ends_with(ext)) - { + let res = if DB_FILE_EXTS.iter().any(|ext| file_name.ends_with(ext)) { // Append tar extension to ensure we find the file if !file_name.ends_with(".tar.gz") { file_name.push_str(".tar.gz"); @@ -65,7 +64,7 @@ async fn get_file( .config .repo_dir .join(repo) - .join(crate::repo::ANY_ARCH) + .join(crate::repo::manager::ANY_ARCH) .join(file_name); ServeFile::new(path).oneshot(req).await @@ -75,7 +74,7 @@ async fn get_file( .config .pkg_dir .join(repo) - .join(crate::repo::ANY_ARCH) + .join(crate::repo::manager::ANY_ARCH) .join(file_name); if repo_exists {