From 1663d22b191553067feecc60db651fba5ce0c230 Mon Sep 17 00:00:00 2001 From: silverpill Date: Fri, 6 Jan 2023 16:46:59 +0000 Subject: [PATCH] Add "configuration" object to response of /api/v1/instance endpoint --- CHANGELOG.md | 5 ++++ docs/openapi.yaml | 30 ++++++++++++++++++++++ src/mastodon_api/instance/types.rs | 41 ++++++++++++++++++++++++++++-- src/mastodon_api/instance/views.rs | 1 + 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db745de..71326f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added `/api/v1/accounts/lookup` Mastodon API endpoint. - Implemented activity delivery queue. - Started to keep track of unreachable actors. +- Added `configuration` object to response of `/api/v1/instance` endpoint. ### Changed @@ -18,6 +19,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Limited the number of requests made during the processing of a thread. - Limited the number of media files that can be attached to a post. +### Deprecated + +- Deprecated `post_character_limit` property in `/api/v1/instance` response. + ### Removed - Removed ability to upload non-images using `/api/v1/media` endpoint. diff --git a/docs/openapi.yaml b/docs/openapi.yaml index b7b0ff9..55762c8 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -1394,6 +1394,36 @@ components: domain_count: description: Domains federated with this instance. type: integer + configuration: + description: Configured values and limits for this instance. + type: object + properties: + statuses: + description: Limits related to authoring posts. + type: object + properties: + max_characters: + description: The maximum number of allowed characters per post. + type: integer + example: 5000 + max_media_attachments: + description: The maximum number of media attachments that can be added to a post. + type: integer + example: 15 + media_attachments: + description: Limits realted to uploading attachments. + type: object + properties: + supported_mime_types: + description: Contains MIME types that can be uploaded. + type: array + items: + type: string + example: 'image/png' + image_size_limit: + description: The maximum size of any uploaded image, in bytes. + type: integer + example: 5242880 login_message: description: Login message for signer. type: string diff --git a/src/mastodon_api/instance/types.rs b/src/mastodon_api/instance/types.rs index ac7a7b8..772b116 100644 --- a/src/mastodon_api/instance/types.rs +++ b/src/mastodon_api/instance/types.rs @@ -3,8 +3,15 @@ use serde_json::{to_value, Value}; use crate::config::{BlockchainConfig, Config}; use crate::ethereum::contracts::ContractSet; -use crate::mastodon_api::MASTODON_API_VERSION; -use crate::utils::markdown::markdown_to_html; +use crate::mastodon_api::{ + MASTODON_API_VERSION, + uploads::UPLOAD_MAX_SIZE, +}; +use crate::models::posts::validators::ATTACHMENTS_MAX_NUM; +use crate::utils::{ + files::SUPPORTED_MEDIA_TYPES, + markdown::markdown_to_html, +}; #[derive(Serialize)] struct InstanceStats { @@ -13,6 +20,24 @@ struct InstanceStats { domain_count: i64, } +#[derive(Serialize)] +struct InstanceStatusLimits { + max_characters: usize, + max_media_attachments: usize, +} + +#[derive(Serialize)] +struct InstanceMediaLimits { + supported_mime_types: [&'static str; 4], + image_size_limit: usize, +} + +#[derive(Serialize)] +struct InstanceConfiguration { + statuses: InstanceStatusLimits, + media_attachments: InstanceMediaLimits, +} + #[derive(Serialize)] struct BlockchainFeatures { gate: bool, @@ -28,6 +53,7 @@ struct BlockchainInfo { features: BlockchainFeatures, } +/// https://docs.joinmastodon.org/entities/V1_Instance/ #[derive(Serialize)] pub struct InstanceInfo { uri: String, @@ -38,6 +64,7 @@ pub struct InstanceInfo { version: String, registrations: bool, stats: InstanceStats, + configuration: InstanceConfiguration, login_message: String, post_character_limit: usize, @@ -116,6 +143,16 @@ impl InstanceInfo { status_count: post_count, domain_count: peer_count, }, + configuration: InstanceConfiguration { + statuses: InstanceStatusLimits { + max_characters: config.post_character_limit, + max_media_attachments: ATTACHMENTS_MAX_NUM, + }, + media_attachments: InstanceMediaLimits { + supported_mime_types: SUPPORTED_MEDIA_TYPES, + image_size_limit: UPLOAD_MAX_SIZE, + }, + }, login_message: config.login_message.clone(), post_character_limit: config.post_character_limit, blockchains: blockchains, diff --git a/src/mastodon_api/instance/views.rs b/src/mastodon_api/instance/views.rs index cd2e998..1fe8dae 100644 --- a/src/mastodon_api/instance/views.rs +++ b/src/mastodon_api/instance/views.rs @@ -11,6 +11,7 @@ use crate::models::{ }; use super::types::InstanceInfo; +/// https://docs.joinmastodon.org/methods/instance/#v1 #[get("")] async fn instance_view( config: web::Data,