feat: 统一创作页表头跟随后台入口配置
This commit is contained in:
@@ -122,7 +122,8 @@ fn upsert_creation_entry_type_config_in_tx(
|
||||
if input.title.trim().is_empty() {
|
||||
return Err("入口标题不能为空".to_string());
|
||||
}
|
||||
let unified_creation_spec_json = normalize_unified_creation_spec_json(&id, &input)?;
|
||||
let unified_creation_spec_json =
|
||||
normalize_unified_creation_spec_json(&id, input.title.trim(), &input)?;
|
||||
let row = CreationEntryTypeConfig {
|
||||
id: id.clone(),
|
||||
title: input.title.trim().to_string(),
|
||||
@@ -297,6 +298,7 @@ fn seed_creation_entry_config_if_missing(ctx: &ReducerContext) {
|
||||
migrate_baby_object_match_entry_from_old_coming_soon_default(ctx, now);
|
||||
migrate_wooden_fish_entry_from_old_puzzle_image_default(ctx, now);
|
||||
migrate_jump_hop_entry_from_old_puzzle_default(ctx, now);
|
||||
migrate_unified_creation_titles_to_entry_defaults(ctx, now);
|
||||
}
|
||||
|
||||
fn migrate_rpg_entry_from_old_hidden_default(ctx: &ReducerContext, now: Timestamp) {
|
||||
@@ -477,6 +479,51 @@ fn migrate_jump_hop_entry_from_old_puzzle_default(ctx: &ReducerContext, now: Tim
|
||||
});
|
||||
}
|
||||
|
||||
fn migrate_unified_creation_titles_to_entry_defaults(ctx: &ReducerContext, now: Timestamp) {
|
||||
let rows = ctx
|
||||
.db
|
||||
.creation_entry_type_config()
|
||||
.iter()
|
||||
.collect::<Vec<_>>();
|
||||
for row in rows {
|
||||
let Some(raw_spec_json) = row.unified_creation_spec_json.as_deref() else {
|
||||
continue;
|
||||
};
|
||||
let Ok(spec) =
|
||||
shared_contracts::creation_entry_config::decode_unified_creation_spec_response(
|
||||
raw_spec_json,
|
||||
)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
let normalized =
|
||||
shared_contracts::creation_entry_config::normalize_unified_creation_spec_title_for_entry(
|
||||
&row.id,
|
||||
&row.title,
|
||||
spec.clone(),
|
||||
);
|
||||
if normalized.title == spec.title {
|
||||
continue;
|
||||
}
|
||||
let Ok(unified_creation_spec_json) =
|
||||
shared_contracts::creation_entry_config::encode_unified_creation_spec_response(
|
||||
&normalized,
|
||||
)
|
||||
else {
|
||||
continue;
|
||||
};
|
||||
|
||||
ctx.db
|
||||
.creation_entry_type_config()
|
||||
.id()
|
||||
.update(CreationEntryTypeConfig {
|
||||
unified_creation_spec_json: Some(unified_creation_spec_json),
|
||||
updated_at: now,
|
||||
..row
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn default_creation_entry_type_configs(now: Timestamp) -> Vec<CreationEntryTypeConfig> {
|
||||
module_runtime::default_creation_entry_type_snapshots(now.to_micros_since_unix_epoch())
|
||||
.into_iter()
|
||||
@@ -500,6 +547,7 @@ fn default_creation_entry_type_configs(now: Timestamp) -> Vec<CreationEntryTypeC
|
||||
|
||||
fn normalize_unified_creation_spec_json(
|
||||
id: &str,
|
||||
entry_title: &str,
|
||||
input: &CreationEntryTypeAdminUpsertInput,
|
||||
) -> Result<Option<String>, String> {
|
||||
let Some(spec_json) = input.unified_creation_spec_json.as_deref() else {
|
||||
@@ -512,6 +560,12 @@ fn normalize_unified_creation_spec_json(
|
||||
|
||||
let spec =
|
||||
shared_contracts::creation_entry_config::decode_unified_creation_spec_response(normalized)?;
|
||||
let spec =
|
||||
shared_contracts::creation_entry_config::normalize_unified_creation_spec_title_for_entry(
|
||||
id,
|
||||
entry_title,
|
||||
spec,
|
||||
);
|
||||
shared_contracts::creation_entry_config::validate_unified_creation_spec_for_play(id, &spec)?;
|
||||
shared_contracts::creation_entry_config::encode_unified_creation_spec_response(&spec).map(Some)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user