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

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

parent 57aa049b
...@@ -66,10 +66,22 @@ ...@@ -66,10 +66,22 @@
* 支持自定义 Content-Type, 默认是 `form` * 支持自定义 Content-Type, 默认是 `form`
* Fix #307 * Fix #307
* 重新规整 `modules/request.js` 代码结构
### 设置模块 ### 设置模块
* 优化了新增Core类型时,编码设置解析逻辑, 现在不需要再改该模块的源代码了 * 优化了新增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)` ## 2021/07/25 `v(2.1.14)`
......
...@@ -10,7 +10,7 @@ const fs = require('fs'), ...@@ -10,7 +10,7 @@ const fs = require('fs'),
path = require('path'), path = require('path'),
CONF = require('./config'), CONF = require('./config'),
Datastore = require('nedb'), Datastore = require('nedb'),
qqwry = require("geoips").info(); qqwry = require("geoips").info(path.join(__dirname, '../static/libs/qqwry.dat'));
var logger; var logger;
...@@ -50,15 +50,13 @@ class Database { ...@@ -50,15 +50,13 @@ class Database {
} }
convertOptstoNedbQuery(opts = {}) { convertOptstoNedbQuery(opts = {}) {
var self = this; var self = this;
if (opts instanceof Array) { if (opts instanceof Array) {
for (let i = 0; i < opts.length; i++) { for (let i = 0; i < opts.length; i++) {
opts[i] = self.convertOptstoNedbQuery(opts[i]); opts[i] = self.convertOptstoNedbQuery(opts[i]);
} }
} else if (opts instanceof Object) { } else if (opts instanceof Object) {
Object Object.keys(opts).map((f) => {
.keys(opts)
.map((f) => {
if (opts[f] instanceof Object) { if (opts[f] instanceof Object) {
opts[f] = self.convertOptstoNedbQuery(opts[f]); opts[f] = self.convertOptstoNedbQuery(opts[f]);
} }
...@@ -69,15 +67,15 @@ class Database { ...@@ -69,15 +67,15 @@ class Database {
opts[f] = new RegExp(opts[f], 'i'); opts[f] = new RegExp(opts[f], 'i');
} }
}); });
}
return opts;
} }
return opts; /**
} * 查询shell数据
/** * @param {Object} event ipcMain对象
* 查询shell数据 * @param {Object} opts 查询配置
* @param {Object} event ipcMain对象 * @return {[type]} [description]
* @param {Object} opts 查询配置 */
* @return {[type]} [description]
*/
findShell(event, opts = {}) { findShell(event, opts = {}) {
opts = this.convertOptstoNedbQuery(opts); opts = this.convertOptstoNedbQuery(opts);
logger.debug('findShell', opts); logger.debug('findShell', opts);
...@@ -460,42 +458,42 @@ class Database { ...@@ -460,42 +458,42 @@ class Database {
* @param {Object} opts 配置(_id,data * @param {Object} opts 配置(_id,data
*/ */
addPluginDataConf(event, plugin, opts) { addPluginDataConf(event, plugin, opts) {
logger.info('addPluginDataConf', plugin, opts); logger.info('addPluginDataConf', plugin, opts);
// 1. 获取原配置列表 // 1. 获取原配置列表
this this
.cursor .cursor
.findOne({ .findOne({
_id: opts['_id'] _id: opts['_id']
}, (err, ret) => { }, (err, ret) => {
ret['plugins'] = ret['plugins'] || {}; ret['plugins'] = ret['plugins'] || {};
let confs = ret['plugins'][plugin] || {}; let confs = ret['plugins'][plugin] || {};
// 随机Id(顺序增长 // 随机Id(顺序增长
const random_id = parseInt(+new Date + Math.random() * 1000).toString(16); const random_id = parseInt(+new Date + Math.random() * 1000).toString(16);
// 添加到配置 // 添加到配置
confs[random_id] = opts['data']; confs[random_id] = opts['data'];
let setdata = { let setdata = {
utime: +new Date utime: +new Date
} }
setdata[`plugins.${plugin}`] = confs; setdata[`plugins.${plugin}`] = confs;
// 更新 // 更新
this this
.cursor .cursor
.update({ .update({
_id: opts['_id'] _id: opts['_id']
}, { }, {
$set: setdata $set: setdata
}, (_err, _ret) => { }, (_err, _ret) => {
event.returnValue = random_id; event.returnValue = random_id;
}); });
}); });
} }
/** /**
* 修改插件数据配置 * 修改插件数据配置
* @param {Object} event ipcMain对象 * @param {Object} event ipcMain对象
* @param {string} plugin 插件注册的名称 * @param {string} plugin 插件注册的名称
* @param {Object} opts 配置(_id,id,data * @param {Object} opts 配置(_id,id,data
*/ */
editPluginDataConf(event, plugin, opts) { editPluginDataConf(event, plugin, opts) {
logger.info('editPluginDataConf', plugin, opts); logger.info('editPluginDataConf', plugin, opts);
// 1. 获取原配置列表 // 1. 获取原配置列表
......
...@@ -30,6 +30,17 @@ const APROXY_CONF = { ...@@ -30,6 +30,17 @@ const APROXY_CONF = {
uri: '' 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 { class Request {
constructor(electron) { constructor(electron) {
...@@ -176,7 +187,7 @@ class Request { ...@@ -176,7 +187,7 @@ class Request {
.type(self.reqContentType) .type(self.reqContentType)
// .set('Content-Type', 'application/x-www-form-urlencoded') // .set('Content-Type', 'application/x-www-form-urlencoded')
.timeout(opts.timeout || REQ_TIMEOUT) .timeout(opts.timeout || REQ_TIMEOUT)
.ignoreHTTPS(opts['ignoreHTTPS']) .ignoreHTTPS(opts['ignoreHTTPS']);
if (opts['useChunk'] == 1) { if (opts['useChunk'] == 1) {
logger.debug("request with Chunked"); logger.debug("request with Chunked");
let antstream; 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