Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
data.agent = conf.RPC_HTTP_AGENT;
}
if (conf.RPC_HTTPS_AGENT) {
data.httpsAgent = conf.RPC_HTTPS_AGENT;
}
if (Buffer.isBuffer(requestForm) || typeof requestForm === 'string') {
data.content = requestForm;
} else if (requestForm) {
data.stream = requestForm;
} else {
data.headers['Content-Length'] = 0;
}
var req = urllib.request(requestURI, data, function (respErr, respBody,
respInfo) {
// var end = parseInt(Date.now() / 1000);
// console.log((end - start) + " seconds");
// console.log("queuing:\t" + respInfo.timing.queuing);
// console.log("dnslookup:\t" + respInfo.timing.dnslookup);
// console.log("connected:\t" + respInfo.timing.connected);
// console.log("requestSent:\t" + respInfo.timing.requestSent);
// console.log("waiting:\t" + respInfo.timing.waiting);
// console.log("contentDownload:\t" + respInfo.timing.contentDownload);
callbackFunc(respErr, respBody, respInfo);
});
return req;
}
// const downloadURLs = {
// linux: '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip',
// mac: '%s/chromium-browser-snapshots/Mac/%d/%s.zip',
// win32: '%s/chromium-browser-snapshots/Win/%d/%s.zip',
// win64: '%s/chromium-browser-snapshots/Win_x64/%d/%s.zip',
// };
let existsCount = 0;
const existDirResults = yield parentDirs.map(name => this.listExists('/' + name + '/'));
const existDirsMap = {};
for (const rows of existDirResults) {
for (const row of rows) {
existDirsMap[row.parent + row.name] = true;
}
}
const result = yield urllib.request(this._npmPackageUrl, {
timeout: 60000,
dataType: 'json',
gzip: true,
followRedirect: true,
});
const versions = result.data.versions || {};
const chromium_revisions = {};
for (var version in versions) {
const pkg = versions[version];
const puppeteerInfo = pkg.puppeteer || {};
if (!puppeteerInfo.chromium_revision) continue;
if (chromium_revisions[puppeteerInfo.chromium_revision]) continue;
const publish_time = result.data.time[pkg.version];
chromium_revisions[puppeteerInfo.chromium_revision] = publish_time;
}
File.prototype.request = function(url, cb) {
var that = this;
var opt = {
gzip: true,
followRedirect: false,
rejectUnauthorized: false,
};
request(url, opt, function(err, data, res) {
if (err) {
that.emit('not found', url);
return cb(err);
}
if (res.statusCode >= 300) {
that.emit('not found', url);
return cb(new Error(res.statusCode));
}
that.emit('found', url);
cb(null, {
headers: shouldGetHeader(that.options) ? getOriginalHeader(res.headers) : null,
data: data,
});
});
exports._deleteGoodsGroup = function (groupId, callback) {
var data = {
"group_id": groupId
};
var url = this.merchantPrefix + 'group/del?access_token=' + this.token.accessToken;
urllib.request(url, postJSON(data), wrapper(callback));
};
function exchangeAccessToken(app_id, app_secret, code, callback){
var url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + app_id + "&secret=" + app_secret + "&code=" + code + "&grant_type=authorization_code";
var opts = {
dataType: 'json',
type: 'GET'
};
urllib.request(url, opts, function(err, body, resp){
if(err){
callback(err);
return;
}
if(body.errcode){
callback(body);
return;
}
callback(null, body);
});
}
var url = "https://api.weixin.qq.com/cgi-bin/groups/members/update?access_token=" + access_token;
var options = {
method: "POST",
dataType: "json",
headers: {
'Content-Type': 'application/json'
},
data: {
openid: fan_open_id,
to_groupid: to_group_id
}
};
urllib.request(url, options, function(err, body, resp){
if(err){
callback(err);
return;
}
if(body.errcode !== 0){
callback(body);
return;
}
callback(null);
});
}
extend(options, this.defaults);
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
for (var key in opts) {
if (key !== 'headers') {
options[key] = opts[key];
} else {
if (opts.headers) {
options.headers = options.headers || {};
extend(options.headers, opts.headers);
}
}
}
urllib.request(url, options, callback);
};
async function _get(url, options, retry, globalOptions) {
try {
return await urllib.request(url, options);
} catch (err) {
retry--;
if (retry > 0) {
const delay = 100 * (MAX_RETRY - retry);
const logger = globalOptions && globalOptions.console || console;
logger.warn('[npminstall:get] retry GET %s after %sms, retry left %s, error: %s, status: %s, headers: %j, \nstack: %s',
url, delay, retry, err, err.status, err.headers, err.stack);
await utils.sleep(delay);
return await _get(url, options, retry, globalOptions);
}
throw err;
}
}
function queryMenu(access_token, callback){
var url = "https://api.weixin.qq.com/cgi-bin/menu/get?access_token=" + access_token;
var options = {
method: "GET",
dataType: "json"
};
urllib.request(url, options, function(err, body, resp){
if(err){
callback(err);
return;
}
if(body.errcode){
callback(body);
return;
}
callback(null, body);
});
}
function* _request(url, options, retry) {
try {
return yield urllib.request(url, options);
} catch (e) {
if (retry > 0) {
retry--;
return yield _request(url, options, retry);
}
throw e;
}
}