diff --git a/CHANGELOG.md b/CHANGELOG.md index 10cd79c..98c2cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added `/api/v1/custom_emojis` endpoint. - Added `limits` parameter group to configuration. - Made file size limit adjustable with `limits.media.file_size_limit` configuration option. +- Added `limits.posts.character_limit` configuration parameter (replaces `post_character_limit`). ### Changed @@ -24,6 +25,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Use "warn" log level for delivery errors. - Don't allow read-only users to manage subscriptions. +### Deprecated + +- Deprecated `post_character_limit` configuration option. + ### Fixed - Change max body size in nginx example config to match app limit. diff --git a/contrib/mitra_config.yaml b/contrib/mitra_config.yaml index 0a5c8be..bf10513 100644 --- a/contrib/mitra_config.yaml +++ b/contrib/mitra_config.yaml @@ -25,8 +25,6 @@ registration: # EIP-4361 login message #login_message: 'Do not sign this message on other sites!' -#post_character_limit: 2000 - # Proxy for outgoing requests #proxy_url: 'socks5h://127.0.0.1:9050' @@ -34,6 +32,8 @@ registration: #limits: # media: # file_size_limit: 20M +# posts: +# character_limit: 2000 # List of blocked domains #blocked_instances: [] diff --git a/src/config/limits.rs b/src/config/limits.rs index 64e60d6..df3f2db 100644 --- a/src/config/limits.rs +++ b/src/config/limits.rs @@ -59,10 +59,28 @@ impl Default for MediaLimits { } } +const fn default_post_character_limit() -> usize { 2000 } + +#[derive(Clone, Deserialize)] +pub struct PostLimits { + #[serde(default = "default_post_character_limit")] + pub character_limit: usize, +} + +impl Default for PostLimits { + fn default() -> Self { + Self { + character_limit: default_post_character_limit(), + } + } +} + #[derive(Clone, Default, Deserialize)] pub struct Limits { #[serde(default)] pub media: MediaLimits, + #[serde(default)] + pub posts: PostLimits, } #[cfg(test)] diff --git a/src/config/loader.rs b/src/config/loader.rs index c5dd859..535c7b6 100644 --- a/src/config/loader.rs +++ b/src/config/loader.rs @@ -113,7 +113,7 @@ pub fn parse_config() -> (Config, Vec<&'static str>) { if let Some(registrations_open) = config.registrations_open { // Change type if 'registrations_open' parameter is used - warnings.push("'registrations_open' setting is deprecated, use 'registration' instead"); + warnings.push("'registrations_open' setting is deprecated, use 'registration.type' instead"); if registrations_open { config.registration.registration_type = RegistrationType::Open; } else { @@ -121,6 +121,11 @@ pub fn parse_config() -> (Config, Vec<&'static str>) { }; }; + if let Some(post_character_limit) = config.post_character_limit { + warnings.push("'post_character_limit' setting is deprecated, use 'limits.posts.character_limit' instead"); + config.limits.posts.character_limit = post_character_limit; + }; + // Insert instance RSA key config.instance_rsa_key = Some(read_instance_rsa_key(&config.storage_dir)); diff --git a/src/config/main.rs b/src/config/main.rs index 0dabdeb..ef92b0b 100644 --- a/src/config/main.rs +++ b/src/config/main.rs @@ -56,8 +56,6 @@ fn default_log_level() -> LogLevel { LogLevel::Info } fn default_login_message() -> String { "Do not sign this message on other sites!".to_string() } -fn default_post_character_limit() -> usize { 2000 } - #[derive(Clone, Deserialize)] pub struct Config { // Properties auto-populated from the environment @@ -99,8 +97,7 @@ pub struct Config { #[serde(default = "default_login_message")] pub login_message: String, - #[serde(default = "default_post_character_limit")] - pub post_character_limit: usize, + pub(super) post_character_limit: Option, // deprecated proxy_url: Option, diff --git a/src/mastodon_api/instance/types.rs b/src/mastodon_api/instance/types.rs index e8ba909..b86c0f1 100644 --- a/src/mastodon_api/instance/types.rs +++ b/src/mastodon_api/instance/types.rs @@ -74,7 +74,7 @@ pub struct InstanceInfo { configuration: InstanceConfiguration, login_message: String, - post_character_limit: usize, + post_character_limit: usize, // deprecated blockchains: Vec, ipfs_gateway_url: Option, } @@ -158,7 +158,7 @@ impl InstanceInfo { }, configuration: InstanceConfiguration { statuses: InstanceStatusLimits { - max_characters: config.post_character_limit, + max_characters: config.limits.posts.character_limit, max_media_attachments: ATTACHMENTS_MAX_NUM, }, media_attachments: InstanceMediaLimits { @@ -168,7 +168,7 @@ impl InstanceInfo { }, }, login_message: config.login_message.clone(), - post_character_limit: config.post_character_limit, + post_character_limit: config.limits.posts.character_limit, blockchains: blockchains, ipfs_gateway_url: config.ipfs_gateway_url.clone(), }