feat=>增加多账号的代理

This commit is contained in:
amadeus5201 2025-01-15 21:20:04 +08:00
parent fa91a2126d
commit dbc6797ce8
3 changed files with 42 additions and 49 deletions

View File

@ -80,16 +80,6 @@ class Line {
}
}
}
function getIp({ url }) {
return new Promise((resolve) => {
send({
url,
method: 'GET',
success: res => resolve(res.body),
failure: err => resolve(err)
});
});
}
/**
* GET请求
@ -142,11 +132,6 @@ function post({ url, config, contents, query }) {
* 网络请求
*/
const bili_client = {
async getIpInfo() {
return await getIp({
url: 'https://myip.qq.com/'
});
},
/**
* 判断是否成功登录
* @returns {Promise<Object?>}
@ -201,11 +186,7 @@ const bili_client = {
const items = res.data.items;
if (items.length !== 0) {
items.forEach(i => {
const { at_time, item, user } = i, { nickname: up_uname } = user, {
business,
uri: url,
source_content
} = item;
const { at_time, item, user } = i, { nickname: up_uname } = user, { business, uri: url, source_content } = item;
atInfo.push({
at_time,
up_uname,
@ -602,7 +583,7 @@ const bili_client = {
* @param {number} uid
* @returns {Promise<string>}
*/
(uid) => get({
(uid) => get({
url: API.WEB_INTERFACE_CARD,
query: {
mid: uid,
@ -617,7 +598,7 @@ const bili_client = {
* @param {number} uid
* @returns {Promise<string>}
*/
(uid) => get({
(uid) => get({
url: API.RELATION_STAT,
query: {
vmid: uid
@ -628,7 +609,7 @@ const bili_client = {
* @param {number} uid
* @returns {Promise<string>}
*/
(uid) => get({
(uid) => get({
url: 'https://tenapi.cn/bilibilifo/',
query: {
uid

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);
});
}
};

29
main.js
View File

@ -6,12 +6,10 @@ const {
hasEnv,
delay,
hasFileOrDir,
clearLotteryInfo
clearLotteryInfo, printIpInfo
} = require('./lib/utils');
const { getIpInfo } = require("./lib/net/bili");
const { HttpsProxyAgent } = require("https-proxy-agent");
const request = require("https");
const { HttpsProxyAgent } = require('https-proxy-agent');
const request = require('https');
const metainfo = [
' _ _ _ _____ _ _ ',
' | | | | | | / ____| (_) | | ',
@ -35,15 +33,6 @@ let ck_flag = 0;
/**
* @returns {Promise<string>} 错误信息
*/
async function printIpInfo(beforeProxy) {
const printMessage = beforeProxy ? '当前IP----->' : '代理后IP=======>';
await getIpInfo().then(res => {
console.log(printMessage + res);
}).catch((err) => {
console.error('获取' + printMessage + '地址失败', err);
});
}
async function main() {
const { COOKIE, NUMBER, CLEAR, ENABLE_MULTIPLE_ACCOUNT, MULTIPLE_ACCOUNT_PARM } = process.env;
if (ENABLE_MULTIPLE_ACCOUNT) {
@ -52,6 +41,7 @@ async function main() {
: JSON.parse(MULTIPLE_ACCOUNT_PARM);
process.env.ENABLE_MULTIPLE_ACCOUNT = '';
let localhost = request.globalAgent;
const request = require('https');
for (const acco of muti_acco) {
@ -60,16 +50,18 @@ async function main() {
process.env.CLEAR = acco.CLEAR;
process.env.NOTE = acco.NOTE;
process.env.ACCOUNT_UA = acco.ACCOUNT_UA;
if (acco.PROXY_HOST) {
await printIpInfo(true);
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);
await printIpInfo(false);
printIpInfo(false);
}else {
//未设置还原
request.globalAgent = localhost;
}
const err_msg = await main();
if (err_msg) {
@ -81,9 +73,8 @@ async function main() {
await delay(3 * 1000);
}
}
request.globalAgent = localhost;
}
/**多账号状态还原 */
process.env.ENABLE_MULTIPLE_ACCOUNT = ENABLE_MULTIPLE_ACCOUNT;
} else if (COOKIE) {