|
|
|
@ -11,6 +11,7 @@ let store = new Store(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
router.post('/rsCookie', async (req, res) => { |
|
|
|
|
let uuid = crypto.randomUUID() |
|
|
|
|
let start = new Date(); |
|
|
|
|
try { |
|
|
|
|
let url = req.body['url']; |
|
|
|
@ -19,7 +20,7 @@ router.post('/rsCookie', async (req, res) => { |
|
|
|
|
let jsStr = req.body['jsBase64']; |
|
|
|
|
let cookie = req.body['cookieBase64']; |
|
|
|
|
let userAgent = req.body['userAgentBase64']; |
|
|
|
|
console.log(`接收到 ${areaName} 请求:${url}`) |
|
|
|
|
console.log(`${uuid};接收到 ${areaName} 请求:${url}`) |
|
|
|
|
if (url == null || url === '') { |
|
|
|
|
return res.status(500).send('error url') |
|
|
|
|
} |
|
|
|
@ -45,12 +46,15 @@ router.post('/rsCookie', async (req, res) => { |
|
|
|
|
jsText, |
|
|
|
|
cookie != null && cookie !== "" ? Buffer.from(cookie, 'base64').toString('utf-8') : null, |
|
|
|
|
userAgent != null && userAgent !== "" ? Buffer.from(userAgent, 'base64').toString('utf-8') : null) |
|
|
|
|
|
|
|
|
|
console.log(`${uuid};返回cookie ---->`,cookies.split('; ')) |
|
|
|
|
|
|
|
|
|
res.status(200).send(cookies); |
|
|
|
|
} catch (e) { |
|
|
|
|
console.error(e) |
|
|
|
|
return res.status(500).send(e.toString()) |
|
|
|
|
} finally { |
|
|
|
|
console.log(`rsCookie ${new Date() - start} ms`) |
|
|
|
|
console.log(`${uuid};rsCookie ${new Date() - start} ms`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}) |
|
|
|
@ -81,8 +85,7 @@ function CookieStr2List(cookies) { |
|
|
|
|
return list |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function handle(url, htmlStr, jsText, cookie, userAgent) { |
|
|
|
|
let uuid = crypto.randomUUID() |
|
|
|
|
async function handle(url, htmlStr, jsText, cookie, userAgent,uuid) { |
|
|
|
|
// 获取 origin
|
|
|
|
|
let baseUrl = new URL(url).origin; |
|
|
|
|
// 初始化 jsDom 和 cookieJar
|
|
|
|
@ -95,9 +98,8 @@ async function handle(url, htmlStr, jsText, cookie, userAgent) { |
|
|
|
|
}) |
|
|
|
|
// 设置 cookie
|
|
|
|
|
if (cookie != null) { |
|
|
|
|
console.log(cookie) |
|
|
|
|
let cookieList = CookieStr2List(cookie); |
|
|
|
|
console.log('cookie 加载--->', cookieList, baseUrl) |
|
|
|
|
console.log(`${uuid};cookie 加载长度--->`, cookieList.length, baseUrl) |
|
|
|
|
for (let i = 0; i < cookieList.length; i++) { |
|
|
|
|
cookieJar.setCookieSync(cookieList[i], baseUrl); |
|
|
|
|
} |
|
|
|
@ -105,7 +107,7 @@ async function handle(url, htmlStr, jsText, cookie, userAgent) { |
|
|
|
|
// 加载dom
|
|
|
|
|
let dom = await jsDom(htmlStr); |
|
|
|
|
// console.log('html 加载长度--->', dom.serialize())
|
|
|
|
|
console.log('html 加载长度--->', dom.serialize().length) |
|
|
|
|
console.log(`${uuid};html 加载长度--->`, dom.serialize().length) |
|
|
|
|
|
|
|
|
|
window = dom.window |
|
|
|
|
// js执行成功后的瑞树会跳转页面 会触发onbeforeunload钩子
|
|
|
|
@ -119,7 +121,7 @@ async function handle(url, htmlStr, jsText, cookie, userAgent) { |
|
|
|
|
browser(window, 'chrome'); |
|
|
|
|
// 加载js
|
|
|
|
|
let js = loadJs(window, jsText); |
|
|
|
|
console.log('js 加载长度--->', js.length) |
|
|
|
|
console.log(`${uuid};js 加载长度--->`, js.length) |
|
|
|
|
|
|
|
|
|
// 执行 js
|
|
|
|
|
let script = new Script(js); |
|
|
|
|