@less-is-more/less-js 1.4.19 → 1.4.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/db.js +5 -2
- package/src/router.js +8 -11
package/package.json
CHANGED
package/src/db.js
CHANGED
|
@@ -94,12 +94,14 @@ module.exports = class Db {
|
|
|
94
94
|
needDelete = false,
|
|
95
95
|
compareColumn = []
|
|
96
96
|
) {
|
|
97
|
+
let updateData = [];
|
|
98
|
+
let addData = [];
|
|
97
99
|
for (let nNewData of newData) {
|
|
98
100
|
const nOldIndex = oldData.findIndex(
|
|
99
101
|
(nOld) => nOld[keyColumn] == nNewData[keyColumn]
|
|
100
102
|
);
|
|
101
103
|
if (nOldIndex == -1) {
|
|
102
|
-
await this.add(model, nNewData);
|
|
104
|
+
addData.push(await this.add(model, nNewData));
|
|
103
105
|
} else {
|
|
104
106
|
const nOldData = oldData[nOldIndex];
|
|
105
107
|
let needUpdate = false;
|
|
@@ -127,7 +129,7 @@ module.exports = class Db {
|
|
|
127
129
|
for (let nColumn of compareColumn) {
|
|
128
130
|
setValues[nColumn] = nNewData[nColumn];
|
|
129
131
|
}
|
|
130
|
-
await this.update(model, setValues, where);
|
|
132
|
+
updateData.push(await this.update(model, setValues, where));
|
|
131
133
|
}
|
|
132
134
|
// 剔除已经处理的
|
|
133
135
|
oldData.splice(nOldIndex, 1);
|
|
@@ -139,6 +141,7 @@ module.exports = class Db {
|
|
|
139
141
|
await n.destroy();
|
|
140
142
|
}
|
|
141
143
|
}
|
|
144
|
+
return { addData: addData, updateData: updateData };
|
|
142
145
|
}
|
|
143
146
|
|
|
144
147
|
/**
|
package/src/router.js
CHANGED
|
@@ -18,9 +18,9 @@ module.exports = class Router {
|
|
|
18
18
|
*/
|
|
19
19
|
static async route(targets, req, res, context) {
|
|
20
20
|
const startTime = new Date().getTime();
|
|
21
|
+
const { methodName, className } = this._getPath(req);
|
|
21
22
|
// 兼容非阿里云
|
|
22
23
|
await this._handleParams(req);
|
|
23
|
-
const { methodName, className } = this._getPath(req);
|
|
24
24
|
if (methodName) {
|
|
25
25
|
const controller = targets[className];
|
|
26
26
|
if (controller == undefined) {
|
|
@@ -64,13 +64,7 @@ module.exports = class Router {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
static _getPath(req) {
|
|
67
|
-
console.log(
|
|
68
|
-
"path:",
|
|
69
|
-
req.method,
|
|
70
|
-
req.path,
|
|
71
|
-
req.headers["content-type"],
|
|
72
|
-
JSON.stringify(req.params)
|
|
73
|
-
);
|
|
67
|
+
console.log("path:", req.method, req.path, req.headers["content-type"]);
|
|
74
68
|
const paths = req.path.split("/");
|
|
75
69
|
const className = paths.length > 2 ? "/" + paths[paths.length - 2] : "/";
|
|
76
70
|
const methodName = paths[paths.length - 1];
|
|
@@ -81,7 +75,10 @@ module.exports = class Router {
|
|
|
81
75
|
if (req.query) {
|
|
82
76
|
req.queries = req.query;
|
|
83
77
|
}
|
|
84
|
-
console.log(
|
|
78
|
+
console.log(
|
|
79
|
+
"queries:",
|
|
80
|
+
req.queries ? JSON.stringify(req.queries).substring(0, 500) : ""
|
|
81
|
+
);
|
|
85
82
|
const isFile =
|
|
86
83
|
req.headers &&
|
|
87
84
|
req.headers["content-type"] &&
|
|
@@ -108,7 +105,7 @@ module.exports = class Router {
|
|
|
108
105
|
}
|
|
109
106
|
} else {
|
|
110
107
|
const data = await promisify(body)(req);
|
|
111
|
-
console.log("body: " + data);
|
|
108
|
+
console.log("body: " + data.substring(0, 500));
|
|
112
109
|
req.body = qs.parse(data);
|
|
113
110
|
}
|
|
114
111
|
}
|
|
@@ -157,7 +154,7 @@ module.exports = class Router {
|
|
|
157
154
|
useTime + "s",
|
|
158
155
|
req.path,
|
|
159
156
|
"response:",
|
|
160
|
-
content.
|
|
157
|
+
content.substring(0, 500)
|
|
161
158
|
);
|
|
162
159
|
res.send(content);
|
|
163
160
|
}
|