diff --git a/src/jobs.rs b/src/jobs.rs index 1cb0359..6908e30 100644 --- a/src/jobs.rs +++ b/src/jobs.rs @@ -22,6 +22,7 @@ struct JobState { pub(super) fn build( base_url: Url, pict_rs_upstream: Url, + content_config: hyaenidae_profiles::ContentConfig, db: sled::Db, ) -> Result { let storage = Storage::new(); @@ -32,6 +33,7 @@ pub(super) fn build( Spawn(queue_handle.clone()), base_url, pict_rs_upstream, + content_config, Arbiter::current(), &db, )?; diff --git a/src/main.rs b/src/main.rs index d041fa1..4979fb8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -82,6 +82,7 @@ async fn main() -> anyhow::Result<()> { let state = jobs::build( config.base_url.clone(), config.pictrs_upstream.clone(), + config.content(), db.clone(), )?; let accounts_state = hyaenidae_accounts::state(&accounts_config, db.clone())?; @@ -195,10 +196,92 @@ struct Config { )] skip_signature_validation: bool, + #[structopt( + long, + env = "HYAENIDAE_MAX_BIO_LENGTH", + about = "Maximum allowed characters in a profile bio", + default_value = "500" + )] + max_bio: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_DISPLAY_NAME_LENGTH", + about = "Maximum allowed characters in a profile display name", + default_value = "20" + )] + max_display_name: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_HANDLE_LENGTH", + about = "Maximum allowed characters in a profile handle", + default_value = "20" + )] + max_handle: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_SUBMISSION_TITLE_LENGTH", + about = "Maximum allowed characters in a submission title", + default_value = "50" + )] + max_submission_title: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_SUBMISSION_BODY_LENGTH", + about = "Maximum allowed characters in a submission body", + default_value = "1000" + )] + max_submission_body: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_POST_TITLE_LENGTH", + about = "Maximum allowed characters in a post title", + default_value = "50" + )] + max_post_title: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_POST_BODY_LENGTH", + about = "Maximum allowed characters in a post body", + default_value = "1000" + )] + max_post_body: usize, + + #[structopt( + long, + env = "HYAENIDAE_MAX_COMMENT_LENGTH", + about = "Maximum allowed characters in a comment", + default_value = "500" + )] + max_comment: usize, + #[structopt(short, long, about = "enable debug logging")] debug: bool, } +impl Config { + fn content(&self) -> hyaenidae_profiles::ContentConfig { + hyaenidae_profiles::ContentConfig { + max_bio_length: self.max_bio, + max_display_name_length: self.max_display_name, + max_handle_length: self.max_handle, + max_domain_length: 256, + max_submission_title_length: self.max_submission_title, + max_submission_body_length: self.max_submission_body, + max_post_title_length: self.max_post_title, + max_post_body_length: self.max_post_body, + max_comment_length: self.max_comment, + max_server_title_length: 50, + max_server_body_length: 1000, + } + } +} + #[derive(Clone)] struct SecretKey { inner: Vec, @@ -245,6 +328,7 @@ impl State { spawn: jobs::Spawn, base_url: url::Url, pict_rs_upstream: url::Url, + content_config: hyaenidae_profiles::ContentConfig, arbiter: Arbiter, db: &Db, ) -> Result { @@ -263,6 +347,7 @@ impl State { apub.clone(), spawn.clone(), Urls, + content_config, arbiter, db.clone(), )?,