@nka212bg/backend-utils 0.1.26 → 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 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
File without changes
package/location/index.js CHANGED
File without changes
File without changes
File without changes
File without changes
package/markdown/index.js CHANGED
File without changes
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.26",
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": "^6.9.14",
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": "^5.1.7",
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.socket = (server) => {
6
- const sl = sockets.length;
7
- sockets[sl] = new WebSocket.Server({ server });
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
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
- exports.sendSocketMessage = ({ userId, skipId, skipToken, data, broadcast } = {}) => {
37
- let sentCount = 0;
38
- let tempCount = 0;
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
- if ((!userId && !broadcast) || !sockets.length) return;
41
- userId = !Array.isArray(userId) ? [String(userId)] : userId.map((e) => String(e));
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
- if (skipId) skipId = !Array.isArray(skipId) ? [String(skipId)] : skipId.map((e) => String(e));
44
- if (skipToken && !Array.isArray(skipToken)) skipToken = [String(skipToken)];
18
+ try {
19
+ if (typeof data === "object") data = JSON.stringify(data);
20
+ } catch {}
45
21
 
46
- try {
47
- if (typeof data != "string") data = JSON.stringify(data);
48
- } catch {}
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
- sockets.forEach((socket) => {
51
- (socket.clients || []).forEach(manageClient);
52
- });
28
+ client.send(data);
29
+ sentCount += 1;
30
+ }
31
+ });
53
32
 
54
- socketsCount = tempCount;
55
- return sentCount;
33
+ return sentCount;
34
+ };
56
35
 
57
- function manageClient(client) {
58
- tempCount += 1;
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
- if (broadcast || userId.includes(client.params.userId)) {
61
- if (skipId && skipId.includes(client.params.userId)) return;
62
- if (skipToken && skipToken.includes(client.params.token)) return;
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
- client.send(data);
65
- sentCount += 1;
66
- }
67
- }
53
+ return socket;
68
54
  };
69
55
 
70
- exports.socketStat = () => {
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