fix: fixed get_file route

concurrent-repos
Jef Roosens 2024-06-15 20:24:58 +02:00
parent 67b4640e56
commit 5d7832c43a
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
3 changed files with 35 additions and 30 deletions

View File

@ -44,7 +44,7 @@ pub struct Cli {
#[arg(
long,
value_name = "LOG_LEVEL",
default_value = "tower_http=debug,rieterd=debug",
default_value = "tower_http=debug,rieterd=debug,sea_orm=debug",
env = "RIETER_LOG"
)]
pub log: String,

View File

@ -268,6 +268,19 @@ impl RepoMgr {
});
}
pub async fn get_repo(&self, distro: &str, repo: &str) -> crate::Result<Option<i32>> {
Ok(db::Repo::find()
.find_also_related(db::Distro)
.filter(
Condition::all()
.add(db::repo::Column::Name.eq(repo))
.add(db::distro::Column::Name.eq(distro)),
)
.one(&self.conn)
.await
.map(|res| res.map(|(repo, _)| repo.id))?)
}
pub async fn get_or_create_repo(&self, distro: &str, repo: &str) -> crate::Result<i32> {
let mut repos = self.repos.write().await;

View File

@ -49,25 +49,29 @@ async fn get_file(
Path((distro, repo, arch, file_name)): Path<(String, String, String, String)>,
req: Request<Body>,
) -> crate::Result<impl IntoResponse> {
let repo_dir = global
.config
.data_dir
.join("distros")
.join(&distro)
.join(&repo);
if let Some(repo_id) = global.mgr.get_repo(&distro, &repo).await? {
let repo_dir = global
.config
.data_dir
.join("repos")
.join(repo_id.to_string());
let file_name =
if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) {
format!("{}.db.tar.gz", arch)
} else if file_name == format!("{}.files", repo)
|| file_name == format!("{}.files.tar.gz", repo)
{
format!("{}.files.tar.gz", arch)
} else {
file_name
};
let file_name =
if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) {
format!("{}.db.tar.gz", arch)
} else if file_name == format!("{}.files", repo)
|| file_name == format!("{}.files.tar.gz", repo)
{
format!("{}.files.tar.gz", arch)
} else {
file_name
};
Ok(ServeFile::new(repo_dir.join(file_name)).oneshot(req).await)
let path = repo_dir.join(file_name);
Ok(ServeFile::new(path).oneshot(req).await)
} else {
Err(StatusCode::NOT_FOUND.into())
}
}
async fn post_package_archive(
@ -84,18 +88,6 @@ async fn post_package_archive(
global.mgr.queue_pkg(repo, tmp_path).await;
//let (name, version, arch) = mgr.add_pkg_from_path(&mut body, &repo).await?;
//
//tracing::info!(
// "Added '{}-{}' to repository '{}' ({})",
// name,
// version,
// repo,
// arch
//);
//tokio::spawn(async move { mgr.sync_repo(&repo).await });
Ok(())
}