mdkcontroller 1.6.2 → 1.7.0
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/demoApp.js +1 -90
- package/dk_modules/users.js +2 -3
- package/main.js +6 -2
- package/package.json +1 -1
package/demoApp.js
CHANGED
|
@@ -69,93 +69,4 @@ global.app.use("/api", newRouterApi);
|
|
|
69
69
|
// });
|
|
70
70
|
// });
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const rl = readline.createInterface({
|
|
75
|
-
input: process.stdin,
|
|
76
|
-
output: process.stdout
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
function ask(question) {
|
|
80
|
-
return new Promise(resolve => {
|
|
81
|
-
rl.question(question, answer => resolve(answer));
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
const PORT = process.env.PORT || 8888;
|
|
85
|
-
_sv.startListen(PORT).then(() => {
|
|
86
|
-
console.log("Server started successfully, listening on port: " + PORT);
|
|
87
|
-
(async () => {
|
|
88
|
-
let keepGoing = true;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
while (keepGoing) {
|
|
92
|
-
const input = await ask('Nhập gì đó (hoặc gõ "exit" để thoát): ');
|
|
93
|
-
|
|
94
|
-
if (input === 'exit') {
|
|
95
|
-
keepGoing = false;
|
|
96
|
-
} else {
|
|
97
|
-
if (input == "help") {
|
|
98
|
-
console.log(`Các lệnh hỗ trợ:
|
|
99
|
-
help: hiển thị danh sách lệnh
|
|
100
|
-
exit: thoát chờ lệnh
|
|
101
|
-
ua: thêm người dùng mới
|
|
102
|
-
ud: xóa người dùng
|
|
103
|
-
ul: danh sách người dùng`);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (input.startsWith("ua")) {
|
|
107
|
-
const parts = input.split(" ");
|
|
108
|
-
if (parts.length != 3) {
|
|
109
|
-
console.log("Cú pháp: ua <username> <password>");
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
const username = parts[1];
|
|
113
|
-
const password = parts[2];
|
|
114
|
-
const existingUser = userTable.find(user => user.username === username);
|
|
115
|
-
if (existingUser) {
|
|
116
|
-
existingUser.password = global.auth.encrypt(password);
|
|
117
|
-
existingUser.signcode = global.generateRandomString(100);
|
|
118
|
-
db.write();
|
|
119
|
-
console.log(`Người dùng ${username} đã được cập nhật.`);
|
|
120
|
-
} else {
|
|
121
|
-
const newUser = {
|
|
122
|
-
id: Sequense('users'),
|
|
123
|
-
username: username.toLowerCase(),
|
|
124
|
-
email: username + "@patsoft.com.vn",
|
|
125
|
-
password: global.auth.encrypt(password),
|
|
126
|
-
active: true,
|
|
127
|
-
signcode: global.generateRandomString(100),
|
|
128
|
-
}
|
|
129
|
-
userTable.push(newUser);
|
|
130
|
-
db.write();
|
|
131
|
-
console.log(`Người dùng ${username} đã được thêm.`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (input.startsWith("ud")) {
|
|
135
|
-
const parts = input.split(" ");
|
|
136
|
-
if (parts.length != 2) {
|
|
137
|
-
console.log("Cú pháp: ud <username>");
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
const username = parts[1];
|
|
141
|
-
const userIndex = userTable.findIndex(user => user.username === username);
|
|
142
|
-
if (userIndex !== -1) {
|
|
143
|
-
userTable.splice(userIndex, 1);
|
|
144
|
-
db.write();
|
|
145
|
-
console.log(`Người dùng ${username} đã được xóa.`);
|
|
146
|
-
} else {
|
|
147
|
-
console.log(`Người dùng ${username} không tồn tại.`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (input.startsWith("ul")) {
|
|
151
|
-
console.log("Danh sách người dùng:");
|
|
152
|
-
userTable.forEach(user => {
|
|
153
|
-
console.log(`- ${user.username}`);
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
rl.close();
|
|
160
|
-
})();
|
|
161
|
-
});
|
|
72
|
+
_sv.startListen(6000, true);
|
package/dk_modules/users.js
CHANGED
|
@@ -65,15 +65,14 @@ export default (router, db) => {
|
|
|
65
65
|
body: JSON.stringify({
|
|
66
66
|
username: bodyParser.username,
|
|
67
67
|
appname: bodyParser.appname || "web " + req.headers.host,
|
|
68
|
-
number: bodyParser.number
|
|
68
|
+
number: `${bodyParser.number || "55"}`
|
|
69
69
|
})
|
|
70
70
|
}).then(async response => {
|
|
71
|
+
const text = await response.text();
|
|
71
72
|
if (response.ok) {
|
|
72
|
-
const text = await response.text();
|
|
73
73
|
const data = JSON.parse(text);
|
|
74
74
|
return data;
|
|
75
75
|
}
|
|
76
|
-
const text = await response.text();
|
|
77
76
|
return { success: false, message: `${response.status}-${text}` };
|
|
78
77
|
})
|
|
79
78
|
.then(data => {
|
package/main.js
CHANGED
|
@@ -90,11 +90,15 @@ export default async function (appname, cfgHandler = {}) {
|
|
|
90
90
|
return result.toUpperCase();
|
|
91
91
|
};
|
|
92
92
|
|
|
93
|
-
app.use(json());
|
|
94
|
-
app.use(cookieParser());
|
|
95
93
|
if (cfgHandler.overuse) {
|
|
96
94
|
cfgHandler.overuse(app);
|
|
95
|
+
} else {
|
|
96
|
+
app.use(json({ limit: '50mb' }));
|
|
97
|
+
app.use(express.urlencoded({ limit: '50mb', extended: true }));
|
|
97
98
|
}
|
|
99
|
+
|
|
100
|
+
app.use(cookieParser());
|
|
101
|
+
|
|
98
102
|
app.use((req, res, next) => {
|
|
99
103
|
res.setHeader('Cache-Control', 'no-store');
|
|
100
104
|
if (req.url === "/") {
|