feat(onboarding): add first-run membership activation
This commit is contained in:
+46
-3
@@ -50,6 +50,9 @@ SHOPEE_PARALLEL_ACCOUNTS_MIN = 1
|
||||
SHOPEE_PARALLEL_ACCOUNTS_MAX = 5
|
||||
CMHUB_CONNECT_TIMEOUT_DEFAULT = 66
|
||||
CMHUB_CONNECT_TIMEOUT_OLD_DEFAULT = 10
|
||||
DEFAULT_CMHUB_BASE_URL = "https://cm.833729.com"
|
||||
DEFAULT_MEMBER_CENTER_URL = "https://cm.833729.com"
|
||||
FIRST_USE_GUIDE_STATES = {"", "pending", "completed", "dismissed"}
|
||||
RUNTIME_CONFIG_KEYS = {
|
||||
"config_path",
|
||||
"ai_models_path",
|
||||
@@ -85,7 +88,7 @@ DEFAULT_CONFIG = {
|
||||
"generate_mode": "",
|
||||
"backend": "cmhub",
|
||||
"cmhub": {
|
||||
"base_url": "",
|
||||
"base_url": DEFAULT_CMHUB_BASE_URL,
|
||||
"title_alias": "",
|
||||
"image_alias": "",
|
||||
"vision_alias": "vision-standard",
|
||||
@@ -125,6 +128,9 @@ DEFAULT_CONFIG = {
|
||||
"subscription": {
|
||||
"last_notice_id": "",
|
||||
},
|
||||
"onboarding": {
|
||||
"first_use_guide_state": "",
|
||||
},
|
||||
}
|
||||
|
||||
DEFAULT_AI_MODELS_CONFIG = {
|
||||
@@ -409,7 +415,10 @@ def _normalize_config_values(config, migrate_old_cmhub_connect_timeout=False):
|
||||
)
|
||||
cmhub = ai.get("cmhub")
|
||||
if isinstance(cmhub, dict):
|
||||
cmhub["base_url"] = normalize_cmhub_base_url(cmhub.get("base_url", ""))
|
||||
cmhub["base_url"] = (
|
||||
normalize_cmhub_base_url(cmhub.get("base_url", ""))
|
||||
or DEFAULT_CMHUB_BASE_URL
|
||||
)
|
||||
cmhub["title_alias"] = str(cmhub.get("title_alias", "") or "").strip()
|
||||
cmhub["image_alias"] = str(cmhub.get("image_alias", "") or "").strip()
|
||||
cmhub["vision_alias"] = str(cmhub.get("vision_alias", "") or "").strip()
|
||||
@@ -456,6 +465,14 @@ def _normalize_config_values(config, migrate_old_cmhub_connect_timeout=False):
|
||||
suite["last_settings"] = _normalize_product_suite_last_settings(
|
||||
suite.get("last_settings")
|
||||
)
|
||||
onboarding = config.get("onboarding")
|
||||
if not isinstance(onboarding, dict):
|
||||
onboarding = {}
|
||||
config["onboarding"] = onboarding
|
||||
guide_state = str(onboarding.get("first_use_guide_state") or "").strip().lower()
|
||||
onboarding["first_use_guide_state"] = (
|
||||
guide_state if guide_state in FIRST_USE_GUIDE_STATES else ""
|
||||
)
|
||||
return config
|
||||
|
||||
|
||||
@@ -728,6 +745,29 @@ def save_subscription_notice_id(notice_id, path=CONFIG_PATH) -> dict:
|
||||
return save_config(config, path=path)
|
||||
|
||||
|
||||
def first_use_guide_state(config=None) -> str:
|
||||
section = _config_or_load(config).get("onboarding", {})
|
||||
if not isinstance(section, dict):
|
||||
return ""
|
||||
state = str(section.get("first_use_guide_state") or "").strip().lower()
|
||||
return state if state in FIRST_USE_GUIDE_STATES else ""
|
||||
|
||||
|
||||
def save_first_use_guide_state(state, path=CONFIG_PATH) -> dict:
|
||||
"""Persist the local first-use guide state without storing credentials."""
|
||||
|
||||
normalized = str(state or "").strip().lower()
|
||||
if normalized not in FIRST_USE_GUIDE_STATES:
|
||||
raise ConfigError("首次使用引导状态无效")
|
||||
config = load_config(path)
|
||||
section = config.get("onboarding", {})
|
||||
if not isinstance(section, dict):
|
||||
section = {}
|
||||
section["first_use_guide_state"] = normalized
|
||||
config["onboarding"] = section
|
||||
return save_config(config, path=path)
|
||||
|
||||
|
||||
def ai_config(config=None) -> dict:
|
||||
return copy.deepcopy(_config_or_load(config).get("ai", DEFAULT_CONFIG["ai"]))
|
||||
|
||||
@@ -830,7 +870,10 @@ def cmhub_config(config=None) -> dict:
|
||||
if not isinstance(value, dict):
|
||||
raise ConfigError("ai.cmhub 必须是对象")
|
||||
merged = _deep_merge(DEFAULT_CONFIG["ai"]["cmhub"], value)
|
||||
merged["base_url"] = normalize_cmhub_base_url(merged.get("base_url", ""))
|
||||
merged["base_url"] = (
|
||||
normalize_cmhub_base_url(merged.get("base_url", ""))
|
||||
or DEFAULT_CMHUB_BASE_URL
|
||||
)
|
||||
merged["title_alias"] = str(merged.get("title_alias", "") or "").strip()
|
||||
merged["image_alias"] = str(merged.get("image_alias", "") or "").strip()
|
||||
merged["vision_alias"] = str(merged.get("vision_alias", "") or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user