feat: complete T-532 cmhub account prompt
This commit is contained in:
@@ -180,14 +180,35 @@ def mask_secret(secret) -> str:
|
||||
return f"{text[:4]}***{text[-4:]}"
|
||||
|
||||
|
||||
def mask_email(email) -> str:
|
||||
"""Return a display-safe email string with the local part masked."""
|
||||
|
||||
text = str(email or "").strip()
|
||||
if not text or "@" not in text:
|
||||
return text
|
||||
local, domain = text.split("@", 1)
|
||||
if not local or not domain:
|
||||
return mask_secret(text)
|
||||
if len(local) == 1:
|
||||
masked_local = "***"
|
||||
elif len(local) == 2:
|
||||
masked_local = f"{local[0]}***"
|
||||
else:
|
||||
masked_local = f"{local[0]}***{local[-1]}"
|
||||
return f"{masked_local}@{domain}"
|
||||
|
||||
|
||||
def sanitize_for_log(value):
|
||||
"""Return a copy of value with secret fields masked for logs/status/export."""
|
||||
|
||||
if isinstance(value, dict):
|
||||
sanitized = {}
|
||||
for key, child in value.items():
|
||||
lowered = str(key).lower()
|
||||
if _is_secret_field_name(key):
|
||||
sanitized[key] = mask_secret(child)
|
||||
elif lowered == "email" or lowered.endswith("_email"):
|
||||
sanitized[key] = mask_email(child)
|
||||
else:
|
||||
sanitized[key] = sanitize_for_log(child)
|
||||
return sanitized
|
||||
|
||||
@@ -1119,10 +1119,67 @@ class SettingsTab(QWidget):
|
||||
image_count = self._cmhub_alias_count("image")
|
||||
balance = payload.get("points_balance")
|
||||
balance_text = f";余额 {balance}" if balance is not None else ""
|
||||
message = f"cmhub 连接成功:生文别名 {title_count} 个,生图别名 {image_count} 个{balance_text};别名已拉取,记得点『保存设置』持久化"
|
||||
subject = self._cmhub_success_subject(payload)
|
||||
message = f"{subject}:生文别名 {title_count} 个,生图别名 {image_count} 个{balance_text};别名已拉取,记得点『保存设置』持久化"
|
||||
self.cmhub_result_label.setText(message)
|
||||
self._set_status(message)
|
||||
|
||||
def _cmhub_success_subject(self, payload):
|
||||
account_name = self._cmhub_account_display_name(payload)
|
||||
if account_name:
|
||||
return f"cmhub 账号「{account_name}」连接成功"
|
||||
return "cmhub 连接成功"
|
||||
|
||||
def _cmhub_account_display_name(self, payload):
|
||||
if not isinstance(payload, dict):
|
||||
return ""
|
||||
sources = []
|
||||
balance = payload.get("balance")
|
||||
if isinstance(balance, dict):
|
||||
account = balance.get("account")
|
||||
if isinstance(account, dict):
|
||||
sources.append(account)
|
||||
user = balance.get("user")
|
||||
if isinstance(user, dict):
|
||||
sources.append(user)
|
||||
elif user is not None:
|
||||
sources.append({"user": user})
|
||||
sources.append(balance)
|
||||
account = payload.get("account")
|
||||
if isinstance(account, dict):
|
||||
sources.append(account)
|
||||
user = payload.get("user")
|
||||
if isinstance(user, dict):
|
||||
sources.append(user)
|
||||
elif user is not None:
|
||||
sources.append({"user": user})
|
||||
sources.append(payload)
|
||||
for source in sources:
|
||||
name = self._cmhub_display_name_from_source(source)
|
||||
if name:
|
||||
return name
|
||||
return ""
|
||||
|
||||
def _cmhub_display_name_from_source(self, source):
|
||||
if not isinstance(source, dict):
|
||||
return ""
|
||||
for field in ("display_name", "name", "account_name", "username", "user", "email", "id"):
|
||||
value = source.get(field)
|
||||
if value is None:
|
||||
continue
|
||||
if isinstance(value, dict):
|
||||
nested_name = self._cmhub_display_name_from_source(value)
|
||||
if nested_name:
|
||||
return nested_name
|
||||
continue
|
||||
text = str(value).strip()
|
||||
if not text:
|
||||
continue
|
||||
if field == "email" or "@" in text:
|
||||
return appconfig.mask_email(text)
|
||||
return text
|
||||
return ""
|
||||
|
||||
def _on_cmhub_failed(self, _task_id, error):
|
||||
message = f"cmhub 连接失败:{error}"
|
||||
self.cmhub_result_label.setText(message)
|
||||
|
||||
Reference in New Issue
Block a user