MCPcopy Create free account
hub / github.com/Bistutu/FluentRead / refreshToken

Function refreshToken

entrypoints/service/microsoft.ts:27–37  ·  view source on GitHub ↗
(token: string)

Source from the content-addressed store, hash-verified

25}
26
27async function refreshToken(token: string) {
28 const decodedToken = parseJwt(token);
29 const currentTimestamp = Math.floor(Date.now() / 1000); // 当前时间的UNIX时间戳(秒)
30 if (decodedToken && currentTimestamp < decodedToken.exp) {
31 return token;
32 }
33 // 如果令牌无效或已过期,则尝试获取新令牌
34 const resp = await fetch("https://edge.microsoft.com/translate/auth")
35 if (resp.ok) return resp.text();
36 else throw new Error(`请求失败: ${resp}`);
37}
38
39// 解析 jwt,返回解析后对象
40function parseJwt(token: string) {

Callers 1

microsoftFunction · 0.70

Calls 1

parseJwtFunction · 0.70

Tested by

no test coverage detected