Add limits.posts.character_limit configuration parameter

This commit is contained in:
silverpill 2023-02-04 21:47:13 +00:00
parent 151b068d97
commit b91e6e77b5
6 changed files with 35 additions and 10 deletions

View file

@ -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 `/api/v1/custom_emojis` endpoint.
- Added `limits` parameter group to configuration. - Added `limits` parameter group to configuration.
- Made file size limit adjustable with `limits.media.file_size_limit` configuration option. - 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 ### 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. - Use "warn" log level for delivery errors.
- Don't allow read-only users to manage subscriptions. - Don't allow read-only users to manage subscriptions.
### Deprecated
- Deprecated `post_character_limit` configuration option.
### Fixed ### Fixed
- Change max body size in nginx example config to match app limit. - Change max body size in nginx example config to match app limit.

View file

@ -25,8 +25,6 @@ registration:
# EIP-4361 login message # EIP-4361 login message
#login_message: 'Do not sign this message on other sites!' #login_message: 'Do not sign this message on other sites!'
#post_character_limit: 2000
# Proxy for outgoing requests # Proxy for outgoing requests
#proxy_url: 'socks5h://127.0.0.1:9050' #proxy_url: 'socks5h://127.0.0.1:9050'
@ -34,6 +32,8 @@ registration:
#limits: #limits:
# media: # media:
# file_size_limit: 20M # file_size_limit: 20M
# posts:
# character_limit: 2000
# List of blocked domains # List of blocked domains
#blocked_instances: [] #blocked_instances: []

View file

@ -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)] #[derive(Clone, Default, Deserialize)]
pub struct Limits { pub struct Limits {
#[serde(default)] #[serde(default)]
pub media: MediaLimits, pub media: MediaLimits,
#[serde(default)]
pub posts: PostLimits,
} }
#[cfg(test)] #[cfg(test)]

View file

@ -113,7 +113,7 @@ pub fn parse_config() -> (Config, Vec<&'static str>) {
if let Some(registrations_open) = config.registrations_open { if let Some(registrations_open) = config.registrations_open {
// Change type if 'registrations_open' parameter is used // 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 { if registrations_open {
config.registration.registration_type = RegistrationType::Open; config.registration.registration_type = RegistrationType::Open;
} else { } 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 // Insert instance RSA key
config.instance_rsa_key = Some(read_instance_rsa_key(&config.storage_dir)); config.instance_rsa_key = Some(read_instance_rsa_key(&config.storage_dir));

View file

@ -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_login_message() -> String { "Do not sign this message on other sites!".to_string() }
fn default_post_character_limit() -> usize { 2000 }
#[derive(Clone, Deserialize)] #[derive(Clone, Deserialize)]
pub struct Config { pub struct Config {
// Properties auto-populated from the environment // Properties auto-populated from the environment
@ -99,8 +97,7 @@ pub struct Config {
#[serde(default = "default_login_message")] #[serde(default = "default_login_message")]
pub login_message: String, pub login_message: String,
#[serde(default = "default_post_character_limit")] pub(super) post_character_limit: Option<usize>, // deprecated
pub post_character_limit: usize,
proxy_url: Option<String>, proxy_url: Option<String>,

View file

@ -74,7 +74,7 @@ pub struct InstanceInfo {
configuration: InstanceConfiguration, configuration: InstanceConfiguration,
login_message: String, login_message: String,
post_character_limit: usize, post_character_limit: usize, // deprecated
blockchains: Vec<BlockchainInfo>, blockchains: Vec<BlockchainInfo>,
ipfs_gateway_url: Option<String>, ipfs_gateway_url: Option<String>,
} }
@ -158,7 +158,7 @@ impl InstanceInfo {
}, },
configuration: InstanceConfiguration { configuration: InstanceConfiguration {
statuses: InstanceStatusLimits { statuses: InstanceStatusLimits {
max_characters: config.post_character_limit, max_characters: config.limits.posts.character_limit,
max_media_attachments: ATTACHMENTS_MAX_NUM, max_media_attachments: ATTACHMENTS_MAX_NUM,
}, },
media_attachments: InstanceMediaLimits { media_attachments: InstanceMediaLimits {
@ -168,7 +168,7 @@ impl InstanceInfo {
}, },
}, },
login_message: config.login_message.clone(), login_message: config.login_message.clone(),
post_character_limit: config.post_character_limit, post_character_limit: config.limits.posts.character_limit,
blockchains: blockchains, blockchains: blockchains,
ipfs_gateway_url: config.ipfs_gateway_url.clone(), ipfs_gateway_url: config.ipfs_gateway_url.clone(),
} }