Add "configuration" object to response of /api/v1/instance endpoint

This commit is contained in:
silverpill 2023-01-06 16:46:59 +00:00
parent fe395480eb
commit 1663d22b19
4 changed files with 75 additions and 2 deletions

View file

@ -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.

View file

@ -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

View file

@ -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,

View file

@ -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<Config>,