use axum::extract::State;
use axum::http::HeaderMap;
use axum::Json;
use serde::Serialize;
use crate::auth::require_bearer;
use crate::error::AppError;
use crate::state::AppState;
const BUILD_PROFILE: &str = if cfg!(debug_assertions) {
"debug"
} else {
"release"
};
#[derive(Debug, Serialize)]
pub struct VersionResponse {
pub server: ServerInfo,
pub api: ApiInfo,
}
#[derive(Debug, Serialize)]
pub struct ServerInfo {
pub version: &'static str,
#[serde(rename = "gitSha", skip_serializing_if = "Option::is_none")]
pub git_sha: Option<&'static str>,
#[serde(rename = "buildProfile")]
pub build_profile: &'static str,
}
#[derive(Debug, Serialize)]
pub struct ApiInfo {
pub version: &'static str,
}
pub async fn get_version(
State(state): State<AppState>,
headers: HeaderMap,
) -> Result<Json<VersionResponse>, AppError> {
require_bearer(&headers, &state.api_token)?;
Ok(Json(VersionResponse {
server: ServerInfo {
version: env!("CARGO_PKG_VERSION"),
git_sha: option_env!("CELLOS_GIT_SHA"),
build_profile: BUILD_PROFILE,
},
api: ApiInfo { version: "v1" },
}))
}