diff --git a/src/api/code.rs b/src/api/code.rs index 2b01294..649ac17 100644 --- a/src/api/code.rs +++ b/src/api/code.rs @@ -5,8 +5,15 @@ use axum::{ use super::TAG; +// Source archive, generated at build time. const SOURCE_ARCHIVE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/archive.zip")); +// App name from Cargo.toml +const APP_NAME: &str = env!("CARGO_PKG_NAME"); + +// Version from Cargo.toml +const APP_VERSION: &str = env!("CARGO_PKG_VERSION"); + /// Serve the source code archive as a downloadable zip file. #[utoipa::path( get, @@ -24,13 +31,13 @@ const SOURCE_ARCHIVE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/archive. ) )] pub async fn route() -> Result { + let filename = format!("{}-{}-source.zip", APP_NAME, APP_VERSION); let content_length = SOURCE_ARCHIVE.len().to_string(); + let content_disposition = format!("attachment; filename=\"{}\"", filename); + let headers = [ (header::CONTENT_TYPE, "application/zip"), - ( - header::CONTENT_DISPOSITION, - "attachment; filename=\"source.zip\"", - ), + (header::CONTENT_DISPOSITION, content_disposition.as_str()), (header::CONTENT_LENGTH, content_length.as_str()), ];