douyin-danma-listener 0.1.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/LICENSE +165 -0
- package/README.md +56 -0
- package/lib/api.js +15 -0
- package/lib/index.js +307 -0
- package/lib/proto.js +22087 -0
- package/lib/utils.js +40 -0
- package/lib/webmssdk.js +9185 -0
- package/package.json +48 -0
- package/types/index.d.ts +44 -0
- package/types/types.d.ts +197 -0
package/lib/utils.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { gunzip } from "node:zlib";
|
|
5
|
+
import { get_sign } from "./webmssdk.js";
|
|
6
|
+
export function loadWebmssdk(jsFile) {
|
|
7
|
+
const dirPath = path.dirname(__filename);
|
|
8
|
+
const jsPath = path.join(dirPath, jsFile);
|
|
9
|
+
return fs.readFileSync(jsPath, "utf-8");
|
|
10
|
+
}
|
|
11
|
+
export function getUserUniqueId() {
|
|
12
|
+
return (Math.floor(Math.random() * (7999999999999999999 - 7300000000000000000)) + 7300000000000000000).toString();
|
|
13
|
+
}
|
|
14
|
+
export function getXMsStub(params) {
|
|
15
|
+
const sigParams = Object.entries(params)
|
|
16
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
17
|
+
.join(",");
|
|
18
|
+
return crypto.createHash("md5").update(sigParams).digest("hex");
|
|
19
|
+
}
|
|
20
|
+
export function getSignature(xMsStub) {
|
|
21
|
+
try {
|
|
22
|
+
return get_sign(xMsStub);
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
return "00000000";
|
|
26
|
+
}
|
|
27
|
+
return "00000000";
|
|
28
|
+
}
|
|
29
|
+
export function decompressGzip(buffer) {
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
gunzip(buffer, (err, result) => {
|
|
32
|
+
if (err) {
|
|
33
|
+
reject(err);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
resolve(result);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|