ming_node 2.9.5 → 2.9.8
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +31 -14
- package/package.json +1 -1
- package/utils/yuque/yuque.js +25 -0
package/index.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
* By : Minglie
|
4
4
|
* QQ: 934031452
|
5
5
|
* Date :2021.12.01
|
6
|
-
* version :2.9.
|
6
|
+
* version :2.9.8
|
7
7
|
*/
|
8
8
|
var http = require('http');
|
9
9
|
var https = require('https');
|
@@ -109,7 +109,7 @@ M.get = function (url, callback, data, headers) {
|
|
109
109
|
if (typeof callback == "function") {
|
110
110
|
|
111
111
|
} else {
|
112
|
-
headers = data || {};
|
112
|
+
headers = data || {'Content-Type': 'application/json'};
|
113
113
|
data = callback;
|
114
114
|
callback = () => {
|
115
115
|
};
|
@@ -175,7 +175,11 @@ M.get = function (url, callback, data, headers) {
|
|
175
175
|
res.on('end', function () {
|
176
176
|
callback(html, res);
|
177
177
|
try {
|
178
|
-
|
178
|
+
if(headers && headers['Content-Type']=='application/json'){
|
179
|
+
html = JSON.parse(html)
|
180
|
+
}else {
|
181
|
+
html = html;
|
182
|
+
}
|
179
183
|
} catch (e) {
|
180
184
|
html = html;
|
181
185
|
}
|
@@ -273,6 +277,7 @@ M._request = function (url, callback, data, headers,methed) {
|
|
273
277
|
|
274
278
|
req.on('error', function (err) {
|
275
279
|
console.error(err);
|
280
|
+
throw err;
|
276
281
|
});
|
277
282
|
if(methed !="GET") req.write(postData);
|
278
283
|
req.end();
|
@@ -357,6 +362,7 @@ M.postJson = function (url, callback, data, headers) {
|
|
357
362
|
|
358
363
|
req.on('error', function (err) {
|
359
364
|
console.error(err);
|
365
|
+
throw err;
|
360
366
|
});
|
361
367
|
req.write(postData);
|
362
368
|
req.end();
|
@@ -1070,6 +1076,7 @@ M.getMySql = function (dbConfig) {
|
|
1070
1076
|
connection.beginTransaction( async function(err) {
|
1071
1077
|
if (err) {
|
1072
1078
|
console.error(err);
|
1079
|
+
throw err;
|
1073
1080
|
return;
|
1074
1081
|
}
|
1075
1082
|
try {
|
@@ -1078,6 +1085,7 @@ M.getMySql = function (dbConfig) {
|
|
1078
1085
|
connection.rollback(function() {
|
1079
1086
|
console.error(e);
|
1080
1087
|
connection.release();
|
1088
|
+
throw e;
|
1081
1089
|
});
|
1082
1090
|
return;
|
1083
1091
|
}
|
@@ -1086,6 +1094,7 @@ M.getMySql = function (dbConfig) {
|
|
1086
1094
|
connection.release();
|
1087
1095
|
if (err) {
|
1088
1096
|
console.error(err);
|
1097
|
+
throw err;
|
1089
1098
|
return;
|
1090
1099
|
}
|
1091
1100
|
});
|
@@ -1497,11 +1506,14 @@ M.server = function () {
|
|
1497
1506
|
}
|
1498
1507
|
return isRest;
|
1499
1508
|
}
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1509
|
+
try {
|
1510
|
+
req.ip = req.headers['x-forwarded-for'] ||
|
1511
|
+
req.connection.remoteAddress ||
|
1512
|
+
req.socket.remoteAddress ||
|
1513
|
+
req.connection.socket.remoteAddress;
|
1514
|
+
}catch (e){
|
1515
|
+
req.ip="";
|
1516
|
+
}
|
1505
1517
|
//请求cookies封装
|
1506
1518
|
req.cookies = querystring.parse(req.headers['cookie'], "; ");
|
1507
1519
|
//设置浏览器cookies
|
@@ -1593,6 +1605,7 @@ M.server = function () {
|
|
1593
1605
|
fs.createReadStream(url).on("end",d=>{})
|
1594
1606
|
.on("error",e=>{
|
1595
1607
|
console.error(e);
|
1608
|
+
throw e;
|
1596
1609
|
}).pipe(res);
|
1597
1610
|
}else {
|
1598
1611
|
var func = http;
|
@@ -1610,7 +1623,8 @@ M.server = function () {
|
|
1610
1623
|
res.writeHead(200, {"Content-Type": "" + (privateObj.staticMime[extname] || 'text/html') + ";charset='utf-8'",});
|
1611
1624
|
res1.on("end",d=>{})
|
1612
1625
|
.on("error",e=>{
|
1613
|
-
console.error(e)
|
1626
|
+
console.error(e);
|
1627
|
+
throw e;
|
1614
1628
|
}).pipe(res);
|
1615
1629
|
});
|
1616
1630
|
}
|
@@ -1769,7 +1783,11 @@ M.server = function () {
|
|
1769
1783
|
}
|
1770
1784
|
} catch (e) {
|
1771
1785
|
console.error(e);
|
1772
|
-
|
1786
|
+
try {
|
1787
|
+
M["_gloable_exception_handle"](e,req,res);
|
1788
|
+
}catch (e){
|
1789
|
+
console.error("e2",e);
|
1790
|
+
}
|
1773
1791
|
}
|
1774
1792
|
}
|
1775
1793
|
|
@@ -1941,7 +1959,7 @@ M.server = function () {
|
|
1941
1959
|
//全局异常钩子
|
1942
1960
|
app.set("gloable_exception_handle",(err,req,res)=>{
|
1943
1961
|
console.error(err.stack)
|
1944
|
-
if (res && !res.alreadySend) {
|
1962
|
+
if (res && res.send && !res.alreadySend) {
|
1945
1963
|
// res.writeHead(500, { "Content-Type": "text/j;charset='utf-8'" });
|
1946
1964
|
res.send(M.result(err.message,false,-1));
|
1947
1965
|
}
|
@@ -1985,8 +2003,6 @@ M.server = function () {
|
|
1985
2003
|
console.log("listen on port:" + port);
|
1986
2004
|
return server;
|
1987
2005
|
}
|
1988
|
-
|
1989
|
-
global.app=app;
|
1990
2006
|
return app;
|
1991
2007
|
}
|
1992
2008
|
M["_gloable_exception_handle"]=(err)=>{
|
@@ -2067,6 +2083,7 @@ M.axios = function (axiosConfig) {
|
|
2067
2083
|
});
|
2068
2084
|
req.on('error', function (err) {
|
2069
2085
|
console.error(err);
|
2086
|
+
throw err;
|
2070
2087
|
});
|
2071
2088
|
req.write(axiosConfig.body);
|
2072
2089
|
req.end();
|
@@ -2833,7 +2850,7 @@ M.getRemoteCacheByUrl = async function (url) {
|
|
2833
2850
|
if (url.startsWith("file:")) {
|
2834
2851
|
text = M.readFile(url.substring(5));
|
2835
2852
|
} else {
|
2836
|
-
text = await M.get(url);
|
2853
|
+
text = await M.get(url,{},{});
|
2837
2854
|
}
|
2838
2855
|
console.log("req remote url:", url);
|
2839
2856
|
M._globle_cacheMap[url] = text;
|
package/package.json
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
M=require("ming_node");
|
2
|
+
let url=require("url");
|
3
|
+
|
4
|
+
|
5
|
+
//M.yuqueToken="ZW9aH3CUDFWvC0ZU6nzoozBg03smn6Y5D36LqB8x";
|
6
|
+
|
7
|
+
|
8
|
+
M.getYuque= async function (yuqueUrl,type){
|
9
|
+
M.reqComHeaders={"X-Auth-Token": M.yuqueToken,"User-Agent":"PostmanRuntime/7.26.1"}
|
10
|
+
type=type||"html";
|
11
|
+
let r= url.parse(yuqueUrl)
|
12
|
+
let host="https://"+r.hostname;
|
13
|
+
let all_path=yuqueUrl.split(host)[1];
|
14
|
+
let all_path_arr=all_path.split("/");
|
15
|
+
let yuqueApi=`${host}/api/v2/repos/${all_path_arr[1]}/${all_path_arr[2]}/docs/${all_path_arr[3]}`;
|
16
|
+
let r1=await M.get(yuqueApi);
|
17
|
+
let artileContent=r1.data.body;
|
18
|
+
artileContent=artileContent.replace(/\s+/g,'')
|
19
|
+
artileContent=artileContent.replace("```"+type,"")
|
20
|
+
artileContent=artileContent.replace("```","")
|
21
|
+
return artileContent;
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
|