github-actions[bot]
commited on
Commit
·
941e70c
1
Parent(s):
7fc5208
Update from GitHub Actions
Browse files- functions/api/mail/auth.ts +37 -28
functions/api/mail/auth.ts
CHANGED
@@ -35,14 +35,14 @@ export const onRequest = async (context: RouteContext): Promise<Response> => {
|
|
35 |
let context;
|
36 |
try {
|
37 |
browser = await chromium.launch({
|
38 |
-
headless: true,
|
39 |
args: [
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
],
|
47 |
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, // 使用系统 Chromium
|
48 |
});
|
@@ -73,11 +73,30 @@ export const onRequest = async (context: RouteContext): Promise<Response> => {
|
|
73 |
console.log(`没有切换到密码登录,继续执行: ${error}`);
|
74 |
}
|
75 |
|
76 |
-
try {
|
77 |
-
const timestamp = Math.floor(Date.now() / 1000);
|
78 |
-
await page.waitForSelector('#idA_PWD_SwitchToCredPicker', { timeout: 3000 });
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
//处理email验证
|
82 |
const proof = [
|
83 |
{
|
@@ -92,28 +111,18 @@ export const onRequest = async (context: RouteContext): Promise<Response> => {
|
|
92 |
}
|
93 |
]
|
94 |
|
95 |
-
const suffix =
|
96 |
const proofConfig = proof.find(p => p.suffix === suffix)!;
|
|
|
97 |
const verificationCode = await getVerificationCode(proofConfig.apiUrl, proofConfig.token!, account.proofEmail, timestamp);
|
98 |
|
99 |
await page.fill('input[type="tel"]', verificationCode);
|
100 |
-
await page.click('
|
101 |
-
}
|
102 |
-
|
103 |
-
throw new Error(`邮箱验证失败:${error}`)
|
104 |
}
|
105 |
-
|
106 |
-
await page.click('#idA_PWD_SwitchToCredPicker');
|
107 |
-
await page.click('#tileList > div:nth-child(2) Button');
|
108 |
-
|
109 |
-
} catch (error) {
|
110 |
-
console.log(`没有直接发邮件验证,继续执行: ${error}`);
|
111 |
}
|
112 |
|
113 |
-
//输入密码
|
114 |
-
await page.waitForURL("https://login.live.com/**")
|
115 |
-
await page.fill('input[type="password"]', account.password);
|
116 |
-
await page.click('button[type="submit"]');
|
117 |
|
118 |
//确认登录
|
119 |
await page.waitForURL('https://login.live.com/ppsecure/**')
|
@@ -128,9 +137,9 @@ export const onRequest = async (context: RouteContext): Promise<Response> => {
|
|
128 |
// 如果超时或页面未出现,直接继续执行
|
129 |
console.log("Consent page not found or timeout, skipping...");
|
130 |
}
|
131 |
-
await page.waitForURL((url)=>{
|
132 |
console.log(url)
|
133 |
-
return
|
134 |
})
|
135 |
} finally {
|
136 |
if (context) await context.close();
|
@@ -177,7 +186,7 @@ export const onRequest = async (context: RouteContext): Promise<Response> => {
|
|
177 |
if (!tokenData.expires_in) {
|
178 |
throw new Error("Missing expires_in in token response");
|
179 |
}
|
180 |
-
|
181 |
// 存储刷新令牌和时间戳
|
182 |
const tokenInfo = {
|
183 |
...tokenData,
|
|
|
35 |
let context;
|
36 |
try {
|
37 |
browser = await chromium.launch({
|
38 |
+
headless: process.env.NODE_ENV === 'development' ? false : true,
|
39 |
args: [
|
40 |
+
'--no-sandbox',
|
41 |
+
'--disable-setuid-sandbox',
|
42 |
+
'--disable-dev-shm-usage',
|
43 |
+
'--disable-blink-features=AutomationControlled', // 禁用自动化特征
|
44 |
+
'--disable-infobars',
|
45 |
+
'--window-size=1920,1080'
|
46 |
],
|
47 |
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH, // 使用系统 Chromium
|
48 |
});
|
|
|
73 |
console.log(`没有切换到密码登录,继续执行: ${error}`);
|
74 |
}
|
75 |
|
|
|
|
|
|
|
76 |
|
77 |
+
//输入密码
|
78 |
+
await page.waitForURL("https://login.live.com/**")
|
79 |
+
await page.fill('input[type="password"]', account.password);
|
80 |
+
await page.click('button[type="submit"]');
|
81 |
+
|
82 |
+
|
83 |
+
for (let i = 0; i < 2; i++) {
|
84 |
try {
|
85 |
+
await page.waitForURL('https://account.live.com/identity/**', { timeout: 5000 });
|
86 |
+
const proofEmail = account.proofEmail;
|
87 |
+
if (!proofEmail) {
|
88 |
+
throw new Error("No proof email provided");
|
89 |
+
}
|
90 |
+
const timestamp = Math.floor(Date.now() / 1000);
|
91 |
+
try {
|
92 |
+
await page.waitForSelector('#iProof0', { timeout: 3000 });
|
93 |
+
await page.click('#iProof0')
|
94 |
+
} catch (error) {
|
95 |
+
console.log(`没有#iProof0,继续执行: ${error}`);
|
96 |
+
}
|
97 |
+
await page.fill("#iProofEmail", proofEmail)
|
98 |
+
await page.click('input[type="submit"]')
|
99 |
+
|
100 |
//处理email验证
|
101 |
const proof = [
|
102 |
{
|
|
|
111 |
}
|
112 |
]
|
113 |
|
114 |
+
const suffix = proofEmail.substring(proofEmail.indexOf('@') + 1);
|
115 |
const proofConfig = proof.find(p => p.suffix === suffix)!;
|
116 |
+
console.log(suffix,proofConfig)
|
117 |
const verificationCode = await getVerificationCode(proofConfig.apiUrl, proofConfig.token!, account.proofEmail, timestamp);
|
118 |
|
119 |
await page.fill('input[type="tel"]', verificationCode);
|
120 |
+
await page.click('input[type="submit"]');
|
121 |
+
} catch (error) {
|
122 |
+
console.log(account.email, `没有多重验证,继续执行: ${error}`);
|
|
|
123 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
}
|
125 |
|
|
|
|
|
|
|
|
|
126 |
|
127 |
//确认登录
|
128 |
await page.waitForURL('https://login.live.com/ppsecure/**')
|
|
|
137 |
// 如果超时或页面未出现,直接继续执行
|
138 |
console.log("Consent page not found or timeout, skipping...");
|
139 |
}
|
140 |
+
await page.waitForURL((url) => {
|
141 |
console.log(url)
|
142 |
+
return url.href.startsWith(redirectUri);
|
143 |
})
|
144 |
} finally {
|
145 |
if (context) await context.close();
|
|
|
186 |
if (!tokenData.expires_in) {
|
187 |
throw new Error("Missing expires_in in token response");
|
188 |
}
|
189 |
+
|
190 |
// 存储刷新令牌和时间戳
|
191 |
const tokenInfo = {
|
192 |
...tokenData,
|