-#[async_trait::async_trait(?Send)]
-impl PerformCrud for CreateSite {
- type Response = SiteResponse;
-
- #[tracing::instrument(skip(context))]
- async fn perform(&self, context: &Data<LemmyContext>) -> Result<SiteResponse, LemmyError> {
- let data: &CreateSite = self;
- let local_user_view = local_user_view_from_jwt(&data.auth, context).await?;
- let local_site = LocalSite::read(&mut context.pool()).await?;
-
- // Make sure user is an admin; other types of users should not create site data...
- is_admin(&local_user_view)?;
-
- validate_create_payload(&local_site, data)?;
-
- let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
- let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
- let keypair = generate_actor_keypair()?;
- let name = sanitize_html(&data.name);
- let sidebar = sanitize_html_opt(&data.sidebar);
- let description = sanitize_html_opt(&data.description);
-
- let site_form = SiteUpdateForm::builder()
- .name(Some(name))
- .sidebar(diesel_option_overwrite(sidebar))
- .description(diesel_option_overwrite(description))
- .icon(diesel_option_overwrite_to_url(&data.icon)?)
- .banner(diesel_option_overwrite_to_url(&data.banner)?)
- .actor_id(Some(actor_id))
- .last_refreshed_at(Some(naive_now()))
- .inbox_url(inbox_url)
- .private_key(Some(Some(keypair.private_key)))
- .public_key(Some(keypair.public_key))
- .build();
-
- let site_id = local_site.site_id;
-
- Site::update(&mut context.pool(), site_id, &site_form).await?;
-
- let application_question = sanitize_html_opt(&data.application_question);
- let default_theme = sanitize_html_opt(&data.default_theme);
- let legal_information = sanitize_html_opt(&data.legal_information);
-
- let local_site_form = LocalSiteUpdateForm::builder()
- // Set the site setup to true
- .site_setup(Some(true))
- .enable_downvotes(data.enable_downvotes)
- .registration_mode(data.registration_mode)
- .enable_nsfw(data.enable_nsfw)
- .community_creation_admin_only(data.community_creation_admin_only)
- .require_email_verification(data.require_email_verification)
- .application_question(diesel_option_overwrite(application_question))
- .private_instance(data.private_instance)
- .default_theme(default_theme)
- .default_post_listing_type(data.default_post_listing_type)
- .legal_information(diesel_option_overwrite(legal_information))
- .application_email_admins(data.application_email_admins)
- .hide_modlog_mod_names(data.hide_modlog_mod_names)
- .updated(Some(Some(naive_now())))
- .slur_filter_regex(diesel_option_overwrite(data.slur_filter_regex.clone()))
- .actor_name_max_length(data.actor_name_max_length)
- .federation_enabled(data.federation_enabled)
- .captcha_enabled(data.captcha_enabled)
- .captcha_difficulty(data.captcha_difficulty.clone())
- .build();
-
- LocalSite::update(&mut context.pool(), &local_site_form).await?;
-
- let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder()
- .message(data.rate_limit_message)
- .message_per_second(data.rate_limit_message_per_second)
- .post(data.rate_limit_post)
- .post_per_second(data.rate_limit_post_per_second)
- .register(data.rate_limit_register)
- .register_per_second(data.rate_limit_register_per_second)
- .image(data.rate_limit_image)
- .image_per_second(data.rate_limit_image_per_second)
- .comment(data.rate_limit_comment)
- .comment_per_second(data.rate_limit_comment_per_second)
- .search(data.rate_limit_search)
- .search_per_second(data.rate_limit_search_per_second)
- .build();
-
- LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form).await?;
-
- let site_view = SiteView::read_local(&mut context.pool()).await?;
-
- let new_taglines = data.taglines.clone();
- let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;
-
- let rate_limit_config =
- local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
- context
- .settings_updated_channel()
- .send(rate_limit_config)
- .await?;
-
- Ok(SiteResponse {
- site_view,
- taglines,
- })
- }
+#[tracing::instrument(skip(context))]
+pub async fn create_site(
+ data: Json<CreateSite>,
+ context: Data<LemmyContext>,
+) -> Result<Json<SiteResponse>, LemmyError> {
+ let local_user_view = local_user_view_from_jwt(&data.auth, &context).await?;
+ let local_site = LocalSite::read(&mut context.pool()).await?;
+
+ // Make sure user is an admin; other types of users should not create site data...
+ is_admin(&local_user_view)?;
+
+ validate_create_payload(&local_site, &data)?;
+
+ let actor_id: DbUrl = Url::parse(&context.settings().get_protocol_and_hostname())?.into();
+ let inbox_url = Some(generate_site_inbox_url(&actor_id)?);
+ let keypair = generate_actor_keypair()?;
+ let name = sanitize_html(&data.name);
+ let sidebar = sanitize_html_opt(&data.sidebar);
+ let description = sanitize_html_opt(&data.description);
+
+ let site_form = SiteUpdateForm::builder()
+ .name(Some(name))
+ .sidebar(diesel_option_overwrite(sidebar))
+ .description(diesel_option_overwrite(description))
+ .icon(diesel_option_overwrite_to_url(&data.icon)?)
+ .banner(diesel_option_overwrite_to_url(&data.banner)?)
+ .actor_id(Some(actor_id))
+ .last_refreshed_at(Some(naive_now()))
+ .inbox_url(inbox_url)
+ .private_key(Some(Some(keypair.private_key)))
+ .public_key(Some(keypair.public_key))
+ .build();
+
+ let site_id = local_site.site_id;
+
+ Site::update(&mut context.pool(), site_id, &site_form).await?;
+
+ let application_question = sanitize_html_opt(&data.application_question);
+ let default_theme = sanitize_html_opt(&data.default_theme);
+ let legal_information = sanitize_html_opt(&data.legal_information);
+
+ let local_site_form = LocalSiteUpdateForm::builder()
+ // Set the site setup to true
+ .site_setup(Some(true))
+ .enable_downvotes(data.enable_downvotes)
+ .registration_mode(data.registration_mode)
+ .enable_nsfw(data.enable_nsfw)
+ .community_creation_admin_only(data.community_creation_admin_only)
+ .require_email_verification(data.require_email_verification)
+ .application_question(diesel_option_overwrite(application_question))
+ .private_instance(data.private_instance)
+ .default_theme(default_theme)
+ .default_post_listing_type(data.default_post_listing_type)
+ .legal_information(diesel_option_overwrite(legal_information))
+ .application_email_admins(data.application_email_admins)
+ .hide_modlog_mod_names(data.hide_modlog_mod_names)
+ .updated(Some(Some(naive_now())))
+ .slur_filter_regex(diesel_option_overwrite(data.slur_filter_regex.clone()))
+ .actor_name_max_length(data.actor_name_max_length)
+ .federation_enabled(data.federation_enabled)
+ .captcha_enabled(data.captcha_enabled)
+ .captcha_difficulty(data.captcha_difficulty.clone())
+ .build();
+
+ LocalSite::update(&mut context.pool(), &local_site_form).await?;
+
+ let local_site_rate_limit_form = LocalSiteRateLimitUpdateForm::builder()
+ .message(data.rate_limit_message)
+ .message_per_second(data.rate_limit_message_per_second)
+ .post(data.rate_limit_post)
+ .post_per_second(data.rate_limit_post_per_second)
+ .register(data.rate_limit_register)
+ .register_per_second(data.rate_limit_register_per_second)
+ .image(data.rate_limit_image)
+ .image_per_second(data.rate_limit_image_per_second)
+ .comment(data.rate_limit_comment)
+ .comment_per_second(data.rate_limit_comment_per_second)
+ .search(data.rate_limit_search)
+ .search_per_second(data.rate_limit_search_per_second)
+ .build();
+
+ LocalSiteRateLimit::update(&mut context.pool(), &local_site_rate_limit_form).await?;
+
+ let site_view = SiteView::read_local(&mut context.pool()).await?;
+
+ let new_taglines = data.taglines.clone();
+ let taglines = Tagline::replace(&mut context.pool(), local_site.id, new_taglines).await?;
+
+ let rate_limit_config =
+ local_site_rate_limit_to_rate_limit_config(&site_view.local_site_rate_limit);
+ context
+ .settings_updated_channel()
+ .send(rate_limit_config)
+ .await?;
+
+ Ok(Json(SiteResponse {
+ site_view,
+ taglines,
+ }))