feat: refresh content workflow and verification settings
All checks were successful
docker-images / build-and-push (admin, admin, termi-astro-admin, admin/Dockerfile) (push) Successful in 43s
docker-images / build-and-push (backend, backend, termi-astro-backend, backend/Dockerfile) (push) Successful in 25m9s
docker-images / build-and-push (frontend, frontend, termi-astro-frontend, frontend/Dockerfile) (push) Successful in 51s
All checks were successful
docker-images / build-and-push (admin, admin, termi-astro-admin, admin/Dockerfile) (push) Successful in 43s
docker-images / build-and-push (backend, backend, termi-astro-backend, backend/Dockerfile) (push) Successful in 25m9s
docker-images / build-and-push (frontend, frontend, termi-astro-frontend, frontend/Dockerfile) (push) Successful in 51s
This commit is contained in:
@@ -93,8 +93,12 @@ pub struct SiteSettingsPayload {
|
||||
pub ai_enabled: Option<bool>,
|
||||
#[serde(default, alias = "paragraphCommentsEnabled")]
|
||||
pub paragraph_comments_enabled: Option<bool>,
|
||||
#[serde(default, alias = "commentVerificationMode")]
|
||||
pub comment_verification_mode: Option<String>,
|
||||
#[serde(default, alias = "commentTurnstileEnabled")]
|
||||
pub comment_turnstile_enabled: Option<bool>,
|
||||
#[serde(default, alias = "subscriptionVerificationMode")]
|
||||
pub subscription_verification_mode: Option<String>,
|
||||
#[serde(default, alias = "subscriptionTurnstileEnabled")]
|
||||
pub subscription_turnstile_enabled: Option<bool>,
|
||||
#[serde(default, alias = "webPushEnabled")]
|
||||
@@ -195,7 +199,9 @@ pub struct PublicSiteSettingsResponse {
|
||||
pub music_playlist: Option<serde_json::Value>,
|
||||
pub ai_enabled: bool,
|
||||
pub paragraph_comments_enabled: bool,
|
||||
pub comment_verification_mode: String,
|
||||
pub comment_turnstile_enabled: bool,
|
||||
pub subscription_verification_mode: String,
|
||||
pub subscription_turnstile_enabled: bool,
|
||||
pub web_push_enabled: bool,
|
||||
pub turnstile_site_key: Option<String>,
|
||||
@@ -270,6 +276,9 @@ pub(crate) fn default_subscription_popup_delay_seconds() -> i32 {
|
||||
18
|
||||
}
|
||||
|
||||
const DEFAULT_TURNSTILE_SITE_KEY: &str = "0x4AAAAAACy58kMBSwXwqMhx";
|
||||
const DEFAULT_TURNSTILE_SECRET_KEY: &str = "0x4AAAAAACy58m3gYfSqM-VIz4QK4wuO73U";
|
||||
|
||||
fn normalize_string_list(values: Vec<String>) -> Vec<String> {
|
||||
values
|
||||
.into_iter()
|
||||
@@ -549,11 +558,48 @@ impl SiteSettingsPayload {
|
||||
if let Some(paragraph_comments_enabled) = self.paragraph_comments_enabled {
|
||||
item.paragraph_comments_enabled = Some(paragraph_comments_enabled);
|
||||
}
|
||||
if let Some(comment_turnstile_enabled) = self.comment_turnstile_enabled {
|
||||
if let Some(comment_verification_mode) = self
|
||||
.comment_verification_mode
|
||||
.as_deref()
|
||||
.and_then(|value| crate::services::turnstile::normalize_verification_mode(Some(value)))
|
||||
{
|
||||
item.comment_verification_mode = Some(comment_verification_mode.as_str().to_string());
|
||||
item.comment_turnstile_enabled = Some(matches!(
|
||||
comment_verification_mode,
|
||||
crate::services::turnstile::VerificationMode::Turnstile
|
||||
));
|
||||
} else if let Some(comment_turnstile_enabled) = self.comment_turnstile_enabled {
|
||||
item.comment_turnstile_enabled = Some(comment_turnstile_enabled);
|
||||
item.comment_verification_mode = Some(
|
||||
if comment_turnstile_enabled {
|
||||
crate::services::turnstile::VERIFICATION_MODE_TURNSTILE
|
||||
} else {
|
||||
crate::services::turnstile::VERIFICATION_MODE_CAPTCHA
|
||||
}
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if let Some(subscription_turnstile_enabled) = self.subscription_turnstile_enabled {
|
||||
if let Some(subscription_verification_mode) = self
|
||||
.subscription_verification_mode
|
||||
.as_deref()
|
||||
.and_then(|value| crate::services::turnstile::normalize_verification_mode(Some(value)))
|
||||
{
|
||||
item.subscription_verification_mode =
|
||||
Some(subscription_verification_mode.as_str().to_string());
|
||||
item.subscription_turnstile_enabled = Some(matches!(
|
||||
subscription_verification_mode,
|
||||
crate::services::turnstile::VerificationMode::Turnstile
|
||||
));
|
||||
} else if let Some(subscription_turnstile_enabled) = self.subscription_turnstile_enabled {
|
||||
item.subscription_turnstile_enabled = Some(subscription_turnstile_enabled);
|
||||
item.subscription_verification_mode = Some(
|
||||
if subscription_turnstile_enabled {
|
||||
crate::services::turnstile::VERIFICATION_MODE_TURNSTILE
|
||||
} else {
|
||||
crate::services::turnstile::VERIFICATION_MODE_OFF
|
||||
}
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
if let Some(web_push_enabled) = self.web_push_enabled {
|
||||
item.web_push_enabled = Some(web_push_enabled);
|
||||
@@ -763,11 +809,17 @@ fn default_payload() -> SiteSettingsPayload {
|
||||
]),
|
||||
ai_enabled: Some(false),
|
||||
paragraph_comments_enabled: Some(true),
|
||||
comment_verification_mode: Some(
|
||||
crate::services::turnstile::VERIFICATION_MODE_CAPTCHA.to_string(),
|
||||
),
|
||||
comment_turnstile_enabled: Some(false),
|
||||
subscription_verification_mode: Some(
|
||||
crate::services::turnstile::VERIFICATION_MODE_OFF.to_string(),
|
||||
),
|
||||
subscription_turnstile_enabled: Some(false),
|
||||
web_push_enabled: Some(false),
|
||||
turnstile_site_key: None,
|
||||
turnstile_secret_key: None,
|
||||
turnstile_site_key: Some(DEFAULT_TURNSTILE_SITE_KEY.to_string()),
|
||||
turnstile_secret_key: Some(DEFAULT_TURNSTILE_SECRET_KEY.to_string()),
|
||||
web_push_vapid_public_key: None,
|
||||
web_push_vapid_private_key: None,
|
||||
web_push_vapid_subject: None,
|
||||
@@ -835,11 +887,11 @@ pub(crate) async fn load_current(ctx: &AppContext) -> Result<Model> {
|
||||
fn public_response(model: Model) -> PublicSiteSettingsResponse {
|
||||
let turnstile_site_key = crate::services::turnstile::site_key(&model);
|
||||
let web_push_vapid_public_key = crate::services::web_push::public_key(&model);
|
||||
let comment_turnstile_enabled = crate::services::turnstile::is_enabled(
|
||||
let comment_verification_mode = crate::services::turnstile::effective_mode(
|
||||
&model,
|
||||
crate::services::turnstile::TurnstileScope::Comment,
|
||||
);
|
||||
let subscription_turnstile_enabled = crate::services::turnstile::is_enabled(
|
||||
let subscription_verification_mode = crate::services::turnstile::effective_mode(
|
||||
&model,
|
||||
crate::services::turnstile::TurnstileScope::Subscription,
|
||||
);
|
||||
@@ -866,8 +918,16 @@ fn public_response(model: Model) -> PublicSiteSettingsResponse {
|
||||
music_playlist: model.music_playlist,
|
||||
ai_enabled: model.ai_enabled.unwrap_or(false),
|
||||
paragraph_comments_enabled: model.paragraph_comments_enabled.unwrap_or(true),
|
||||
comment_turnstile_enabled,
|
||||
subscription_turnstile_enabled,
|
||||
comment_verification_mode: comment_verification_mode.as_str().to_string(),
|
||||
comment_turnstile_enabled: matches!(
|
||||
comment_verification_mode,
|
||||
crate::services::turnstile::VerificationMode::Turnstile
|
||||
),
|
||||
subscription_verification_mode: subscription_verification_mode.as_str().to_string(),
|
||||
subscription_turnstile_enabled: matches!(
|
||||
subscription_verification_mode,
|
||||
crate::services::turnstile::VerificationMode::Turnstile
|
||||
),
|
||||
web_push_enabled,
|
||||
turnstile_site_key,
|
||||
web_push_vapid_public_key,
|
||||
@@ -890,8 +950,6 @@ fn public_response(model: Model) -> PublicSiteSettingsResponse {
|
||||
|
||||
#[debug_handler]
|
||||
pub async fn home(State(ctx): State<AppContext>) -> Result<Response> {
|
||||
content::sync_markdown_posts(&ctx).await?;
|
||||
|
||||
let site_settings = public_response(load_current(&ctx).await?);
|
||||
let posts = posts::Entity::find()
|
||||
.order_by_desc(posts::Column::CreatedAt)
|
||||
|
||||
Reference in New Issue
Block a user