fix(eslint): fix files which have eslint problems

This commit is contained in:
MoeFurina
2025-11-01 13:11:38 +08:00
parent 398f410109
commit 597ac1498f
13 changed files with 387 additions and 288 deletions
+6 -3
View File
@@ -155,9 +155,12 @@ function ApiCache() {
}
// add automatic cache clearing from duration, includes max limit on setTimeout
timers[key] = setTimeout(function () {
instance.clear(key, true)
}, Math.min(duration, 2147483647))
timers[key] = setTimeout(
function () {
instance.clear(key, true)
},
Math.min(duration, 2147483647),
)
}
function accumulateContent(res, content) {
+61 -61
View File
@@ -1,5 +1,5 @@
const crypto = require("crypto");
const os = require("os");
const crypto = require('crypto')
const os = require('os')
class AdvancedClientSignGenerator {
/**
@@ -7,25 +7,25 @@ class AdvancedClientSignGenerator {
*/
static getRealMacAddress() {
try {
const interfaces = os.networkInterfaces();
const interfaces = os.networkInterfaces()
for (let interfaceName in interfaces) {
const interface = interfaces[interfaceName];
for (let i = 0; i < interface.length; i++) {
const alias = interface[i];
const networkInterface = interfaces[interfaceName]
for (let i = 0; i < networkInterface.length; i++) {
const alias = networkInterface[i]
// 排除内部地址和无效地址
if (
alias.mac &&
alias.mac !== "00:00:00:00:00:00" &&
alias.mac !== '00:00:00:00:00:00' &&
!alias.internal
) {
return alias.mac.toUpperCase();
return alias.mac.toUpperCase()
}
}
}
return null;
return null
} catch (error) {
console.warn("获取MAC地址失败:", error.message);
return null;
console.warn('获取MAC地址失败:', error.message)
return null
}
}
@@ -33,108 +33,108 @@ class AdvancedClientSignGenerator {
* 生成随机MAC地址
*/
static generateRandomMac() {
const chars = "0123456789ABCDEF";
let mac = "";
const chars = '0123456789ABCDEF'
let mac = ''
for (let i = 0; i < 6; i++) {
if (i > 0) mac += ":";
if (i > 0) mac += ':'
mac +=
chars[Math.floor(Math.random() * 16)] +
chars[Math.floor(Math.random() * 16)];
chars[Math.floor(Math.random() * 16)]
}
// 确保第一个字节是单播地址(最低位为0)
const firstByte = parseInt(mac.substring(0, 2), 16);
const firstByte = parseInt(mac.substring(0, 2), 16)
const unicastFirstByte = (firstByte & 0xfe)
.toString(16)
.padStart(2, "0")
.toUpperCase();
return unicastFirstByte + mac.substring(2);
.padStart(2, '0')
.toUpperCase()
return unicastFirstByte + mac.substring(2)
}
/**
* 获取MAC地址(优先真实,否则随机)
*/
static getMacAddress() {
const realMac = this.getRealMacAddress();
const realMac = this.getRealMacAddress()
if (realMac) {
return realMac;
return realMac
}
console.warn("无法获取真实MAC地址,使用随机生成");
return this.generateRandomMac();
console.warn('无法获取真实MAC地址,使用随机生成')
return this.generateRandomMac()
}
/**
* 字符串转HEX编码
*/
static stringToHex(str) {
return Buffer.from(str, "utf8").toString("hex").toUpperCase();
return Buffer.from(str, 'utf8').toString('hex').toUpperCase()
}
/**
* SHA-256哈希
*/
static sha256(data) {
return crypto.createHash("sha256").update(data, "utf8").digest("hex");
return crypto.createHash('sha256').update(data, 'utf8').digest('hex')
}
/**
* 生成随机设备ID
*/
static generateRandomDeviceId() {
const partLengths = [4, 4, 4, 4, 4, 4, 4, 5]; // 各部分长度
const chars = "0123456789ABCDEF";
const partLengths = [4, 4, 4, 4, 4, 4, 4, 5] // 各部分长度
const chars = '0123456789ABCDEF'
const parts = partLengths.map((length) => {
let part = "";
let part = ''
for (let i = 0; i < length; i++) {
part += chars[Math.floor(Math.random() * 16)];
part += chars[Math.floor(Math.random() * 16)]
}
return part;
});
return part
})
return parts.join("_");
return parts.join('_')
}
/**
* 生成随机clientSign(优先使用真实MAC,否则随机)
*/
static generateRandomClientSign(secretKey = "") {
static generateRandomClientSign(secretKey = '') {
// 获取MAC地址(优先真实,否则随机)
const macAddress = this.getMacAddress();
const macAddress = this.getMacAddress()
// 生成随机设备ID
const deviceId = this.generateRandomDeviceId();
const deviceId = this.generateRandomDeviceId()
// 转换设备ID为HEX
const hexDeviceId = this.stringToHex(deviceId);
const hexDeviceId = this.stringToHex(deviceId)
// 构造签名字符串
const signString = `${macAddress}@@@${hexDeviceId}`;
const signString = `${macAddress}@@@${hexDeviceId}`
// 生成哈希
const hash = this.sha256(signString + secretKey);
const hash = this.sha256(signString + secretKey)
return `${signString}@@@@@@${hash}`;
return `${signString}@@@@@@${hash}`
}
/**
* 批量生成多个随机签名
*/
static generateMultipleRandomSigns(count, secretKey = "") {
const signs = [];
static generateMultipleRandomSigns(count, secretKey = '') {
const signs = []
for (let i = 0; i < count; i++) {
signs.push(this.generateRandomClientSign(secretKey));
signs.push(this.generateRandomClientSign(secretKey))
}
return signs;
return signs
}
/**
* 使用指定参数生成签名
*/
static generateWithCustomDeviceId(macAddress, deviceId, secretKey = "") {
const hexDeviceId = this.stringToHex(deviceId);
const signString = `${macAddress}@@@${hexDeviceId}`;
const hash = this.sha256(signString + secretKey);
return `${signString}@@@@@@${hash}`;
static generateWithCustomDeviceId(macAddress, deviceId, secretKey = '') {
const hexDeviceId = this.stringToHex(deviceId)
const signString = `${macAddress}@@@${hexDeviceId}`
const hash = this.sha256(signString + secretKey)
return `${signString}@@@@@@${hash}`
}
/**
@@ -142,28 +142,28 @@ class AdvancedClientSignGenerator {
*/
static validateClientSign(clientSign) {
try {
const parts = clientSign.split("@@@@@@");
if (parts.length !== 2) return false;
const parts = clientSign.split('@@@@@@')
if (parts.length !== 2) return false
const [infoPart, hash] = parts;
const infoParts = infoPart.split("@@@");
if (infoParts.length !== 2) return false;
const [infoPart, hash] = parts
const infoParts = infoPart.split('@@@')
if (infoParts.length !== 2) return false
const [mac, hexDeviceId] = infoParts;
const [mac, hexDeviceId] = infoParts
// 验证MAC地址格式
const macRegex = /^([0-9A-F]{2}:){5}[0-9A-F]{2}$/;
if (!macRegex.test(mac)) return false;
const macRegex = /^([0-9A-F]{2}:){5}[0-9A-F]{2}$/
if (!macRegex.test(mac)) return false
// 验证哈希格式
const hashRegex = /^[0-9a-f]{64}$/;
if (!hashRegex.test(hash)) return false;
const hashRegex = /^[0-9a-f]{64}$/
if (!hashRegex.test(hash)) return false
return true;
return true
} catch (error) {
return false;
return false
}
}
}
module.exports = AdvancedClientSignGenerator;
module.exports = AdvancedClientSignGenerator
+37 -23
View File
@@ -1,28 +1,42 @@
// ANSI 颜色代码
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m',
black: '\x1b[30m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
bgRed: '\x1b[41m',
bgGreen: '\x1b[42m',
bgYellow: '\x1b[43m'
};
reset: '\x1b[0m',
bright: '\x1b[1m',
dim: '\x1b[2m',
black: '\x1b[30m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
white: '\x1b[37m',
bgRed: '\x1b[41m',
bgGreen: '\x1b[42m',
bgYellow: '\x1b[43m',
}
const logger = {
debug: (msg, ...args) => console.info(`${colors.cyan}[DEBUG]${colors.reset}`, msg, ...args),
info: (msg, ...args) => console.info(`${colors.green}[INFO]${colors.reset}`, msg, ...args),
warn: (msg, ...args) => console.info(`${colors.yellow}[WARN]${colors.reset}`, msg, ...args),
error: (msg, ...args) => console.error(`${colors.red}[ERROR]${colors.reset}`, msg, ...args),
success: (msg, ...args) => console.log(`${colors.bright}${colors.green}[SUCCESS]${colors.reset}`, msg, ...args),
critical: (msg, ...args) => console.error(`${colors.bright}${colors.bgRed}[CRITICAL]${colors.reset}`, msg, ...args)
};
debug: (msg, ...args) =>
console.info(`${colors.cyan}[DEBUG]${colors.reset}`, msg, ...args),
info: (msg, ...args) =>
console.info(`${colors.green}[INFO]${colors.reset}`, msg, ...args),
warn: (msg, ...args) =>
console.info(`${colors.yellow}[WARN]${colors.reset}`, msg, ...args),
error: (msg, ...args) =>
console.error(`${colors.red}[ERROR]${colors.reset}`, msg, ...args),
success: (msg, ...args) =>
console.log(
`${colors.bright}${colors.green}[SUCCESS]${colors.reset}`,
msg,
...args,
),
critical: (msg, ...args) =>
console.error(
`${colors.bright}${colors.bgRed}[CRITICAL]${colors.reset}`,
msg,
...args,
),
}
module.exports = logger;
module.exports = logger
+8 -6
View File
@@ -101,7 +101,7 @@ const SPECIAL_STATUS_CODES = new Set([201, 302, 400, 502, 800, 801, 802, 803])
// chooseUserAgent函数
const chooseUserAgent = (crypto, uaType = 'pc') => {
return userAgentMap[crypto]?.[uaType] || ''
return (userAgentMap[crypto] && userAgentMap[crypto][uaType]) || ''
}
// cookie处理
@@ -153,15 +153,17 @@ const createHeaderCookie = (header) => {
const generateRequestId = () => {
return `${now()}_${floor(random() * 1000)
.toString()
.padStart(4, "0")}`;
.padStart(4, '0')}`
}
const createRequest = (uri, data, options) => {
return new Promise((resolve, reject) => {
// 变量声明和初始化
const headers = options.headers ? { ...options.headers } : {}
const ip = options.realIP || options.ip || (options.randomCNIP ? generateRandomChineseIP() : '')
const ip =
options.realIP ||
options.ip ||
(options.randomCNIP ? generateRandomChineseIP() : '')
// IP头设置
if (ip) {
headers['X-Real-IP'] = ip
@@ -243,8 +245,8 @@ const createRequest = (uri, data, options) => {
options.e_r !== undefined
? options.e_r
: data.e_r !== undefined
? data.e_r
: ENCRYPT_RESPONSE,
? data.e_r
: ENCRYPT_RESPONSE,
)
encryptData = encrypt.eapi(uri, data)
url = API_DOMAIN + '/eapi/' + uri.substr(5)