adapt to the new version of cookie
This commit is contained in:
+25
-50
@@ -56,10 +56,8 @@ class YouProvider {
|
|||||||
|
|
||||||
// extract essential jwt session and token from cookie
|
// extract essential jwt session and token from cookie
|
||||||
for (let index = 0; index < config.sessions.length; index++) {
|
for (let index = 0; index < config.sessions.length; index++) {
|
||||||
let session = config.sessions[index];
|
let session = config.sessions[index], {jwtSession, jwtToken, ds, dsr} = extractCookie(session.cookie);
|
||||||
var { jwtSession, jwtToken, ds, dsr, youproSubscription, youSubscription, aiModel } = extractCookie(session.cookie);
|
if (jwtSession && jwtToken) {
|
||||||
|
|
||||||
if (jwtSession && jwtToken) {
|
|
||||||
// 旧版cookie处理
|
// 旧版cookie处理
|
||||||
try {
|
try {
|
||||||
let jwt = JSON.parse(Buffer.from(jwtToken.split(".")[1], "base64").toString());
|
let jwt = JSON.parse(Buffer.from(jwtToken.split(".")[1], "base64").toString());
|
||||||
@@ -67,9 +65,6 @@ class YouProvider {
|
|||||||
configIndex: index,
|
configIndex: index,
|
||||||
jwtSession,
|
jwtSession,
|
||||||
jwtToken,
|
jwtToken,
|
||||||
youproSubscription,
|
|
||||||
youSubscription,
|
|
||||||
aiModel,
|
|
||||||
valid: false,
|
valid: false,
|
||||||
};
|
};
|
||||||
console.log(`已添加 #${index} ${jwt.user.name} (旧版cookie)`);
|
console.log(`已添加 #${index} ${jwt.user.name} (旧版cookie)`);
|
||||||
@@ -77,51 +72,32 @@ class YouProvider {
|
|||||||
console.error(`解析第${index}个旧版cookie失败: ${e.message}`);
|
console.error(`解析第${index}个旧版cookie失败: ${e.message}`);
|
||||||
}
|
}
|
||||||
} else if (ds) {
|
} else if (ds) {
|
||||||
// 新版cookie处理,只要有DS就处理
|
// 新版cookie处理
|
||||||
try {
|
try {
|
||||||
let jwt = JSON.parse(Buffer.from(ds.split(".")[1], "base64").toString());
|
let jwt = JSON.parse(Buffer.from(ds.split(".")[1], "base64").toString());
|
||||||
this.sessions[jwt.email] = {
|
this.sessions[jwt.email] = {
|
||||||
configIndex: index,
|
configIndex: index,
|
||||||
ds,
|
ds,
|
||||||
dsr, // 即使dsr为null也会被添加
|
dsr,
|
||||||
youproSubscription,
|
|
||||||
youSubscription,
|
|
||||||
aiModel,
|
|
||||||
valid: false,
|
valid: false,
|
||||||
};
|
};
|
||||||
console.log(`已添加 #${index} ${jwt.email} (新版cookie)`);
|
console.log(`已添加 #${index} ${jwt.email} (新版cookie)`);
|
||||||
if (!dsr) {
|
if (!dsr) {
|
||||||
console.warn(`警告: 第${index}个cookie缺少DSR字段。程序继续执行。`);
|
console.warn(`警告: 第${index}个cookie缺少DSR字段。`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`解析第${index}个新版cookie失败: ${e.message}`);
|
console.error(`解析第${index}个新版cookie失败: ${e.message}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 无效cookie处理
|
|
||||||
console.error(`第${index}个cookie无效,请重新获取。`);
|
console.error(`第${index}个cookie无效,请重新获取。`);
|
||||||
if (jwtSession || jwtToken) {
|
console.error(`未检测到有效的DS或stytch_session字段。`);
|
||||||
console.error(`检测到部分旧版cookie字段,但不完整。`);
|
|
||||||
if (!jwtSession) console.error(`缺少: stytch_session`);
|
|
||||||
if (!jwtToken) console.error(`缺少: stytch_session_jwt`);
|
|
||||||
} else if (ds) {
|
|
||||||
console.error(`检测到新版cookie的DS字段,但缺少其他必要字段。`);
|
|
||||||
} else {
|
|
||||||
console.error(`未检测到任何有效的cookie字段。`);
|
|
||||||
}
|
|
||||||
console.error(`提示: 请确保登录You.com并成功获取完整的cookie。`);
|
|
||||||
continue; // 跳过无效的cookie,继续下一个
|
|
||||||
}
|
|
||||||
|
|
||||||
if (youproSubscription === "false" || youSubscription === "freemium") {
|
|
||||||
console.warn(`警告: 第${index}个cookie可能没有有效的订阅。请检查You是否有有效的Pro订阅。`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(`已添加 ${Object.keys(this.sessions).length} 个 cookie,开始验证有效性(是否有订阅)`);
|
console.log(`已添加 ${Object.keys(this.sessions).length} 个 cookie,开始验证有效性`);
|
||||||
|
|
||||||
|
for (let username of Object.keys(this.sessions)) {
|
||||||
for (var username of Object.keys(this.sessions)) {
|
let session = this.sessions[username];
|
||||||
var session = this.sessions[username];
|
createDirectoryIfNotExists(path.join(__dirname, "browser_profiles", username));
|
||||||
createDirectoryIfNotExists(path.join(__dirname, "browser_profiles", username));
|
|
||||||
await connect({
|
await connect({
|
||||||
headless: "auto",
|
headless: "auto",
|
||||||
turnstile: true,
|
turnstile: true,
|
||||||
@@ -136,16 +112,13 @@ class YouProvider {
|
|||||||
session.jwtSession,
|
session.jwtSession,
|
||||||
session.jwtToken,
|
session.jwtToken,
|
||||||
session.ds,
|
session.ds,
|
||||||
session.dsr,
|
session.dsr
|
||||||
session.youproSubscription,
|
|
||||||
session.youSubscription,
|
|
||||||
session.aiModel
|
|
||||||
));
|
));
|
||||||
|
|
||||||
page.goto("https://you.com", { timeout: 60000 });
|
page.goto("https://you.com", { timeout: 60000 });
|
||||||
await sleep(5000); // 等待加载完毕
|
await sleep(5000); // 等待加载完毕
|
||||||
// 如果遇到盾了就多等一段时间
|
// 如果遇到盾了就多等一段时间
|
||||||
var pageContent = await page.content();
|
let pageContent = await page.content();
|
||||||
if (pageContent.indexOf("https://challenges.cloudflare.com") > -1) {
|
if (pageContent.indexOf("https://challenges.cloudflare.com") > -1) {
|
||||||
console.log(`请在30秒内完成人机验证`);
|
console.log(`请在30秒内完成人机验证`);
|
||||||
page.evaluate(() => {
|
page.evaluate(() => {
|
||||||
@@ -167,10 +140,12 @@ class YouProvider {
|
|||||||
session.page = page;
|
session.page = page;
|
||||||
} else {
|
} else {
|
||||||
console.log(`${username} 无有效订阅`);
|
console.log(`${username} 无有效订阅`);
|
||||||
|
console.warn(`警告: ${username} 可能没有有效的订阅。请检查You是否有有效的Pro订阅。`);
|
||||||
await browser.close();
|
await browser.close();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`${username} 已失效`);
|
console.log(`${username} 已失效`);
|
||||||
|
console.warn(`警告: ${username} 验证失败。请检查cookie是否有效。`);
|
||||||
await browser.close();
|
await browser.close();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -200,8 +175,8 @@ class YouProvider {
|
|||||||
browsers.edge = this.findLinuxBrowser('microsoft-edge');
|
browsers.edge = this.findLinuxBrowser('microsoft-edge');
|
||||||
}
|
}
|
||||||
|
|
||||||
const preferredBrowser = this.preferredBrowser === 'auto' || this.preferredBrowser === undefined
|
const preferredBrowser = this.preferredBrowser === 'auto' || this.preferredBrowser === undefined
|
||||||
? Object.keys(browsers).find(browser => browsers[browser])
|
? Object.keys(browsers).find(browser => browsers[browser])
|
||||||
: this.preferredBrowser;
|
: this.preferredBrowser;
|
||||||
|
|
||||||
if (browsers[preferredBrowser]) {
|
if (browsers[preferredBrowser]) {
|
||||||
@@ -249,7 +224,7 @@ class YouProvider {
|
|||||||
|
|
||||||
const userAppDataPath = process.env.LOCALAPPDATA || `${process.env.USERPROFILE}\\AppData\\Local`;
|
const userAppDataPath = process.env.LOCALAPPDATA || `${process.env.USERPROFILE}\\AppData\\Local`;
|
||||||
const appDataPath = path.join(userAppDataPath, folderName, 'Application');
|
const appDataPath = path.join(userAppDataPath, folderName, 'Application');
|
||||||
|
|
||||||
if (fs.existsSync(appDataPath)) {
|
if (fs.existsSync(appDataPath)) {
|
||||||
const files = fs.readdirSync(appDataPath);
|
const files = fs.readdirSync(appDataPath);
|
||||||
const exePath = files.find(file => file.toLowerCase() === exeName.toLowerCase());
|
const exePath = files.find(file => file.toLowerCase() === exeName.toLowerCase());
|
||||||
@@ -284,7 +259,7 @@ class YouProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getCompletion(username, messages, stream = false, proxyModel, useCustomMode = false) {
|
async getCompletion({username, messages, stream = false, proxyModel, useCustomMode = false}) {
|
||||||
const session = this.sessions[username];
|
const session = this.sessions[username];
|
||||||
if (!session || !session.valid) {
|
if (!session || !session.valid) {
|
||||||
throw new Error(`用户 ${username} 的会话无效`);
|
throw new Error(`用户 ${username} 的会话无效`);
|
||||||
@@ -297,15 +272,15 @@ class YouProvider {
|
|||||||
this.switchCounter++;
|
this.switchCounter++;
|
||||||
this.requestsInCurrentMode++;
|
this.requestsInCurrentMode++;
|
||||||
console.log(`当前模式: ${this.currentMode}, 本模式下的请求次数: ${this.requestsInCurrentMode}, 距离下次切换还有 ${this.switchThreshold - this.switchCounter} 次请求`);
|
console.log(`当前模式: ${this.currentMode}, 本模式下的请求次数: ${this.requestsInCurrentMode}, 距离下次切换还有 ${this.switchThreshold - this.switchCounter} 次请求`);
|
||||||
|
|
||||||
if (this.switchCounter >= this.switchThreshold) {
|
if (this.switchCounter >= this.switchThreshold) {
|
||||||
this.switchMode();
|
this.switchMode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 根据轮换状态决定是否使用自定义模式
|
// 根据轮换状态决定是否使用自定义模式
|
||||||
const effectiveUseCustomMode = this.isRotationEnabled ? (this.currentMode === "custom") : useCustomMode;
|
const effectiveUseCustomMode = this.isRotationEnabled ? (this.currentMode === "custom") : useCustomMode;
|
||||||
|
|
||||||
// 检查页面是否已经加载完成
|
// 检查页面是否已经加载完成
|
||||||
const isLoaded = await page.evaluate(() => {
|
const isLoaded = await page.evaluate(() => {
|
||||||
return document.readyState === 'complete' || document.readyState === 'interactive';
|
return document.readyState === 'complete' || document.readyState === 'interactive';
|
||||||
@@ -319,7 +294,7 @@ class YouProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await page.goto("https://you.com/?chatMode=default", { waitUntil: "domcontentloaded" });
|
await page.goto("https://you.com/?chatMode=default", { waitUntil: "domcontentloaded" });
|
||||||
|
|
||||||
// 计算用户消息长度
|
// 计算用户消息长度
|
||||||
let userMessage = [{ question: "", answer: "" }];
|
let userMessage = [{ question: "", answer: "" }];
|
||||||
let userQuery = "";
|
let userQuery = "";
|
||||||
@@ -393,7 +368,7 @@ class YouProvider {
|
|||||||
} else {
|
} else {
|
||||||
console.log("Custom mode is disabled, using default mode.");
|
console.log("Custom mode is disabled, using default mode.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成随机文件名
|
// 生成随机文件名
|
||||||
function generateRandomFileName(length) {
|
function generateRandomFileName(length) {
|
||||||
const validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
const validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
|
||||||
@@ -403,7 +378,7 @@ class YouProvider {
|
|||||||
}
|
}
|
||||||
return result + '.docx';
|
return result + '.docx';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 生成随机长度(6-16)的文件名
|
// 生成随机长度(6-16)的文件名
|
||||||
const randomFileName = generateRandomFileName(Math.floor(Math.random() * 11) + 6);
|
const randomFileName = generateRandomFileName(Math.floor(Math.random() * 11) + 6);
|
||||||
console.log(`Generated random file name: ${randomFileName}`);
|
console.log(`Generated random file name: ${randomFileName}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user