部分脚本 API 请求增加 timeout=3000,防止 API 请求超时导致进程僵死

This commit is contained in:
guyuexuan
2021-01-13 15:39:13 +08:00
parent 569786772b
commit 0715d79954
3 changed files with 21 additions and 12 deletions

View File

@ -1167,7 +1167,8 @@ async function initForFarm() {
"sec-fetch-site": "same-site",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0"),
"Content-Type": "application/x-www-form-urlencoded"
}
},
timeout: 3000,
};
$.post(option, (err, resp, data) => {
try {
@ -1239,7 +1240,7 @@ function timeFormat(time) {
}
function readShareCode() {
return new Promise(async resolve => {
$.get({url: `http://api.turinglabs.net/api/v1/jd/farm/read/${randomCount}/`}, (err, resp, data) => {
$.get({url: `http://api.turinglabs.net/api/v1/jd/farm/read/${randomCount}/`, timeout: 3000,}, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
@ -1355,7 +1356,8 @@ function TotalBean() {
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
},
"timeout": 3000,
}
$.post(options, (err, resp, data) => {
try {
@ -1423,7 +1425,8 @@ function taskUrl(function_id, body = {}) {
headers: {
Cookie: cookie,
UserAgent: $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0"),
}
},
timeout: 3000,
}
}
// prettier-ignore

View File

@ -503,7 +503,8 @@ function queryVkComponent() {
"Host": `api.m.jd.com`,
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0"),
"Accept-Language": `zh-Hans-CN;q=1, en-CN;q=0.9`,
}
},
"timeout": 3000,
}
$.post(options, (err, resp, data) => {
try {
@ -621,7 +622,7 @@ function jdfactory_getHomeData() {
function readShareCode() {
console.log(`开始`)
return new Promise(async resolve => {
$.get({url: `http://api.turinglabs.net/api/v1/jd/ddfactory/read/${randomCount}/`}, (err, resp, data) => {
$.get({url: `http://api.turinglabs.net/api/v1/jd/ddfactory/read/${randomCount}/`, timeout: 3000}, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
@ -695,7 +696,8 @@ function taskPostUrl(function_id, body = {}, function_id2) {
"referer": "https://h5.m.jd.com/",
'Content-Type': 'application/x-www-form-urlencoded',
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0"),
}
},
timeout: 3000,
}
}
function TotalBean() {
@ -711,7 +713,8 @@ function TotalBean() {
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
},
"timeout": 3000,
}
$.post(options, (err, resp, data) => {
try {

View File

@ -514,7 +514,7 @@ async function plantBeanIndex() {
}
function readShareCode() {
return new Promise(async resolve => {
$.get({url: `http://api.turinglabs.net/api/v1/jd/bean/read/${randomCount}/`}, (err, resp, data) => {
$.get({url: `http://api.turinglabs.net/api/v1/jd/bean/read/${randomCount}/`, timeout: 3000}, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
@ -635,7 +635,8 @@ function requestGet(function_id, body = {}) {
'Accept-Language': 'zh-Hans-CN;q=1,en-CN;q=0.9',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': "application/x-www-form-urlencoded"
}
},
timeout: 3000,
};
$.get(option, (err, resp, data) => {
try {
@ -666,7 +667,8 @@ function TotalBean() {
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
}
},
"timeout": 3000,
}
$.post(options, (err, resp, data) => {
try {
@ -729,7 +731,8 @@ function taskUrl(function_id, body) {
"Accept-Language": "zh-Hans-CN;q=1,en-CN;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/x-www-form-urlencoded"
}
},
timeout: 3000,
}
}
function getParam(url, name) {