add app name and version to source archive filename
This commit is contained in:
parent
dddc4b4081
commit
525e278a4e
1 changed files with 11 additions and 4 deletions
|
@ -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()),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue