- 新增小红书前端模块(启动服务、内容分析、爆款创作、发布记录、技能卡片、拟人设置、AI 助手) - 新增 xhs-agent-desktop 独立桌面 Agent,对接 OMS 任务调度 - 登录页重构,整合微信登录与 OMS JWT 认证 - 订单、渠道、用户中心等页面与 API 增强 Co-authored-by: Cursor <cursoragent@cursor.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
/** 解析 JWT payload(不做签名校验,仅读取客户端声明) */
|
||
export function parseJwtPayload(token: string): Record<string, unknown> | null {
|
||
const raw = token.startsWith('Bearer ') ? token.slice(7) : token
|
||
const parts = raw.split('.')
|
||
if (parts.length < 2) return null
|
||
try {
|
||
const base64 = parts[1].replace(/-/g, '+').replace(/_/g, '/')
|
||
const padded = base64 + '='.repeat((4 - (base64.length % 4)) % 4)
|
||
const json = decodeURIComponent(
|
||
atob(padded)
|
||
.split('')
|
||
.map((c) => `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`)
|
||
.join('')
|
||
)
|
||
return JSON.parse(json) as Record<string, unknown>
|
||
} catch {
|
||
return null
|
||
}
|
||
}
|
||
|
||
/** 从 access token 读取 RBAC mapId(user.userid,对应 t_customer.UserId) */
|
||
export function getMapIdFromAccessToken(token?: string | null): number | null {
|
||
if (!token) return null
|
||
const payload = parseJwtPayload(token)
|
||
if (!payload) return null
|
||
const raw = payload.mapId ?? payload.MapId
|
||
if (raw == null || raw === '') return null
|
||
const n = Number(raw)
|
||
return Number.isFinite(n) && n > 0 ? n : null
|
||
}
|