@less-is-more/less-js 1.2.11 → 1.2.12
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 +2 -1
- package/src/router.js +19 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@less-is-more/less-js",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"description": "Fast develop kit for nodejs",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"ejs": "^3.1.6",
|
|
22
22
|
"fs-extra": "^10.0.0",
|
|
23
23
|
"inquirer": "^8.1.2",
|
|
24
|
+
"multiparty": "^4.2.2",
|
|
24
25
|
"mysql2": "^2.2.5",
|
|
25
26
|
"pg-hstore": "^2.3.3",
|
|
26
27
|
"querystring": "^0.2.1",
|
package/src/router.js
CHANGED
|
@@ -2,6 +2,7 @@ const Ret = require("./ret.js");
|
|
|
2
2
|
const Param = require("./param.js");
|
|
3
3
|
const querystring = require("querystring");
|
|
4
4
|
const body = require("body");
|
|
5
|
+
const multiparty = require("multiparty");
|
|
5
6
|
const { promisify } = require("util");
|
|
6
7
|
|
|
7
8
|
module.exports = class Router {
|
|
@@ -70,15 +71,17 @@ module.exports = class Router {
|
|
|
70
71
|
JSON.stringify(req.headers).includes("multipart/form-data");
|
|
71
72
|
console.log("multipart:", isFile);
|
|
72
73
|
if (req.method == "POST") {
|
|
73
|
-
let data = await promisify(body)(req);
|
|
74
74
|
if (isFile) {
|
|
75
|
-
|
|
75
|
+
await this._getFile(req);
|
|
76
|
+
console.log("params", req.params);
|
|
77
|
+
console.log("files", req.files);
|
|
76
78
|
} else {
|
|
79
|
+
const data = await promisify(body)(req);
|
|
77
80
|
console.log("body: " + decodeURIComponent(data));
|
|
78
81
|
req.body = querystring.parse(decodeURIComponent(data));
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
|
-
req.params = {};
|
|
84
|
+
if (req.params == undefined) req.params = {};
|
|
82
85
|
if (!Param.isBlank(req.queries)) {
|
|
83
86
|
Object.keys(req.queries).forEach((n) => (req.params[n] = req.queries[n]));
|
|
84
87
|
}
|
|
@@ -87,6 +90,19 @@ module.exports = class Router {
|
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
|
|
93
|
+
static _getFile(req) {
|
|
94
|
+
return new Promise((resolve, reject) => {
|
|
95
|
+
const form = new multiparty.Form();
|
|
96
|
+
|
|
97
|
+
form.parse(req, function (err, fields, files) {
|
|
98
|
+
if (err) reject(err);
|
|
99
|
+
req.params = fields;
|
|
100
|
+
req.files = files;
|
|
101
|
+
resolve();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
90
106
|
static _handleReturn(result, res) {
|
|
91
107
|
if (!Param.isBlank(result)) {
|
|
92
108
|
if (result instanceof Ret) {
|