From 9591be4df02ee01c9dd5ebf6875fc9cb1de2b9bd Mon Sep 17 00:00:00 2001 From: silverpill Date: Tue, 8 Feb 2022 01:12:36 +0000 Subject: [PATCH] Use Pleroma-compliant instance version in /api/v1/instance https://codeberg.org/silverpill/mitra/issues/4 --- Cargo.lock | 2 +- Cargo.toml | 2 +- docs/openapi.yaml | 3 ++- src/mastodon_api/instance/types.rs | 11 ++++++++++- src/mastodon_api/mod.rs | 2 ++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index baab7c5..21d349b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1686,7 +1686,7 @@ dependencies = [ [[package]] name = "mitra" -version = "0.2.0" +version = "0.4.0" dependencies = [ "actix-cors", "actix-files", diff --git a/Cargo.toml b/Cargo.toml index da41b9b..d2258d2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mitra" -version = "0.2.0" +version = "0.4.0" description = "Mitra backend" license = "AGPL-3.0" diff --git a/docs/openapi.yaml b/docs/openapi.yaml index 6ed23b0..1a81b2f 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -571,8 +571,9 @@ components: description: Admin-defined description of the site. type: string version: - description: The version of Mitra server. + description: Mastodon API compatibility version and the version of Mitra server. type: string + example: '3.0.0 (compatible; Mitra 0.4.0)' registrations: description: Whether registrations are enabled. type: boolean diff --git a/src/mastodon_api/instance/types.rs b/src/mastodon_api/instance/types.rs index f35e424..39c503a 100644 --- a/src/mastodon_api/instance/types.rs +++ b/src/mastodon_api/instance/types.rs @@ -2,6 +2,7 @@ use serde::Serialize; use crate::config::Config; use crate::ethereum::contracts::ADAPTER; +use crate::mastodon_api::MASTODON_API_VERSION; #[derive(Serialize)] pub struct InstanceInfo { @@ -19,6 +20,14 @@ pub struct InstanceInfo { ipfs_gateway_url: Option, } +fn get_full_api_version(version: &str) -> String { + format!( + "{0} (compatible; Mitra {1})", + MASTODON_API_VERSION, + version, + ) +} + impl From<&Config> for InstanceInfo { fn from(config: &Config) -> Self { Self { @@ -26,7 +35,7 @@ impl From<&Config> for InstanceInfo { title: config.instance_title.clone(), short_description: config.instance_short_description.clone(), description: config.instance_description.clone(), - version: config.version.clone(), + version: get_full_api_version(&config.version), registrations: config.registrations_open, login_message: config.login_message.clone(), blockchain_explorer_url: config.blockchain.as_ref() diff --git a/src/mastodon_api/mod.rs b/src/mastodon_api/mod.rs index 8f1dfc6..9ef8bbf 100644 --- a/src/mastodon_api/mod.rs +++ b/src/mastodon_api/mod.rs @@ -8,3 +8,5 @@ pub mod oauth; pub mod search; pub mod statuses; pub mod timelines; + +pub const MASTODON_API_VERSION: &str = "3.0.0";