@nka212bg/backend-utils 0.1.25 → 0.1.27
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/README.md +0 -0
- package/db/dbUtils.js +0 -0
- package/db/mysql2.js +0 -0
- package/db/sqlite3.js +0 -0
- package/index.js +0 -0
- package/location/GeoLite2-City.mmdb +0 -0
- package/location/VPNs-master.zip +0 -0
- package/location/index.js +0 -0
- package/location/localelib.js +0 -0
- package/mailSmsTools/defaultTemplate.html +0 -0
- package/mailSmsTools/index.js +0 -0
- package/markdown/index.js +0 -0
- package/markdown/markdown.js +0 -0
- package/misc.js +0 -0
- package/os.js +0 -0
- package/package.json +3 -3
- package/session.js +0 -0
- package/socket.js +40 -58
- package/stripe.js +0 -0
- package/systemLog.js +0 -0
package/README.md
CHANGED
|
File without changes
|
package/db/dbUtils.js
CHANGED
|
File without changes
|
package/db/mysql2.js
CHANGED
|
File without changes
|
package/db/sqlite3.js
CHANGED
|
File without changes
|
package/index.js
CHANGED
|
File without changes
|
|
File without changes
|
package/location/VPNs-master.zip
CHANGED
|
File without changes
|
package/location/index.js
CHANGED
|
File without changes
|
package/location/localelib.js
CHANGED
|
File without changes
|
|
File without changes
|
package/mailSmsTools/index.js
CHANGED
|
File without changes
|
package/markdown/index.js
CHANGED
|
File without changes
|
package/markdown/markdown.js
CHANGED
|
File without changes
|
package/misc.js
CHANGED
|
File without changes
|
package/os.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nka212bg/backend-utils",
|
|
3
3
|
"author": "nka212bg",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.27",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@maxmind/geoip2-node": "^5.0.0",
|
|
8
8
|
"systeminformation": "^5.21.24",
|
|
9
9
|
"adm-zip": "^0.5.16",
|
|
10
|
-
"nodemailer": "^
|
|
10
|
+
"nodemailer": "^8.0.8",
|
|
11
11
|
"os-utils": "^0.0.14",
|
|
12
12
|
"stripe": "^14.23.0",
|
|
13
13
|
"mysql2": "^3.11.0",
|
|
14
|
-
"sqlite3": "^
|
|
14
|
+
"sqlite3": "^6.0.1",
|
|
15
15
|
"sharp": "^0.33.5",
|
|
16
16
|
"ws": "^7.3.0"
|
|
17
17
|
}
|
package/session.js
CHANGED
|
File without changes
|
package/socket.js
CHANGED
|
@@ -1,77 +1,59 @@
|
|
|
1
1
|
const WebSocket = require("ws");
|
|
2
|
-
let socketsCount = 0;
|
|
3
|
-
let sockets = [];
|
|
4
2
|
|
|
5
|
-
exports
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
sockets[sl].on("connection", (ws, req) => {
|
|
3
|
+
module.exports = (server) => {
|
|
4
|
+
const socket = new WebSocket.Server({ server, noServer: !server });
|
|
5
|
+
socket.on("connection", (ws, req) => {
|
|
9
6
|
try {
|
|
10
|
-
ws.params = Object.fromEntries(new URLSearchParams(decodeURIComponent(req.url || "").replace(/^(
|
|
7
|
+
ws.params = Object.fromEntries(new URLSearchParams(decodeURIComponent(req.url || "").replace(/^(\/\?|\?|\/)/g, "")));
|
|
11
8
|
} catch (error) {}
|
|
12
9
|
});
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.getUsersStatuses = (users) => {
|
|
16
|
-
if (typeof users == "string") users = users.split(/[, ]/g);
|
|
17
|
-
if (!Array.isArray(users) || !sockets.length) return {};
|
|
18
|
-
|
|
19
|
-
const usersObj = {};
|
|
20
|
-
users.forEach((u) => {
|
|
21
|
-
usersObj[u] = { online: false };
|
|
22
|
-
|
|
23
|
-
for (const socket of sockets) {
|
|
24
|
-
for (const client of socket.clients) {
|
|
25
|
-
if (client.params.userId == u) {
|
|
26
|
-
usersObj[u] = { online: true };
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return usersObj;
|
|
34
|
-
};
|
|
35
10
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
11
|
+
socket.send = ({ id = [], skipId = [], skipToken = [], data, broadcast } = {}) => {
|
|
12
|
+
id = Array.isArray(id) ? id.map((e) => String(e)) : [String(id)];
|
|
13
|
+
if (!data || (!id.length && !broadcast)) return 0;
|
|
39
14
|
|
|
40
|
-
|
|
41
|
-
|
|
15
|
+
skipId = Array.isArray(skipId) ? skipId.map((e) => String(e)) : [String(skipId)];
|
|
16
|
+
skipToken = Array.isArray(skipToken) ? skipToken.map((e) => String(e)) : [String(skipToken)];
|
|
42
17
|
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
try {
|
|
19
|
+
if (typeof data === "object") data = JSON.stringify(data);
|
|
20
|
+
} catch {}
|
|
45
21
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
22
|
+
let sentCount = 0;
|
|
23
|
+
(socket.clients || []).forEach((client) => {
|
|
24
|
+
if (broadcast || id.includes(client.params.id)) {
|
|
25
|
+
if (skipId.includes(client.params.id)) return;
|
|
26
|
+
if (skipToken.includes(client.params.token)) return;
|
|
49
27
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
28
|
+
client.send(data);
|
|
29
|
+
sentCount += 1;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
53
32
|
|
|
54
|
-
|
|
55
|
-
|
|
33
|
+
return sentCount;
|
|
34
|
+
};
|
|
56
35
|
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
socket.getStatuses = (users) => {
|
|
37
|
+
if (typeof users == "string") users = users.split(/[, ]/g);
|
|
38
|
+
if (!Array.isArray(users)) return {};
|
|
39
|
+
const usersObj = {};
|
|
40
|
+
users.forEach((u) => {
|
|
41
|
+
usersObj[u] = 0;
|
|
59
42
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
for (const client of socket.clients) {
|
|
44
|
+
if (client.params.id == u) {
|
|
45
|
+
usersObj[u] = 1;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return usersObj;
|
|
51
|
+
};
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
sentCount += 1;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
53
|
+
return socket;
|
|
68
54
|
};
|
|
69
55
|
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
socketsCount,
|
|
73
|
-
};
|
|
74
|
-
};
|
|
56
|
+
////////////////////////////////////////
|
|
75
57
|
|
|
76
58
|
// "web-push": "^3.2.2", // package.json
|
|
77
59
|
// const webPush = require("web-push");
|
package/stripe.js
CHANGED
|
File without changes
|
package/systemLog.js
CHANGED
|
File without changes
|