@nka212bg/backend-utils 0.1.27 → 0.1.28
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 +75 -1
- package/os.js +0 -0
- package/package.json +1 -1
- package/session.js +0 -0
- package/socket.js +49 -28
- 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
|
@@ -374,6 +374,80 @@ exports.crypto = ({ salt, embedSalt } = {}) => {
|
|
|
374
374
|
function byteHex(n) {
|
|
375
375
|
return ("0" + Number(n).toString(16)).slice(-2);
|
|
376
376
|
}
|
|
377
|
+
|
|
378
|
+
// TODO
|
|
379
|
+
// NEW CRYPTO
|
|
380
|
+
//
|
|
381
|
+
// --- 1. PRE-COMPUTE THE CRYPTO KEY ONCE ---
|
|
382
|
+
// async function initializeKey(password) {
|
|
383
|
+
// const rawKey = await crypto.subtle.digest("SHA-256"
|
|
384
|
+
// return crypto.subtle.importKey("raw", rawKey, "AES-CTR", false, ["encrypt", "decrypt"]);
|
|
385
|
+
// }
|
|
386
|
+
//
|
|
387
|
+
// // --- HELPER: GZIP Compression Streams ---
|
|
388
|
+
// async function compressText(text) {
|
|
389
|
+
// const stream = new Response(text).body.
|
|
390
|
+
// return new Uint8Array(await new Response(stream).arrayBuffer()
|
|
391
|
+
// }
|
|
392
|
+
//
|
|
393
|
+
// async function decompressText(bytes) {
|
|
394
|
+
// const stream = new Response(bytes).body.
|
|
395
|
+
// return new Response(stream).text();
|
|
396
|
+
// }
|
|
397
|
+
//
|
|
398
|
+
// // --- 2. ENCRYPT WITH COMPRESSION ---
|
|
399
|
+
// async function encrypt(plainText, cryptoKey) {
|
|
400
|
+
// const iv = crypto.getRandomValues(new Uint8Array(16));
|
|
401
|
+
//
|
|
402
|
+
// // Compress the text into tiny raw bytes first
|
|
403
|
+
// const compressedBytes = await compressText(plainText);
|
|
404
|
+
//
|
|
405
|
+
// // Encrypt the tiny compressed bytes
|
|
406
|
+
// const buffer = await crypto.subtle.encrypt(
|
|
407
|
+
// { name: "AES-CTR", counter: iv, length: 64 },
|
|
408
|
+
// cryptoKey,
|
|
409
|
+
// compressedBytes
|
|
410
|
+
// );
|
|
411
|
+
//
|
|
412
|
+
// const ivBase64 = btoa(String.fromCharCode(...
|
|
413
|
+
// const cipherBase64 = btoa(String.fromCharCode(...
|
|
414
|
+
//
|
|
415
|
+
// return `${ivBase64}:${cipherBase64}`;
|
|
416
|
+
// }
|
|
417
|
+
//
|
|
418
|
+
// // --- 3. DECRYPT WITH DECOMPRESSION ---
|
|
419
|
+
// async function decrypt(encryptedString, cryptoKey) {
|
|
420
|
+
// const [ivBase64, cipherBase64] = encryptedString.split(":");
|
|
421
|
+
//
|
|
422
|
+
// const iv = Uint8Array.from(atob(ivBase64)
|
|
423
|
+
// const cipherText = Uint8Array.from(atob(
|
|
424
|
+
//
|
|
425
|
+
// // Decrypt back to compressed bytes
|
|
426
|
+
// const decryptedBuffer = await crypto.subtle.decrypt(
|
|
427
|
+
// { name: "AES-CTR", counter: iv, length: 64 },
|
|
428
|
+
// cryptoKey,
|
|
429
|
+
// cipherText
|
|
430
|
+
// );
|
|
431
|
+
//
|
|
432
|
+
// // Decompress back to original text string
|
|
433
|
+
// return await decompressText(new Uint8Array(decryptedBuffer));
|
|
434
|
+
// }
|
|
435
|
+
//
|
|
436
|
+
// // --- DEMO RUN ---
|
|
437
|
+
// async function run() {
|
|
438
|
+
// const cryptoKey = await initializeKey("sdfg#$%gd
|
|
439
|
+
//
|
|
440
|
+
// // Compression shines on repetitive texts, paragraphs, or JSON data!
|
|
441
|
+
// const longText = "Repeat this! Repeat сасдасфд this! Repeat this! Super long paragraph data...";
|
|
442
|
+
//
|
|
443
|
+
// const encrypted = await encrypt(longText, cryptoKey);
|
|
444
|
+
// console.log("Compressed & Encrypted String:\n", encrypted);
|
|
445
|
+
//
|
|
446
|
+
// const decrypted = await decrypt(encrypted, cryptoKey);
|
|
447
|
+
// console.log("\nDecrypted Output:\n", decrypted);
|
|
448
|
+
// }
|
|
449
|
+
//
|
|
450
|
+
// run();
|
|
377
451
|
};
|
|
378
452
|
|
|
379
453
|
exports.secToTime = (sec) => {
|
|
@@ -484,7 +558,7 @@ exports.strToEmailsArray = (emailString) => {
|
|
|
484
558
|
String(emailString)
|
|
485
559
|
.toLowerCase()
|
|
486
560
|
// .match(/\w[\w\.-]+\w@\w+((\.\w+){1,})+\w+/gi)
|
|
487
|
-
.match(/\w[\w\.-]+\w@[\w\.-]+((\.\w+){1,})+\w+/g)
|
|
561
|
+
.match(/\w[\w\.-]+\w@[\w\.-]+((\.\w+){1,})+\w+/g),
|
|
488
562
|
),
|
|
489
563
|
].sort();
|
|
490
564
|
};
|
package/os.js
CHANGED
|
File without changes
|
package/package.json
CHANGED
package/session.js
CHANGED
|
File without changes
|
package/socket.js
CHANGED
|
@@ -8,51 +8,72 @@ module.exports = (server) => {
|
|
|
8
8
|
} catch (error) {}
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
socket.
|
|
12
|
-
|
|
13
|
-
if (
|
|
11
|
+
socket.broadcast = (data, { skipId, skipToken } = {}) => {
|
|
12
|
+
if (!data) return 0;
|
|
13
|
+
if (typeof data === "object") data = JSON.stringify(data);
|
|
14
14
|
|
|
15
|
-
skipId =
|
|
16
|
-
skipToken =
|
|
15
|
+
skipId = new Set(String(skipId).split(/[,"' ]/g).filter(Boolean));
|
|
16
|
+
skipToken = new Set(String(skipToken).split(/[,"' ]/g).filter(Boolean));
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
let sentCount = 0;
|
|
19
|
+
for (const client of socket.clients || []) {
|
|
20
|
+
if (skipId.has(client.params.userId)) continue;
|
|
21
|
+
if (skipToken.has(client.params.authToken)) continue;
|
|
22
|
+
|
|
23
|
+
client.send(data);
|
|
24
|
+
sentCount++;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return sentCount;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
socket.send = (data, { userId = [], skipId = [], skipToken = [] } = {}) => {
|
|
31
|
+
if (!data) return 0;
|
|
32
|
+
if (typeof data === "object") data = JSON.stringify(data);
|
|
33
|
+
|
|
34
|
+
userId = new Set(String(userId).split(/[,"' ]/g).filter(Boolean));
|
|
35
|
+
skipId = new Set(String(skipId).split(/[,"' ]/g).filter(Boolean));
|
|
36
|
+
skipToken = new Set(String(skipToken).split(/[,"' ]/g).filter(Boolean));
|
|
21
37
|
|
|
22
38
|
let sentCount = 0;
|
|
23
|
-
(socket.clients || [])
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
for (const client of socket.clients || []) {
|
|
40
|
+
if (!userId.has(client.params.userId)) continue;
|
|
41
|
+
if (skipId.has(client.params.userId)) continue;
|
|
42
|
+
if (skipToken.has(client.params.authToken)) continue;
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
44
|
+
client.send(data);
|
|
45
|
+
sentCount++;
|
|
46
|
+
}
|
|
32
47
|
|
|
33
48
|
return sentCount;
|
|
34
49
|
};
|
|
35
50
|
|
|
36
51
|
socket.getStatuses = (users) => {
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
users = new Set(String(users).split(/[,"' ]/g).filter(Boolean));
|
|
53
|
+
|
|
39
54
|
const usersObj = {};
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
55
|
+
for (const u of users) usersObj[u] = 0;
|
|
56
|
+
|
|
57
|
+
let remaining = users.size;
|
|
58
|
+
for (const client of socket.clients || []) {
|
|
59
|
+
if (!remaining) break;
|
|
60
|
+
if (!users.has(client.params.userId)) continue;
|
|
61
|
+
|
|
62
|
+
usersObj[client.params.userId] = 1;
|
|
63
|
+
remaining--;
|
|
64
|
+
}
|
|
65
|
+
|
|
50
66
|
return usersObj;
|
|
51
67
|
};
|
|
52
68
|
|
|
69
|
+
|
|
53
70
|
return socket;
|
|
54
71
|
};
|
|
55
72
|
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
56
77
|
////////////////////////////////////////
|
|
57
78
|
|
|
58
79
|
// "web-push": "^3.2.2", // package.json
|
package/stripe.js
CHANGED
|
File without changes
|
package/systemLog.js
CHANGED
|
File without changes
|