dedupe version getting code, rename to CONDUWUIT_VERSION_EXTRA

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-05-01 13:35:16 -04:00 committed by June
parent 8ec9372a8e
commit a496cc4705
7 changed files with 26 additions and 41 deletions

View file

@ -10,7 +10,7 @@ use ruma::api::client::{
error::ErrorKind,
};
use crate::{services, Error, Result, Ruma};
use crate::{services, utils::conduwuit_version, Error, Result, Ruma};
/// # `GET /_matrix/client/versions`
///
@ -142,14 +142,9 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
},
};
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
Ok(Json(serde_json::json!({
"server": server_url,
"version": version,
"version": conduwuit_version(),
})))
}
@ -158,13 +153,8 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
/// Conduwuit-specific API to get the server version, results akin to
/// `/_matrix/federation/v1/version`
pub(crate) async fn conduwuit_server_version() -> Result<impl IntoResponse> {
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
Ok(Json(serde_json::json!({
"name": "Conduwuit",
"version": version,
"version": conduwuit_version(),
})))
}

View file

@ -66,15 +66,10 @@ use crate::{
pub(crate) async fn get_server_version_route(
_body: Ruma<get_server_version::v1::Request>,
) -> Result<get_server_version::v1::Response> {
let version = match option_env!("CONDUIT_VERSION_EXTRA") {
Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra),
None => env!("CARGO_PKG_VERSION").to_owned(),
};
Ok(get_server_version::v1::Response {
server: Some(get_server_version::v1::Server {
name: Some("Conduwuit".to_owned()),
version: Some(version),
version: Some(utils::conduwuit_version()),
}),
})
}