's'
This commit is contained in:
@@ -35,6 +35,25 @@ _admin_token_cache_value: str | None = None
|
||||
_admin_token_cache_expire_at = 0.0
|
||||
|
||||
|
||||
def _record_get(obj, key: str, default=None):
|
||||
"""兼容 PocketBase SDK Record 与 dict 取值。"""
|
||||
if obj is None:
|
||||
return default
|
||||
if isinstance(obj, dict):
|
||||
return obj.get(key, default)
|
||||
if hasattr(obj, key):
|
||||
try:
|
||||
value = getattr(obj, key)
|
||||
return default if value is None else value
|
||||
except Exception:
|
||||
return default
|
||||
try:
|
||||
value = obj[key] # type: ignore[index]
|
||||
return default if value is None else value
|
||||
except Exception:
|
||||
return default
|
||||
|
||||
|
||||
def _get_notify_path(provider_name: str) -> str:
|
||||
if provider_name == "xorpay":
|
||||
return f"{BASE_URL.rstrip('/')}/nomadvip/xorpay_notify"
|
||||
@@ -233,14 +252,14 @@ def _get_linked_email_for_user(pb, user_id: str) -> str | None:
|
||||
1, 1, {"filter": f'anonymous_user_id = "{user_id}"'}
|
||||
)
|
||||
if link_rec.items:
|
||||
return link_rec.items[0].get("email") or ""
|
||||
return (_record_get(link_rec.items[0], "email", "") or "").strip().lower()
|
||||
|
||||
if user_id and user_id.startswith("user") and user_id[4:].isdigit():
|
||||
link_rec = pb.collection("vip_email_link").get_list(
|
||||
1, 1, {"filter": f'user_id = "{user_id}"'}
|
||||
)
|
||||
if link_rec.items:
|
||||
return link_rec.items[0].get("email") or ""
|
||||
return (_record_get(link_rec.items[0], "email", "") or "").strip().lower()
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
@@ -255,7 +274,7 @@ def _uid_has_vip(pb, uid: str, site_id: str = "vip") -> bool:
|
||||
)
|
||||
if sv.items:
|
||||
rec = sv.items[0]
|
||||
expires = rec.get("expires_at") or ""
|
||||
expires = (_record_get(rec, "expires_at", "") or "").strip()
|
||||
if not expires:
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user