@nka212bg/backend-utils 0.1.29 → 0.1.31
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/misc.js +3 -16
- package/package.json +1 -1
- package/session.js +2 -0
package/misc.js
CHANGED
|
@@ -86,11 +86,11 @@ exports.createToken = ({ length = 14, type } = {}) => {
|
|
|
86
86
|
const nums = "1234567890";
|
|
87
87
|
|
|
88
88
|
if (type == "number") return mixer(nums, length);
|
|
89
|
-
if (type == "date") return mixer(chars,
|
|
90
|
-
return mixer(chars, 1) + mixer(nums + chars
|
|
89
|
+
if (type == "date") return mixer(chars, Math.max(length - 6, 4)) + parseInt(Date.now() / 10000000);
|
|
90
|
+
return mixer(chars, 1) + mixer(nums + chars, length - 2) + mixer(chars, 1);
|
|
91
91
|
|
|
92
92
|
function mixer(string, length) {
|
|
93
|
-
|
|
93
|
+
while (string.length < length) string += string;
|
|
94
94
|
|
|
95
95
|
return string
|
|
96
96
|
.split("")
|
|
@@ -563,19 +563,6 @@ exports.strToEmailsArray = (emailString) => {
|
|
|
563
563
|
].sort();
|
|
564
564
|
};
|
|
565
565
|
|
|
566
|
-
exports.handlebars = ({ template, ...params } = {}) => {
|
|
567
|
-
const placeholders = template.match(/(\{\{)(.*?)(\}\})/g);
|
|
568
|
-
|
|
569
|
-
for (const p in params) {
|
|
570
|
-
const placeholder = placeholders.find((e) => e.includes(p));
|
|
571
|
-
if (!placeholder) continue;
|
|
572
|
-
|
|
573
|
-
template = template.replace(RegExp(placeholder, "g"), params[p]);
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
return template;
|
|
577
|
-
};
|
|
578
|
-
|
|
579
566
|
exports.iterateObject = (obj, callback) => {
|
|
580
567
|
for (let key in obj) {
|
|
581
568
|
if (Array.isArray(obj[key])) {
|
package/package.json
CHANGED
package/session.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { existsSync, readFileSync, writeFileSync, mkdirSync } = require("fs");
|
|
2
|
+
const { createToken } = require("./misc");
|
|
2
3
|
|
|
3
4
|
!existsSync(`${__basedir}/state`) && mkdirSync(`${__basedir}/state`, { recursive: true });
|
|
4
5
|
const sessionStateFile = `${__basedir}/state/session.json`;
|
|
@@ -38,6 +39,7 @@ exports.session = {
|
|
|
38
39
|
|
|
39
40
|
if (!payload.expirePeriod) payload.expirePeriod = 60000 * 60 * 24 * 7; // 7days
|
|
40
41
|
payload.expireTime = now + payload.expirePeriod;
|
|
42
|
+
payload.uuid = createToken({ type: "date" });
|
|
41
43
|
|
|
42
44
|
SESSION[token] = payload;
|
|
43
45
|
return { ...payload, expireIn: payload.expirePeriod + 60000 };
|