add app name and version to source archive filename

This commit is contained in:
Sebastian Hugentobler 2025-07-01 14:44:11 +02:00
parent dddc4b4081
commit 525e278a4e
Signed by: shu
SSH key fingerprint: SHA256:ppcx6MlixdNZd5EUM1nkHOKoyQYoJwzuQKXM6J/t66M

View file

@ -5,8 +5,15 @@ use axum::{
use super::TAG; use super::TAG;
// Source archive, generated at build time.
const SOURCE_ARCHIVE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/archive.zip")); 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. /// Serve the source code archive as a downloadable zip file.
#[utoipa::path( #[utoipa::path(
get, get,
@ -24,13 +31,13 @@ const SOURCE_ARCHIVE: &[u8] = include_bytes!(concat!(env!("OUT_DIR"), "/archive.
) )
)] )]
pub async fn route() -> Result<Response, StatusCode> { pub async fn route() -> Result<Response, StatusCode> {
let filename = format!("{}-{}-source.zip", APP_NAME, APP_VERSION);
let content_length = SOURCE_ARCHIVE.len().to_string(); let content_length = SOURCE_ARCHIVE.len().to_string();
let content_disposition = format!("attachment; filename=\"{}\"", filename);
let headers = [ let headers = [
(header::CONTENT_TYPE, "application/zip"), (header::CONTENT_TYPE, "application/zip"),
( (header::CONTENT_DISPOSITION, content_disposition.as_str()),
header::CONTENT_DISPOSITION,
"attachment; filename=\"source.zip\"",
),
(header::CONTENT_LENGTH, content_length.as_str()), (header::CONTENT_LENGTH, content_length.as_str()),
]; ];