From 47889410eba59131e9bc6933a64ec6b0f52ed52f Mon Sep 17 00:00:00 2001 From: strawberry Date: Fri, 29 Mar 2024 18:21:33 -0400 Subject: [PATCH] use CONDUIT_VERSION_EXTRA in endpoints Signed-off-by: strawberry --- src/api/client_server/unversioned.rs | 14 ++++++++++++-- src/api/server_server.rs | 7 ++++++- src/service/globals/client.rs | 7 ++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/api/client_server/unversioned.rs b/src/api/client_server/unversioned.rs index 652fb8ca..624c9774 100644 --- a/src/api/client_server/unversioned.rs +++ b/src/api/client_server/unversioned.rs @@ -74,9 +74,14 @@ pub async fn syncv3_client_server_json() -> Result { }, }; + 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": format!("Conduwuit {}", env!("CARGO_PKG_VERSION")) + "version": version, }))) } @@ -85,8 +90,13 @@ pub async fn syncv3_client_server_json() -> Result { /// Conduwuit-specific API to get the server version, results akin to /// `/_matrix/federation/v1/version` pub async fn conduwuit_server_version() -> Result { + 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": env!("CARGO_PKG_VERSION"), + "version": version, }))) } diff --git a/src/api/server_server.rs b/src/api/server_server.rs index 613e077e..84325a66 100644 --- a/src/api/server_server.rs +++ b/src/api/server_server.rs @@ -623,10 +623,15 @@ pub async fn get_server_version_route( return Err(Error::bad_config("Federation is disabled.")); } + 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(env!("CARGO_PKG_VERSION").to_owned()), + version: Some(version), }), }) } diff --git a/src/service/globals/client.rs b/src/service/globals/client.rs index c3c098d8..a6e5d4cb 100644 --- a/src/service/globals/client.rs +++ b/src/service/globals/client.rs @@ -83,13 +83,18 @@ impl Client { } fn base(config: &Config) -> Result { + let version = match option_env!("CONDUIT_VERSION_EXTRA") { + Some(extra) => format!("{} ({})", env!("CARGO_PKG_VERSION"), extra), + None => env!("CARGO_PKG_VERSION").to_owned(), + }; + let builder = reqwest::Client::builder() .hickory_dns(true) .timeout(Duration::from_secs(config.request_timeout)) .connect_timeout(Duration::from_secs(config.request_conn_timeout)) .pool_max_idle_per_host(config.request_idle_per_host.into()) .pool_idle_timeout(Duration::from_secs(config.request_idle_timeout)) - .user_agent("Conduwuit".to_owned() + "/" + env!("CARGO_PKG_VERSION")) + .user_agent("Conduwuit".to_owned() + "/" + &version) .redirect(redirect::Policy::limited(6)); if let Some(proxy) = config.proxy.to_proxy()? {