mirror of https://github.com/6dylan6/jdpro.git
This commit is contained in:
parent
6614f2c87b
commit
08f3a368b6
304
jdCookie.js
304
jdCookie.js
|
@ -3,26 +3,26 @@
|
||||||
*/
|
*/
|
||||||
//此处填写京东账号cookie。
|
//此处填写京东账号cookie。
|
||||||
let CookieJDs = [
|
let CookieJDs = [
|
||||||
'',//账号一ck,例:pt_key=XXX;pt_pin=XXX;
|
'',//账号一ck,例:pt_key=XXX;pt_pin=XXX;
|
||||||
'',//账号二ck,例:pt_key=XXX;pt_pin=XXX;如有更多,依次类推
|
'',//账号二ck,例:pt_key=XXX;pt_pin=XXX;如有更多,依次类推
|
||||||
]
|
]
|
||||||
let IP = '';
|
let IP = '';
|
||||||
// 判断环境变量里面是否有京东ck
|
// 判断环境变量里面是否有京东ck
|
||||||
if (process.env.JD_COOKIE) {
|
if (process.env.JD_COOKIE) {
|
||||||
if (process.env.JD_COOKIE.indexOf('&') > -1) {
|
if (process.env.JD_COOKIE.indexOf('&') > -1) {
|
||||||
CookieJDs = process.env.JD_COOKIE.split('&');
|
CookieJDs = process.env.JD_COOKIE.split('&');
|
||||||
} else if (process.env.JD_COOKIE.indexOf('\n') > -1) {
|
} else if (process.env.JD_COOKIE.indexOf('\n') > -1) {
|
||||||
CookieJDs = process.env.JD_COOKIE.split('\n');
|
CookieJDs = process.env.JD_COOKIE.split('\n');
|
||||||
} else {
|
} else {
|
||||||
CookieJDs = [process.env.JD_COOKIE];
|
CookieJDs = [process.env.JD_COOKIE];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (JSON.stringify(process.env).indexOf('GITHUB') > -1) {
|
if (JSON.stringify(process.env).indexOf('GITHUB') > -1) {
|
||||||
console.log(`请勿使用github action运行此脚本,无论你是从你自己的私库还是其他哪里拉取的源代码,都会导致我被封号\n`);
|
console.log(`请勿使用github action运行此脚本,无论你是从你自己的私库还是其他哪里拉取的源代码,都会导致我被封号\n`);
|
||||||
!(async () => {
|
!(async () => {
|
||||||
await require('./sendNotify').sendNotify('提醒', `请勿使用github action、滥用github资源会封我仓库以及账号`)
|
await require('./sendNotify').sendNotify('提醒', `请勿使用github action、滥用github资源会封我仓库以及账号`)
|
||||||
await process.exit(0);
|
await process.exit(0);
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
//!(async () => {
|
//!(async () => {
|
||||||
// IP = await getIP();
|
// IP = await getIP();
|
||||||
|
@ -34,171 +34,173 @@ if (JSON.stringify(process.env).indexOf('GITHUB') > -1) {
|
||||||
CookieJDs = [...new Set(CookieJDs.filter(item => !!item))]
|
CookieJDs = [...new Set(CookieJDs.filter(item => !!item))]
|
||||||
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { };
|
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { };
|
||||||
if (process.env.BANPIN) {
|
if (process.env.BANPIN) {
|
||||||
try {
|
try {
|
||||||
let banpin = process.env.BANPIN;
|
let banpin = process.env.BANPIN;
|
||||||
if (banpin.includes('@')) {
|
if (banpin.includes('@')) {
|
||||||
const arr = banpin.split('&');
|
const arr = banpin.split('&');
|
||||||
for (let i of arr) {
|
for (let i of arr) {
|
||||||
//if (process.mainModule.filename.includes(i.split('^')[0])) {
|
//if (process.mainModule.filename.includes(i.split('^')[0])) {
|
||||||
if (i.split('@')[0].split('|').filter(x => process.argv[1].includes(x)).length != 0) {
|
if (i.split('@')[0].split('|').filter(x => process.argv[1].includes(x)).length != 0) {
|
||||||
let pinarr = i.split('@')[1].split(',');
|
let pinarr = i.split('@')[1].split(',');
|
||||||
console.log(`已配置该任务不执行pin: ${JSON.stringify(pinarr)}`);
|
console.log(`已配置该任务不执行pin: ${JSON.stringify(pinarr)}`);
|
||||||
for (let j of pinarr) {
|
for (let j of pinarr) {
|
||||||
CookieJDs = CookieJDs.filter(x => !x.includes(decodeURIComponent(j)));
|
j = decodeURIComponent(j);
|
||||||
}
|
CookieJDs = CookieJDs.filter(x => !x.includes(encodeURIComponent(j)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
let pinarr = banpin.split(',');
|
||||||
|
console.log(`已配置全局不执行pin: ${JSON.stringify(pinarr)}`);
|
||||||
|
for (let i of pinarr) {
|
||||||
|
j = decodeURIComponent(j);
|
||||||
|
CookieJDs = CookieJDs.filter(x => !x.includes(encodeURIComponent(i)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} catch { }
|
||||||
|
|
||||||
} else {
|
|
||||||
let pinarr = banpin.split(',');
|
|
||||||
console.log(`已配置全局不执行pin: ${JSON.stringify(pinarr)}`);
|
|
||||||
for (let i of pinarr) {
|
|
||||||
CookieJDs = CookieJDs.filter(x => !x.includes(decodeURIComponent(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch { }
|
|
||||||
}
|
}
|
||||||
console.log(`\n====================共${CookieJDs.length}个京东账号Cookie=================`);
|
console.log(`\n====================共${CookieJDs.length}个京东账号Cookie=================`);
|
||||||
console.log(`===========脚本执行时间:${formatdate(new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000))}============`);
|
console.log(`===========脚本执行时间:${formatdate(new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000))}============`);
|
||||||
console.log('>>>>>>>>>>>>6Dy提醒您:有问题先更新不行在反馈>>>>>>>>>>>>>\n');
|
console.log('>>>>>>>>>>>>6dylan6提醒您:有问题先更新不行在反馈>>>>>>>>>>>>>\n');
|
||||||
|
|
||||||
for (let i = 0; i < CookieJDs.length; i++) {
|
for (let i = 0; i < CookieJDs.length; i++) {
|
||||||
if (!CookieJDs[i].match(/pt_pin=(.+?);/) || !CookieJDs[i].match(/pt_key=(.+?);/)) console.log(`\n提示:京东cookie 【${CookieJDs[i]}】填写不规范,可能会影响部分脚本正常使用。正确格式为: pt_key=xxx;pt_pin=xxx;(分号;不可少)\n`);
|
if (!CookieJDs[i].match(/pt_pin=(.+?);/) || !CookieJDs[i].match(/pt_key=(.+?);/)) console.log(`\n提示:京东cookie 【${CookieJDs[i]}】填写不规范,可能会影响部分脚本正常使用。正确格式为: pt_key=xxx;pt_pin=xxx;(分号;不可少)\n`);
|
||||||
CookieJDs[i] = CookieJDs[i].replace(/[\u4e00-\u9fa5]/g, (str) => encodeURI(str));
|
CookieJDs[i] = CookieJDs[i].replace(/[\u4e00-\u9fa5]/g, (str) => encodeURI(str));
|
||||||
const index = (i + 1 === 1) ? '' : (i + 1);
|
const index = (i + 1 === 1) ? '' : (i + 1);
|
||||||
exports['CookieJD' + index] = CookieJDs[i].trim();
|
exports['CookieJD' + index] = CookieJDs[i].trim();
|
||||||
}
|
}
|
||||||
let permit = process.env.PERMIT_JS ? process.env.PERMIT_JS.split('&') : '';
|
let permit = process.env.PERMIT_JS ? process.env.PERMIT_JS.split('&') : '';
|
||||||
|
|
||||||
if (process.env.DP_POOL) {
|
if (process.env.DP_POOL) {
|
||||||
if (permit && permit.filter(x => process.mainModule.filename.includes(x)).length != 0) {
|
if (permit && permit.filter(x => process.mainModule.filename.includes(x)).length != 0) {
|
||||||
try {
|
try {
|
||||||
require("global-agent/bootstrap");
|
require("global-agent/bootstrap");
|
||||||
global.GLOBAL_AGENT.HTTP_PROXY = process.env.DP_POOL;
|
global.GLOBAL_AGENT.HTTP_PROXY = process.env.DP_POOL;
|
||||||
console.log(`\n---------------使用代理池模式---------------\n`);
|
console.log(`\n---------------使用代理池模式---------------\n`);
|
||||||
} catch {
|
} catch {
|
||||||
throw new Error(`请安装global-agent依赖,才能启用代理!`);
|
throw new Error(`请安装global-agent依赖,才能启用代理!`);
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
function getIP() {
|
function getIP() {
|
||||||
const https = require('https');
|
const https = require('https');
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
let opt = {
|
let opt = {
|
||||||
hostname: "www.cip.cc",
|
hostname: "www.cip.cc",
|
||||||
port: 443,
|
port: 443,
|
||||||
path: "/",
|
path: "/",
|
||||||
method: "GET",
|
method: "GET",
|
||||||
headers: {
|
headers: {
|
||||||
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
|
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36',
|
||||||
},
|
},
|
||||||
timeout: 5000
|
timeout: 5000
|
||||||
}
|
}
|
||||||
const req = https.request(opt, (res) => {
|
const req = https.request(opt, (res) => {
|
||||||
res.setEncoding('utf-8');
|
res.setEncoding('utf-8');
|
||||||
let tmp = '';
|
let tmp = '';
|
||||||
res.on('error', reject);
|
res.on('error', reject);
|
||||||
res.on('data', d => tmp += d);
|
res.on('data', d => tmp += d);
|
||||||
res.on('end', () => resolve(tmp));
|
res.on('end', () => resolve(tmp));
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', reject);
|
req.on('error', reject);
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 以下为注入互助码环境变量(仅nodejs内起效)的代码
|
// 以下为注入互助码环境变量(仅nodejs内起效)的代码
|
||||||
function SetShareCodesEnv(nameChinese = "", nameConfig = "", envName = "") {
|
function SetShareCodesEnv(nameChinese = "", nameConfig = "", envName = "") {
|
||||||
let rawCodeConfig = {}
|
let rawCodeConfig = {}
|
||||||
let fs = require('fs')
|
let fs = require('fs')
|
||||||
// 读取互助码
|
// 读取互助码
|
||||||
let shareCodeLogPath = fs.existsSync(`${process.env.QL_DIR}/data`) ? `${process.env.QL_DIR}/data/log/.ShareCode/${nameConfig}.log` : `${process.env.QL_DIR}/log/.ShareCode/${nameConfig}.log`;
|
let shareCodeLogPath = fs.existsSync(`${process.env.QL_DIR}/data`) ? `${process.env.QL_DIR}/data/log/.ShareCode/${nameConfig}.log` : `${process.env.QL_DIR}/log/.ShareCode/${nameConfig}.log`;
|
||||||
if (fs.existsSync(shareCodeLogPath)) {
|
if (fs.existsSync(shareCodeLogPath)) {
|
||||||
// 因为faker2目前没有自带ini,改用已有的dotenv来解析
|
// 因为faker2目前没有自带ini,改用已有的dotenv来解析
|
||||||
// // 利用ini模块读取原始互助码和互助组信息
|
// // 利用ini模块读取原始互助码和互助组信息
|
||||||
// let ini = require('ini')
|
// let ini = require('ini')
|
||||||
// rawCodeConfig = ini.parse(fs.readFileSync(shareCodeLogPath, 'utf-8'))
|
// rawCodeConfig = ini.parse(fs.readFileSync(shareCodeLogPath, 'utf-8'))
|
||||||
|
|
||||||
// 使用env模块
|
// 使用env模块
|
||||||
require('dotenv').config({ path: shareCodeLogPath })
|
require('dotenv').config({ path: shareCodeLogPath })
|
||||||
rawCodeConfig = process.env
|
rawCodeConfig = process.env
|
||||||
}
|
|
||||||
|
|
||||||
// 解析每个用户的互助码
|
|
||||||
let codes = {}
|
|
||||||
Object.keys(rawCodeConfig).forEach(function (key) {
|
|
||||||
if (key.startsWith(`My${nameConfig}`)) {
|
|
||||||
codes[key] = rawCodeConfig[key]
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// 解析每个用户要帮助的互助码组,将用户实际的互助码填充进去
|
// 解析每个用户的互助码
|
||||||
let helpOtherCodes = {}
|
let codes = {}
|
||||||
Object.keys(rawCodeConfig).forEach(function (key) {
|
Object.keys(rawCodeConfig).forEach(function (key) {
|
||||||
if (key.startsWith(`ForOther${nameConfig}`)) {
|
if (key.startsWith(`My${nameConfig}`)) {
|
||||||
let helpCode = rawCodeConfig[key]
|
codes[key] = rawCodeConfig[key]
|
||||||
for (const [codeEnv, codeVal] of Object.entries(codes)) {
|
}
|
||||||
helpCode = helpCode.replace("${" + codeEnv + "}", codeVal)
|
});
|
||||||
}
|
|
||||||
|
|
||||||
helpOtherCodes[key] = helpCode
|
// 解析每个用户要帮助的互助码组,将用户实际的互助码填充进去
|
||||||
|
let helpOtherCodes = {}
|
||||||
|
Object.keys(rawCodeConfig).forEach(function (key) {
|
||||||
|
if (key.startsWith(`ForOther${nameConfig}`)) {
|
||||||
|
let helpCode = rawCodeConfig[key]
|
||||||
|
for (const [codeEnv, codeVal] of Object.entries(codes)) {
|
||||||
|
helpCode = helpCode.replace("${" + codeEnv + "}", codeVal)
|
||||||
|
}
|
||||||
|
|
||||||
|
helpOtherCodes[key] = helpCode
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 按顺序用&拼凑到一起,并放入环境变量,供目标脚本使用
|
||||||
|
let shareCodes = []
|
||||||
|
let leftIndex = 1, rightIndex = Object.keys(helpOtherCodes).length
|
||||||
|
|
||||||
|
// 判断是否是ptask并行触发,若是,则修改实际需要设置的互助码范围
|
||||||
|
let ptaskLeft = process.env.PTASK_LEFT
|
||||||
|
let ptaskRight = process.env.PTASK_RIGHT
|
||||||
|
if (ptaskLeft && ptaskRight) {
|
||||||
|
leftIndex = Number(ptaskLeft)
|
||||||
|
rightIndex = Number(ptaskRight)
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
// 按顺序用&拼凑到一起,并放入环境变量,供目标脚本使用
|
for (let idx = leftIndex; idx <= rightIndex; idx++) {
|
||||||
let shareCodes = []
|
shareCodes.push(helpOtherCodes[`ForOther${nameConfig}${idx}`])
|
||||||
let leftIndex = 1, rightIndex = Object.keys(helpOtherCodes).length
|
}
|
||||||
|
let shareCodesStr = shareCodes.join('&')
|
||||||
|
process.env[envName] = shareCodesStr
|
||||||
|
|
||||||
// 判断是否是ptask并行触发,若是,则修改实际需要设置的互助码范围
|
let totalCodeCount = rightIndex - leftIndex + 1
|
||||||
let ptaskLeft = process.env.PTASK_LEFT
|
//console.info(`${nameChinese}的 互助码环境变量 ${envName},共计 ${totalCodeCount} 组互助码,总大小为 ${shareCodesStr.length} 字节`)
|
||||||
let ptaskRight = process.env.PTASK_RIGHT
|
|
||||||
if (ptaskLeft && ptaskRight) {
|
|
||||||
leftIndex = Number(ptaskLeft)
|
|
||||||
rightIndex = Number(ptaskRight)
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let idx = leftIndex; idx <= rightIndex; idx++) {
|
|
||||||
shareCodes.push(helpOtherCodes[`ForOther${nameConfig}${idx}`])
|
|
||||||
}
|
|
||||||
let shareCodesStr = shareCodes.join('&')
|
|
||||||
process.env[envName] = shareCodesStr
|
|
||||||
|
|
||||||
let totalCodeCount = rightIndex - leftIndex + 1
|
|
||||||
//console.info(`${nameChinese}的 互助码环境变量 ${envName},共计 ${totalCodeCount} 组互助码,总大小为 ${shareCodesStr.length} 字节`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断当前活动脚本是否在互助脚本列表中
|
// 判断当前活动脚本是否在互助脚本列表中
|
||||||
function IsShareJsFile() {
|
function IsShareJsFile() {
|
||||||
// 尝试获取在task_before.sh中设置的 互助活动的脚本文件名的关键部分 列表
|
// 尝试获取在task_before.sh中设置的 互助活动的脚本文件名的关键部分 列表
|
||||||
let rawJsNameList = process.env.ShareCodeJSNameList
|
let rawJsNameList = process.env.ShareCodeJSNameList
|
||||||
if (!rawJsNameList) {
|
if (!rawJsNameList) {
|
||||||
return false
|
return false
|
||||||
}
|
|
||||||
|
|
||||||
// 转换为list
|
|
||||||
let jsNameList = process.env.ShareCodeJSNameList.split(" ")
|
|
||||||
|
|
||||||
// 判断当前
|
|
||||||
let currentActivityScriptFileName = GetCurrentActivityScriptFileName()
|
|
||||||
|
|
||||||
let isShareJsFile = false
|
|
||||||
for (let idx = 0; idx < jsNameList.length; idx++) {
|
|
||||||
if (currentActivityScriptFileName.includes(jsNameList[idx])) {
|
|
||||||
isShareJsFile = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return isShareJsFile
|
// 转换为list
|
||||||
|
let jsNameList = process.env.ShareCodeJSNameList.split(" ")
|
||||||
|
|
||||||
|
// 判断当前
|
||||||
|
let currentActivityScriptFileName = GetCurrentActivityScriptFileName()
|
||||||
|
|
||||||
|
let isShareJsFile = false
|
||||||
|
for (let idx = 0; idx < jsNameList.length; idx++) {
|
||||||
|
if (currentActivityScriptFileName.includes(jsNameList[idx])) {
|
||||||
|
isShareJsFile = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return isShareJsFile
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取当前活动脚本的文件名
|
// 获取当前活动脚本的文件名
|
||||||
function GetCurrentActivityScriptFileName() {
|
function GetCurrentActivityScriptFileName() {
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
return path.basename(process.argv[1])
|
return path.basename(process.argv[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 若在task_before.sh 中设置了要设置互助码环境变量的活动名称和环境变量名称信息,则在nodejs中处理,供活动使用
|
// 若在task_before.sh 中设置了要设置互助码环境变量的活动名称和环境变量名称信息,则在nodejs中处理,供活动使用
|
||||||
|
@ -206,14 +208,14 @@ let nameChinese = process.env.ShareCodeConfigChineseName
|
||||||
let nameConfig = process.env.ShareCodeConfigName
|
let nameConfig = process.env.ShareCodeConfigName
|
||||||
let envName = process.env.ShareCodeEnvName
|
let envName = process.env.ShareCodeEnvName
|
||||||
if (nameChinese && nameConfig && envName) {
|
if (nameChinese && nameConfig && envName) {
|
||||||
SetShareCodesEnv(nameChinese, nameConfig, envName)
|
SetShareCodesEnv(nameChinese, nameConfig, envName)
|
||||||
}
|
}
|
||||||
function formatdate(date) {
|
function formatdate(date) {
|
||||||
const year = date.getFullYear();
|
const year = date.getFullYear();
|
||||||
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
const month = ('0' + (date.getMonth() + 1)).slice(-2);
|
||||||
const day = ('0' + date.getDate()).slice(-2);
|
const day = ('0' + date.getDate()).slice(-2);
|
||||||
const hours = ('0' + date.getHours()).slice(-2);
|
const hours = ('0' + date.getHours()).slice(-2);
|
||||||
const minutes = ('0' + date.getMinutes()).slice(-2);
|
const minutes = ('0' + date.getMinutes()).slice(-2);
|
||||||
const seconds = ('0' + date.getSeconds()).slice(-2);
|
const seconds = ('0' + date.getSeconds()).slice(-2);
|
||||||
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
|
return `${year}/${month}/${day} ${hours}:${minutes}:${seconds}`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue