fix: fixed get_file route
parent
67b4640e56
commit
5d7832c43a
|
@ -44,7 +44,7 @@ pub struct Cli {
|
||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
value_name = "LOG_LEVEL",
|
value_name = "LOG_LEVEL",
|
||||||
default_value = "tower_http=debug,rieterd=debug",
|
default_value = "tower_http=debug,rieterd=debug,sea_orm=debug",
|
||||||
env = "RIETER_LOG"
|
env = "RIETER_LOG"
|
||||||
)]
|
)]
|
||||||
pub log: String,
|
pub log: String,
|
||||||
|
|
|
@ -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> {
|
pub async fn get_or_create_repo(&self, distro: &str, repo: &str) -> crate::Result<i32> {
|
||||||
let mut repos = self.repos.write().await;
|
let mut repos = self.repos.write().await;
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,12 @@ async fn get_file(
|
||||||
Path((distro, repo, arch, file_name)): Path<(String, String, String, String)>,
|
Path((distro, repo, arch, file_name)): Path<(String, String, String, String)>,
|
||||||
req: Request<Body>,
|
req: Request<Body>,
|
||||||
) -> crate::Result<impl IntoResponse> {
|
) -> crate::Result<impl IntoResponse> {
|
||||||
|
if let Some(repo_id) = global.mgr.get_repo(&distro, &repo).await? {
|
||||||
let repo_dir = global
|
let repo_dir = global
|
||||||
.config
|
.config
|
||||||
.data_dir
|
.data_dir
|
||||||
.join("distros")
|
.join("repos")
|
||||||
.join(&distro)
|
.join(repo_id.to_string());
|
||||||
.join(&repo);
|
|
||||||
|
|
||||||
let file_name =
|
let file_name =
|
||||||
if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) {
|
if file_name == format!("{}.db", repo) || file_name == format!("{}.db.tar.gz", repo) {
|
||||||
|
@ -67,7 +67,11 @@ async fn get_file(
|
||||||
file_name
|
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(
|
async fn post_package_archive(
|
||||||
|
@ -84,18 +88,6 @@ async fn post_package_archive(
|
||||||
|
|
||||||
global.mgr.queue_pkg(repo, tmp_path).await;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue