use std::sync::Arc; use axum::{ body::{BoxBody, StreamBody}, extract::Path, http::StatusCode, Extension, }; use semver::Version; use tokio::fs::File; use tokio_util::io::ReaderStream; use crate::State; pub async fn download( Path((crate_name, version)): Path<(String, Version)>, Extension(state): Extension>, ) -> Result { let mut path = state.crate_dir.clone(); path.push(&crate_name); path.push(version.to_string()); path.push("crate.crate"); let file = match File::open(path).await { Ok(v) => v, Err(_) => return Err(StatusCode::NOT_FOUND), }; Ok(BoxBody::new(StreamBody::new(ReaderStream::new(file)))) }