feat: 增加多账号的代理 (#433)
Some checks failed
Build and push Docker images / docker (push) Has been cancelled
Mirror and run GitLab CI / build (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, linux) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, macos) (push) Has been cancelled
Package Node.js project into an executable / node${{ matrix.nodev }}-${{ matrix.platform }}-x64 (18, win) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (alpine) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linux) (push) Has been cancelled
Package Node.js project into an executable / node18-${{ matrix.platform }}-arm64 (linuxstatic) (push) Has been cancelled

* feat=>增加多账号的代理

* feat=>增加多账号的代理

* fix=>变量声明
This commit is contained in:
amadeus5201 2025-01-16 08:04:30 +08:00 committed by GitHub
parent 717d8cf281
commit 1832f6d52b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 66 additions and 12 deletions

View File

@ -64,7 +64,11 @@ module.exports = Object.freeze({
NUMBER: 1,
CLEAR: true,
WAIT: 60 * 1000,
ACCOUNT_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
ACCOUNT_UA: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
PROXY_HOST:'',//代理ip
PROXY_PORT:'',//代理ip端口
PROXY_USER:'',//代理ip账号
PROXY_PASS:'',//代理ip密码
}
],

View File

@ -98,6 +98,7 @@ const utils = {
return _c(restNum - 1, argsList.concat(x));
};
}
return _c(func.length, []);
},
/**
@ -121,7 +122,9 @@ const utils = {
let c = {
i: 0,
next: () => c.i++,
clear: () => { c.i = 0; },
clear: () => {
c.i = 0;
},
value: () => c.i
};
return c;
@ -130,7 +133,7 @@ const utils = {
* 无限序列
* `[0..]`
*/
*infiniteNumber() {
* infiniteNumber() {
for (let index = 0; ; index++) {
yield index;
}
@ -178,7 +181,7 @@ const utils = {
/**
* 是否有指定环境变量
* @param {string} env_name
* @returns
* @returns
*/
hasEnv(env_name) {
return process.env[env_name] ? true : false;
@ -278,7 +281,7 @@ const utils = {
},
/**
* 验证码识别
* @param {string} url
* @param {string} url
* @returns {Promise<string>}
*/
ocr(url) {
@ -340,7 +343,7 @@ const utils = {
/**
* 是否存在文件或目录
* @param {string} path
* @returns
* @returns
*/
hasFileOrDir(path) {
try {
@ -414,7 +417,7 @@ const utils = {
/**
* 追加lotteryinfo
* @param {string} from
* @param {import("./core/searcher").LotteryInfo[]} lottery_info
* @param {import('./core/searcher').LotteryInfo[]} lottery_info
* @return {Promise<void>}
*/
async appendLotteryInfoFile(from, lottery_info) {
@ -435,7 +438,7 @@ const utils = {
/**
* 读取lottery_info
* @param {string} filename
* @return {Promise<import("./core/searcher").LotteryInfo[]>}
* @return {Promise<import('./core/searcher').LotteryInfo[]>}
*/
readLotteryInfoFile(filename) {
return new Promise((resolve) => {
@ -471,6 +474,24 @@ const utils = {
}
});
});
},
getIpInfo() {
return new Promise((resolve) => {
send({
url: 'https://myip.qq.com/',
method: 'GET',
success: res => resolve(res.body),
failure: err => resolve(err)
});
});
},
printIpInfo(beforeProxy) {
const printMessage = beforeProxy ? '当前IP----->' : '代理后IP=======>';
utils.getIpInfo().then(res => {
console.log(printMessage + res);
}).catch((err) => {
console.error('获取' + printMessage + '地址失败', err);
});
}
};

37
main.js
View File

@ -1,5 +1,15 @@
const { version: ve, env_file, config_file, log, hasEnv, delay, hasFileOrDir, clearLotteryInfo } = require('./lib/utils');
const {
version: ve,
env_file,
config_file,
log,
hasEnv,
delay,
hasFileOrDir,
clearLotteryInfo, printIpInfo
} = require('./lib/utils');
const { HttpsProxyAgent } = require('https-proxy-agent');
const request = require('https');
const metainfo = [
' _ _ _ _____ _ _ ',
' | | | | | | / ____| (_) | | ',
@ -31,6 +41,7 @@ async function main() {
: JSON.parse(MULTIPLE_ACCOUNT_PARM);
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
let localhost = request.globalAgent;
for (const acco of muti_acco) {
process.env.COOKIE = acco.COOKIE;
@ -38,6 +49,19 @@ async function main() {
process.env.CLEAR = acco.CLEAR;
process.env.NOTE = acco.NOTE;
process.env.ACCOUNT_UA = acco.ACCOUNT_UA;
if (acco.PROXY_HOST) {
printIpInfo(true);
//http://ip:port
//http://user:pwd@ip:port'
const proxyUrl = acco.PROXY_USER
? 'http://' + acco.PROXY_USER + ':' + acco.PROXY_PASS + '@' + acco.PROXY_HOST + ':' + acco.PROXY_PORT
: 'http://' + acco.PROXY_HOST + ':' + acco.PROXY_PORT;
request.globalAgent = new HttpsProxyAgent(proxyUrl);
printIpInfo(false);
}else {
//未设置还原
request.globalAgent = localhost;
}
const err_msg = await main();
if (err_msg) {
return err_msg;
@ -48,8 +72,8 @@ async function main() {
await delay(3 * 1000);
}
}
request.globalAgent = localhost;
}
/**多账号状态还原 */
process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT;
} else if (COOKIE) {
@ -65,7 +89,12 @@ async function main() {
const mode = process.env.lottery_mode;
const help_msg = '用法: lottery [OPTIONS]\n\nOPTIONS:\n\tstart 启动抽奖\n\tcheck 中奖检查\n\tacount 查看帐号信息\n\tclear 清理动态和关注\n\tlogin 扫码登录更新CK\n\tupdate 检查更新\n\thelp 帮助信息';
if (await checkCookie(NUMBER)) {
const { lottery_loop_wait, check_loop_wait, clear_loop_wait, save_lottery_info_to_file } = require('./lib/data/config');
const {
lottery_loop_wait,
check_loop_wait,
clear_loop_wait,
save_lottery_info_to_file
} = require('./lib/data/config');
ck_flag = 1;
switch (mode) {
case 'start':