Use Pleroma-compliant instance version in /api/v1/instance

https://codeberg.org/silverpill/mitra/issues/4
This commit is contained in:
silverpill 2022-02-08 01:12:36 +00:00
parent d9f0095787
commit 9591be4df0
5 changed files with 16 additions and 4 deletions

2
Cargo.lock generated
View file

@ -1686,7 +1686,7 @@ dependencies = [
[[package]] [[package]]
name = "mitra" name = "mitra"
version = "0.2.0" version = "0.4.0"
dependencies = [ dependencies = [
"actix-cors", "actix-cors",
"actix-files", "actix-files",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "mitra" name = "mitra"
version = "0.2.0" version = "0.4.0"
description = "Mitra backend" description = "Mitra backend"
license = "AGPL-3.0" license = "AGPL-3.0"

View file

@ -571,8 +571,9 @@ components:
description: Admin-defined description of the site. description: Admin-defined description of the site.
type: string type: string
version: version:
description: The version of Mitra server. description: Mastodon API compatibility version and the version of Mitra server.
type: string type: string
example: '3.0.0 (compatible; Mitra 0.4.0)'
registrations: registrations:
description: Whether registrations are enabled. description: Whether registrations are enabled.
type: boolean type: boolean

View file

@ -2,6 +2,7 @@ use serde::Serialize;
use crate::config::Config; use crate::config::Config;
use crate::ethereum::contracts::ADAPTER; use crate::ethereum::contracts::ADAPTER;
use crate::mastodon_api::MASTODON_API_VERSION;
#[derive(Serialize)] #[derive(Serialize)]
pub struct InstanceInfo { pub struct InstanceInfo {
@ -19,6 +20,14 @@ pub struct InstanceInfo {
ipfs_gateway_url: Option<String>, ipfs_gateway_url: Option<String>,
} }
fn get_full_api_version(version: &str) -> String {
format!(
"{0} (compatible; Mitra {1})",
MASTODON_API_VERSION,
version,
)
}
impl From<&Config> for InstanceInfo { impl From<&Config> for InstanceInfo {
fn from(config: &Config) -> Self { fn from(config: &Config) -> Self {
Self { Self {
@ -26,7 +35,7 @@ impl From<&Config> for InstanceInfo {
title: config.instance_title.clone(), title: config.instance_title.clone(),
short_description: config.instance_short_description.clone(), short_description: config.instance_short_description.clone(),
description: config.instance_description.clone(), description: config.instance_description.clone(),
version: config.version.clone(), version: get_full_api_version(&config.version),
registrations: config.registrations_open, registrations: config.registrations_open,
login_message: config.login_message.clone(), login_message: config.login_message.clone(),
blockchain_explorer_url: config.blockchain.as_ref() blockchain_explorer_url: config.blockchain.as_ref()

View file

@ -8,3 +8,5 @@ pub mod oauth;
pub mod search; pub mod search;
pub mod statuses; pub mod statuses;
pub mod timelines; pub mod timelines;
pub const MASTODON_API_VERSION: &str = "3.0.0";