mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 13:20:42 +00:00
- Implemented `DepotRepo` for repository access, including methods for catalog path, file path, and manifest retrieval. - Introduced foundational HTTP routes for catalog, manifest, file, and package info retrieval. - Added integration tests to validate repository setup and basic server functionality. - Modularized HTTP handlers for better maintainability and extended them with new implementations like `info` and `manifest` handling. - Refactored `main` function to simplify initialization and leverage reusable `run` logic in a new `lib.rs`. - Updated `Cargo.toml` and `Cargo.lock` to include new dependencies: `walkdir` and updated testing utilities.
26 lines
800 B
Rust
26 lines
800 B
Rust
use axum::{
|
|
extract::{Path, State, Request},
|
|
response::{IntoResponse, Response},
|
|
};
|
|
use std::sync::Arc;
|
|
use tower_http::services::ServeFile;
|
|
use tower::ServiceExt;
|
|
use crate::repo::DepotRepo;
|
|
use crate::errors::DepotError;
|
|
|
|
pub async fn get_file(
|
|
State(repo): State<Arc<DepotRepo>>,
|
|
Path((publisher, _algo, digest)): Path<(String, String, String)>,
|
|
req: Request,
|
|
) -> Result<Response, DepotError> {
|
|
let path = repo.get_file_path(&publisher, &digest)
|
|
.ok_or_else(|| DepotError::Repo(libips::repository::RepositoryError::NotFound(digest.clone())))?;
|
|
|
|
let service = ServeFile::new(path);
|
|
let result = service.oneshot(req).await;
|
|
|
|
match result {
|
|
Ok(res) => Ok(res.into_response()),
|
|
Err(e) => Err(DepotError::Server(e.to_string())),
|
|
}
|
|
}
|