Commit 0c8ef7ab authored by Medicean's avatar Medicean Committed by Medicean

Code(Modules/request): 调整 superagent ignoreHTTPS 注入,避免 npm upgrade之后引发问题

parent 57aa049b
......@@ -66,10 +66,22 @@
* 支持自定义 Content-Type, 默认是 `form`
* Fix #307
* 重新规整 `modules/request.js` 代码结构
### 设置模块
* 优化了新增Core类型时,编码设置解析逻辑, 现在不需要再改该模块的源代码了
* 优化全局代理设置, 代理在设置完后不需要再重启了
### 其它
* 更新纯真IP数据库为 2022/04/20 (https://github.com/out0fmemory/qqwry.dat)
> 如需自己更新请下载后替换 `static/libs/qqwry.dat` 文件
* 升级 superagent 到 6.1.0 (再高的版本需要高版本Electron支持)
* 升级 superagent-proxy 到 v3.0.0
## 2021/07/25 `v(2.1.14)`
......
......@@ -10,7 +10,7 @@ const fs = require('fs'),
path = require('path'),
CONF = require('./config'),
Datastore = require('nedb'),
qqwry = require("geoips").info();
qqwry = require("geoips").info(path.join(__dirname, '../static/libs/qqwry.dat'));
var logger;
......@@ -50,15 +50,13 @@ class Database {
}
convertOptstoNedbQuery(opts = {}) {
var self = this;
if (opts instanceof Array) {
for (let i = 0; i < opts.length; i++) {
opts[i] = self.convertOptstoNedbQuery(opts[i]);
}
} else if (opts instanceof Object) {
Object
.keys(opts)
.map((f) => {
var self = this;
if (opts instanceof Array) {
for (let i = 0; i < opts.length; i++) {
opts[i] = self.convertOptstoNedbQuery(opts[i]);
}
} else if (opts instanceof Object) {
Object.keys(opts).map((f) => {
if (opts[f] instanceof Object) {
opts[f] = self.convertOptstoNedbQuery(opts[f]);
}
......@@ -69,15 +67,15 @@ class Database {
opts[f] = new RegExp(opts[f], 'i');
}
});
}
return opts;
}
return opts;
}
/**
* 查询shell数据
* @param {Object} event ipcMain对象
* @param {Object} opts 查询配置
* @return {[type]} [description]
*/
/**
* 查询shell数据
* @param {Object} event ipcMain对象
* @param {Object} opts 查询配置
* @return {[type]} [description]
*/
findShell(event, opts = {}) {
opts = this.convertOptstoNedbQuery(opts);
logger.debug('findShell', opts);
......@@ -460,42 +458,42 @@ class Database {
* @param {Object} opts 配置(_id,data
*/
addPluginDataConf(event, plugin, opts) {
logger.info('addPluginDataConf', plugin, opts);
// 1. 获取原配置列表
this
.cursor
.findOne({
_id: opts['_id']
}, (err, ret) => {
ret['plugins'] = ret['plugins'] || {};
let confs = ret['plugins'][plugin] || {};
// 随机Id(顺序增长
const random_id = parseInt(+new Date + Math.random() * 1000).toString(16);
// 添加到配置
confs[random_id] = opts['data'];
let setdata = {
utime: +new Date
}
setdata[`plugins.${plugin}`] = confs;
logger.info('addPluginDataConf', plugin, opts);
// 1. 获取原配置列表
this
.cursor
.findOne({
_id: opts['_id']
}, (err, ret) => {
ret['plugins'] = ret['plugins'] || {};
let confs = ret['plugins'][plugin] || {};
// 随机Id(顺序增长
const random_id = parseInt(+new Date + Math.random() * 1000).toString(16);
// 添加到配置
confs[random_id] = opts['data'];
let setdata = {
utime: +new Date
}
setdata[`plugins.${plugin}`] = confs;
// 更新
this
.cursor
.update({
_id: opts['_id']
}, {
$set: setdata
}, (_err, _ret) => {
event.returnValue = random_id;
});
});
}
/**
* 修改插件数据配置
* @param {Object} event ipcMain对象
* @param {string} plugin 插件注册的名称
* @param {Object} opts 配置(_id,id,data
*/
// 更新
this
.cursor
.update({
_id: opts['_id']
}, {
$set: setdata
}, (_err, _ret) => {
event.returnValue = random_id;
});
});
}
/**
* 修改插件数据配置
* @param {Object} event ipcMain对象
* @param {string} plugin 插件注册的名称
* @param {Object} opts 配置(_id,id,data
*/
editPluginDataConf(event, plugin, opts) {
logger.info('editPluginDataConf', plugin, opts);
// 1. 获取原配置列表
......
......@@ -30,6 +30,17 @@ const APROXY_CONF = {
uri: ''
}
/**
* 忽略 HTTPS 证书校验 SuperAgent patch
* @param {bool} ignore
* @api public
*/
superagent.Request.prototype.ignoreHTTPS = function(ignore) {
this._ignoreHttps = !ignore;
process.env.NODE_TLS_REJECT_UNAUTHORIZED = ignore ? '0' : undefined;
return this;
};
class Request {
constructor(electron) {
......@@ -176,7 +187,7 @@ class Request {
.type(self.reqContentType)
// .set('Content-Type', 'application/x-www-form-urlencoded')
.timeout(opts.timeout || REQ_TIMEOUT)
.ignoreHTTPS(opts['ignoreHTTPS'])
.ignoreHTTPS(opts['ignoreHTTPS']);
if (opts['useChunk'] == 1) {
logger.debug("request with Chunked");
let antstream;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment