ming_node 2.9.3 → 2.9.7
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +22 -13
- package/module/FileDb.js +10 -2
- 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.7
|
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
|
}
|
@@ -1497,11 +1501,14 @@ M.server = function () {
|
|
1497
1501
|
}
|
1498
1502
|
return isRest;
|
1499
1503
|
}
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1504
|
+
try {
|
1505
|
+
req.ip = req.headers['x-forwarded-for'] ||
|
1506
|
+
req.connection.remoteAddress ||
|
1507
|
+
req.socket.remoteAddress ||
|
1508
|
+
req.connection.socket.remoteAddress;
|
1509
|
+
}catch (e){
|
1510
|
+
req.ip="";
|
1511
|
+
}
|
1505
1512
|
//请求cookies封装
|
1506
1513
|
req.cookies = querystring.parse(req.headers['cookie'], "; ");
|
1507
1514
|
//设置浏览器cookies
|
@@ -1769,7 +1776,11 @@ M.server = function () {
|
|
1769
1776
|
}
|
1770
1777
|
} catch (e) {
|
1771
1778
|
console.error(e);
|
1772
|
-
|
1779
|
+
try {
|
1780
|
+
M["_gloable_exception_handle"](e,req,res);
|
1781
|
+
}catch (e){
|
1782
|
+
console.error("e2",e);
|
1783
|
+
}
|
1773
1784
|
}
|
1774
1785
|
}
|
1775
1786
|
|
@@ -1941,7 +1952,7 @@ M.server = function () {
|
|
1941
1952
|
//全局异常钩子
|
1942
1953
|
app.set("gloable_exception_handle",(err,req,res)=>{
|
1943
1954
|
console.error(err.stack)
|
1944
|
-
if (res && !res.alreadySend) {
|
1955
|
+
if (res && res.send && !res.alreadySend) {
|
1945
1956
|
// res.writeHead(500, { "Content-Type": "text/j;charset='utf-8'" });
|
1946
1957
|
res.send(M.result(err.message,false,-1));
|
1947
1958
|
}
|
@@ -1985,8 +1996,6 @@ M.server = function () {
|
|
1985
1996
|
console.log("listen on port:" + port);
|
1986
1997
|
return server;
|
1987
1998
|
}
|
1988
|
-
|
1989
|
-
global.app=app;
|
1990
1999
|
return app;
|
1991
2000
|
}
|
1992
2001
|
M["_gloable_exception_handle"]=(err)=>{
|
@@ -2833,7 +2842,7 @@ M.getRemoteCacheByUrl = async function (url) {
|
|
2833
2842
|
if (url.startsWith("file:")) {
|
2834
2843
|
text = M.readFile(url.substring(5));
|
2835
2844
|
} else {
|
2836
|
-
text = await M.get(url);
|
2845
|
+
text = await M.get(url,{},{});
|
2837
2846
|
}
|
2838
2847
|
console.log("req remote url:", url);
|
2839
2848
|
M._globle_cacheMap[url] = text;
|
package/module/FileDb.js
CHANGED
@@ -100,9 +100,17 @@ class FileDb{
|
|
100
100
|
let orderType=orderArr[1];
|
101
101
|
rows.sort((a,b)=>{
|
102
102
|
let ret=0;
|
103
|
-
|
103
|
+
let a_order_v=0;
|
104
|
+
let b_order_v=0;
|
105
|
+
if(a[orderField]!=null){
|
106
|
+
a_order_v=a[orderField];
|
107
|
+
}
|
108
|
+
if(b[orderField]!=null){
|
109
|
+
b_order_v=b[orderField];
|
110
|
+
}
|
111
|
+
if (a_order_v>b_order_v) {
|
104
112
|
ret= 1;
|
105
|
-
}else if(
|
113
|
+
}else if(a_order_v<b_order_v){
|
106
114
|
ret= -1
|
107
115
|
}else{
|
108
116
|
ret= 0;
|
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
|
+
|