MCPcopy Index your code
hub / github.com/QLHazyCoder/FlowPilot / requestHotmailLocalCode

Function requestHotmailLocalCode

background.js:1636–1714  ·  view source on GitHub ↗
(account, pollPayload = {})

Source from the content-addressed store, hash-verified

1634}
1635
1636async function requestHotmailLocalCode(account, pollPayload = {}) {
1637 if (!account?.email) {
1638 throw new Error('Hotmail 账号缺少邮箱地址。');
1639 }
1640 if (!account?.clientId) {
1641 throw new Error(`Hotmail 账号 ${account.email || account.id} 缺少客户端 ID。`);
1642 }
1643 if (!account?.refreshToken) {
1644 throw new Error(`Hotmail 账号 ${account.email || account.id} 缺少刷新令牌(refresh token)。`);
1645 }
1646
1647 const serviceSettings = getHotmailServiceSettings(await getState());
1648 const { timeoutMs } = getHotmailMailApiRequestConfig();
1649 const requestTimeoutMs = Math.max(timeoutMs, HOTMAIL_LOCAL_HELPER_TIMEOUT_MS);
1650 const controller = new AbortController();
1651 const timeoutId = setTimeout(() => controller.abort(new Error('timeout')), requestTimeoutMs);
1652
1653 let response;
1654 try {
1655 response = await fetch(buildHotmailLocalEndpoint(serviceSettings.localBaseUrl, '/code'), {
1656 method: 'POST',
1657 headers: {
1658 'Content-Type': 'application/json',
1659 Accept: 'application/json',
1660 },
1661 body: JSON.stringify({
1662 email: account.email,
1663 clientId: account.clientId,
1664 refreshToken: account.refreshToken,
1665 mailboxes: HOTMAIL_MAILBOXES,
1666 top: 5,
1667 senderFilters: pollPayload.senderFilters || [],
1668 subjectFilters: pollPayload.subjectFilters || [],
1669 excludeCodes: pollPayload.excludeCodes || [],
1670 filterAfterTimestamp: Number(pollPayload.filterAfterTimestamp || 0) || 0,
1671 }),
1672 signal: controller.signal,
1673 });
1674 } catch (err) {
1675 if (err?.name === 'AbortError') {
1676 throw new Error(`Hotmail 本地助手请求超时(>${Math.round(requestTimeoutMs / 1000)} 秒)`);
1677 }
1678 throw new Error(`Hotmail 本地助手请求失败:${err.message}`);
1679 } finally {
1680 clearTimeout(timeoutId);
1681 }
1682
1683 const text = await response.text();
1684 let payload = {};
1685 try {
1686 payload = text ? JSON.parse(text) : {};
1687 } catch {
1688 payload = { raw: text };
1689 }
1690
1691 if (!response.ok || payload?.ok === false) {
1692 const errorText = payload?.error || payload?.message || text || `HTTP ${response.status}`;
1693 throw new Error(`Hotmail 本地助手返回失败:${errorText}`);

Calls 7

getStateFunction · 0.85
upsertHotmailAccountFunction · 0.85

Tested by

no test coverage detected