nomadro/src/modules/vip/app/lib/remoteConfigBridge.ts
Eric 3e60ba1a1b Ship social places/join UX, room-archive ops, and rich Markdown ntfy alerts.
Unify city+cafe into one places page, gate join with on-page modal, and enrich ntfy with icons, tables, and action buttons across portal/API/admin.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-05 12:21:01 +08:00

43 lines
1.2 KiB
TypeScript

/**
* 读取门户写入的远程配置缓存(与 ~/lib/use-remote-config CACHE_KEY 对齐)
* VIP 垂直仓不直接依赖门户路径,只读 localStorage。
*/
const WEB_CACHE_KEY = "nomadro_web_remote_config_v2";
export type VipRemoteCopy = {
vipPriceFen?: number;
vipProductId?: string;
vipCta?: string;
payEnabled?: boolean;
};
export function readPortalRemoteCopy(): VipRemoteCopy {
if (typeof window === "undefined") return {};
try {
const raw = localStorage.getItem(WEB_CACHE_KEY);
if (!raw) return {};
const parsed = JSON.parse(raw) as {
config?: {
copy?: {
vipPriceFen?: number;
vipProductId?: string;
vipCta?: string;
};
flags?: { payEnabled?: boolean };
};
};
const copy = parsed?.config?.copy || {};
const flags = parsed?.config?.flags || {};
// 0 = 免费;禁止 `Number(x) || undefined` 把 0 吞掉后回落到 ¥0.1
const fenRaw = Number(copy.vipPriceFen);
return {
vipPriceFen: Number.isFinite(fenRaw) ? fenRaw : undefined,
vipProductId: copy.vipProductId,
vipCta: copy.vipCta,
payEnabled: flags.payEnabled,
};
} catch {
return {};
}
}