melperjs 5.0.0 → 6.0.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/README.md +4 -2
- package/cjs/index.js +185 -185
- package/cjs/node.js +194 -194
- package/lib/index.js +234 -234
- package/mjs/index.js +156 -156
- package/mjs/node.js +175 -175
- package/package.json +1 -1
- package/src/index.js +36 -5
- package/src/node.js +11 -49
- package/test/script.js +3 -2
package/cjs/node.js
CHANGED
|
@@ -1,195 +1,195 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createNumDir = createNumDir;
|
|
7
|
-
exports.formatProxy = formatProxy;
|
|
8
|
-
exports.getVersion = getVersion;
|
|
9
|
-
exports.hashBcrypt = hashBcrypt;
|
|
10
|
-
exports.md5 = md5;
|
|
11
|
-
exports.proxify = proxify;
|
|
12
|
-
exports.proxyObject = proxyObject;
|
|
13
|
-
exports.serverIp = serverIp;
|
|
14
|
-
exports.tokenHex = tokenHex;
|
|
15
|
-
exports.tokenString = tokenString;
|
|
16
|
-
exports.tokenUuid = tokenUuid;
|
|
17
|
-
exports.tokenWeighted = tokenWeighted;
|
|
18
|
-
exports.verifyBcrypt = verifyBcrypt;
|
|
19
|
-
var _fs = _interopRequireDefault(require("fs"));
|
|
20
|
-
var _path = _interopRequireDefault(require("path"));
|
|
21
|
-
var _crypto = _interopRequireDefault(require("crypto"));
|
|
22
|
-
var _os = require("os");
|
|
23
|
-
var _child_process = require("child_process");
|
|
24
|
-
var _bcrypt = _interopRequireDefault(require("bcrypt"));
|
|
25
|
-
var _axios = _interopRequireDefault(require("axios"));
|
|
26
|
-
var _hpagent = require("hpagent");
|
|
27
|
-
var _index = require("./index.js");
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
-
function tokenString(length, useNumbers = true, useUppercase = false) {
|
|
30
|
-
const lowercaseChars = _index.CONSTANTS.LOWER_CASE;
|
|
31
|
-
const uppercaseChars = _index.CONSTANTS.UPPER_CASE;
|
|
32
|
-
const numbers = _index.CONSTANTS.NUMBERS;
|
|
33
|
-
let characters = lowercaseChars;
|
|
34
|
-
if (useUppercase) characters += uppercaseChars;
|
|
35
|
-
if (useNumbers) characters += numbers;
|
|
36
|
-
let randomString = '';
|
|
37
|
-
while (randomString.length < length) {
|
|
38
|
-
const byte = _crypto.default.randomBytes(1)[0];
|
|
39
|
-
const index = byte % characters.length;
|
|
40
|
-
if (byte < 256 - 256 % characters.length) {
|
|
41
|
-
randomString += characters[index];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return randomString;
|
|
45
|
-
}
|
|
46
|
-
function tokenHex(length) {
|
|
47
|
-
return _crypto.default.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
48
|
-
}
|
|
49
|
-
function tokenUuid(useDashes = true) {
|
|
50
|
-
const uuid = _crypto.default.randomUUID().toString();
|
|
51
|
-
return useDashes ? uuid : uuid.replaceAll("-", "");
|
|
52
|
-
}
|
|
53
|
-
function tokenWeighted(dict) {
|
|
54
|
-
return (0, _index.randomWeighted)(dict, _crypto.default.randomInt);
|
|
55
|
-
}
|
|
56
|
-
function serverIp() {
|
|
57
|
-
const interfaces = (0, _os.networkInterfaces)();
|
|
58
|
-
for (const devName in interfaces) {
|
|
59
|
-
const interfaceValue = interfaces[devName];
|
|
60
|
-
for (let i = 0; i < interfaceValue.length; i++) {
|
|
61
|
-
const alias = interfaceValue[i];
|
|
62
|
-
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith("192.168.") && !alias.internal) return alias.address;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return '127.0.0.1';
|
|
66
|
-
}
|
|
67
|
-
function getVersion() {
|
|
68
|
-
try {
|
|
69
|
-
const date = new Date((0, _child_process.execSync)('git show -s --format=%ci HEAD').toString().trim());
|
|
70
|
-
const formatDatePart = value => value.toString().padStart(2, '0');
|
|
71
|
-
const year = date.getFullYear().toString().slice(-2);
|
|
72
|
-
const month = formatDatePart(date.getMonth() + 1);
|
|
73
|
-
const day = formatDatePart(date.getDate());
|
|
74
|
-
const hour = formatDatePart(date.getHours());
|
|
75
|
-
const minute = formatDatePart(date.getMinutes());
|
|
76
|
-
return parseFloat(`${year}${month}.${day}${hour}${minute}`);
|
|
77
|
-
} catch {
|
|
78
|
-
return 1.0;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function createNumDir(mainDirectory) {
|
|
82
|
-
_fs.default.mkdirSync(mainDirectory, {
|
|
83
|
-
recursive: true
|
|
84
|
-
});
|
|
85
|
-
for (let i = 0; i <= 9; i++) {
|
|
86
|
-
try {
|
|
87
|
-
_fs.default.mkdirSync(_path.default.join(mainDirectory, i.toString()));
|
|
88
|
-
} catch (e) {
|
|
89
|
-
console.error(`createNumDir:${i}`, e.message);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function md5(data) {
|
|
94
|
-
return _crypto.default.createHash('md5').update(data).digest("hex");
|
|
95
|
-
}
|
|
96
|
-
function hashBcrypt(plainText) {
|
|
97
|
-
return _bcrypt.default.hashSync(plainText, _bcrypt.default.genSaltSync(10));
|
|
98
|
-
}
|
|
99
|
-
function verifyBcrypt(plainText, hash) {
|
|
100
|
-
return _bcrypt.default.compareSync(plainText, hash);
|
|
101
|
-
}
|
|
102
|
-
function formatProxy(proxy, protocol = "http") {
|
|
103
|
-
proxy = proxy.trim();
|
|
104
|
-
const splitByProtocol = proxy.split("://");
|
|
105
|
-
if (1 < splitByProtocol.length) protocol = splitByProtocol[0];
|
|
106
|
-
proxy = splitByProtocol[splitByProtocol.length - 1];
|
|
107
|
-
if (!proxy.includes("@")) {
|
|
108
|
-
const proxyParts = proxy.split(":");
|
|
109
|
-
if (4 <= proxyParts.length) {
|
|
110
|
-
proxy = `${proxyParts[proxyParts.length - 2]}:${proxyParts[proxyParts.length - 1]}@`;
|
|
111
|
-
proxyParts.pop();
|
|
112
|
-
proxyParts.pop();
|
|
113
|
-
proxy += proxyParts.join(":");
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const proxyParts = proxy.split(':');
|
|
117
|
-
const proxyEnd = parseInt(proxyParts[proxyParts.length - 1]);
|
|
118
|
-
const proxyStart = proxyParts[proxyParts.length - 2];
|
|
119
|
-
if (!proxyStart.includes(".")) {
|
|
120
|
-
proxyParts.pop();
|
|
121
|
-
proxyParts[proxyParts.length - 1] = _crypto.default.randomInt(parseInt(proxyStart), proxyEnd + 1).toString();
|
|
122
|
-
}
|
|
123
|
-
return protocol + "://" + proxyParts.join(':');
|
|
124
|
-
}
|
|
125
|
-
function proxyObject(...args) {
|
|
126
|
-
let proxy = formatProxy(...args);
|
|
127
|
-
const splitByProtocol = proxy.split('://');
|
|
128
|
-
const splitById = splitByProtocol[splitByProtocol.length - 1].split('@');
|
|
129
|
-
const splitByConn = splitById[splitById.length - 1].split(':');
|
|
130
|
-
proxy = {
|
|
131
|
-
protocol: splitByProtocol[0],
|
|
132
|
-
host: splitByConn[0],
|
|
133
|
-
port: parseInt(splitByConn[1])
|
|
134
|
-
};
|
|
135
|
-
if (1 < splitById.length) {
|
|
136
|
-
const splitByAuth = splitById[0].split(':');
|
|
137
|
-
proxy.auth = {
|
|
138
|
-
username: splitByAuth[0],
|
|
139
|
-
password: splitByAuth[1]
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
return proxy;
|
|
143
|
-
}
|
|
144
|
-
async function proxify(proxyConfig, callback = formatProxy) {
|
|
145
|
-
proxyConfig = proxyConfig || {};
|
|
146
|
-
const timeout = 7000;
|
|
147
|
-
if (proxyConfig.mode === 1) {
|
|
148
|
-
return callback(proxyConfig.proxy);
|
|
149
|
-
} else if (proxyConfig.mode === 2) {
|
|
150
|
-
const proxy = callback(proxyConfig.proxy);
|
|
151
|
-
try {
|
|
152
|
-
await _axios.default.get(proxyConfig.resetApi, {
|
|
153
|
-
timeout
|
|
154
|
-
});
|
|
155
|
-
} catch {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
await (0, _index.sleep)(5);
|
|
159
|
-
for (let i = 0; i < 5; i++) {
|
|
160
|
-
try {
|
|
161
|
-
const res = await _axios.default.get("https://api64.ipify.org", {
|
|
162
|
-
timeout,
|
|
163
|
-
httpsAgent: new _hpagent.HttpsProxyAgent({
|
|
164
|
-
proxy,
|
|
165
|
-
timeout: 7000
|
|
166
|
-
})
|
|
167
|
-
});
|
|
168
|
-
if (res.status === 200) return proxy;
|
|
169
|
-
} catch {
|
|
170
|
-
await (0, _index.sleep)(3);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
} else if (proxyConfig.mode === 3) {
|
|
174
|
-
try {
|
|
175
|
-
const res = await _axios.default.get(proxyConfig.resetApi, {
|
|
176
|
-
timeout
|
|
177
|
-
});
|
|
178
|
-
if (res.status === 200) return callback(proxyConfig.proxy);
|
|
179
|
-
} catch {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
} else if (proxyConfig.mode === 4) {
|
|
183
|
-
return callback(proxyConfig.proxy).replace("{SESSION}", tokenHex(8));
|
|
184
|
-
} else if (proxyConfig.mode === 5) {
|
|
185
|
-
try {
|
|
186
|
-
const lines = proxyConfig.proxy.split("\n");
|
|
187
|
-
const line = lines[_crypto.default.randomInt(0, lines.length)];
|
|
188
|
-
return callback(line);
|
|
189
|
-
} catch {
|
|
190
|
-
return false;
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createNumDir = createNumDir;
|
|
7
|
+
exports.formatProxy = formatProxy;
|
|
8
|
+
exports.getVersion = getVersion;
|
|
9
|
+
exports.hashBcrypt = hashBcrypt;
|
|
10
|
+
exports.md5 = md5;
|
|
11
|
+
exports.proxify = proxify;
|
|
12
|
+
exports.proxyObject = proxyObject;
|
|
13
|
+
exports.serverIp = serverIp;
|
|
14
|
+
exports.tokenHex = tokenHex;
|
|
15
|
+
exports.tokenString = tokenString;
|
|
16
|
+
exports.tokenUuid = tokenUuid;
|
|
17
|
+
exports.tokenWeighted = tokenWeighted;
|
|
18
|
+
exports.verifyBcrypt = verifyBcrypt;
|
|
19
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
20
|
+
var _path = _interopRequireDefault(require("path"));
|
|
21
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
22
|
+
var _os = require("os");
|
|
23
|
+
var _child_process = require("child_process");
|
|
24
|
+
var _bcrypt = _interopRequireDefault(require("bcrypt"));
|
|
25
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
26
|
+
var _hpagent = require("hpagent");
|
|
27
|
+
var _index = require("./index.js");
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
29
|
+
function tokenString(length, useNumbers = true, useUppercase = false) {
|
|
30
|
+
const lowercaseChars = _index.CONSTANTS.LOWER_CASE;
|
|
31
|
+
const uppercaseChars = _index.CONSTANTS.UPPER_CASE;
|
|
32
|
+
const numbers = _index.CONSTANTS.NUMBERS;
|
|
33
|
+
let characters = lowercaseChars;
|
|
34
|
+
if (useUppercase) characters += uppercaseChars;
|
|
35
|
+
if (useNumbers) characters += numbers;
|
|
36
|
+
let randomString = '';
|
|
37
|
+
while (randomString.length < length) {
|
|
38
|
+
const byte = _crypto.default.randomBytes(1)[0];
|
|
39
|
+
const index = byte % characters.length;
|
|
40
|
+
if (byte < 256 - 256 % characters.length) {
|
|
41
|
+
randomString += characters[index];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return randomString;
|
|
45
|
+
}
|
|
46
|
+
function tokenHex(length) {
|
|
47
|
+
return _crypto.default.randomBytes(Math.ceil(length / 2)).toString('hex').slice(0, length);
|
|
48
|
+
}
|
|
49
|
+
function tokenUuid(useDashes = true) {
|
|
50
|
+
const uuid = _crypto.default.randomUUID().toString();
|
|
51
|
+
return useDashes ? uuid : uuid.replaceAll("-", "");
|
|
52
|
+
}
|
|
53
|
+
function tokenWeighted(dict) {
|
|
54
|
+
return (0, _index.randomWeighted)(dict, _crypto.default.randomInt);
|
|
55
|
+
}
|
|
56
|
+
function serverIp() {
|
|
57
|
+
const interfaces = (0, _os.networkInterfaces)();
|
|
58
|
+
for (const devName in interfaces) {
|
|
59
|
+
const interfaceValue = interfaces[devName];
|
|
60
|
+
for (let i = 0; i < interfaceValue.length; i++) {
|
|
61
|
+
const alias = interfaceValue[i];
|
|
62
|
+
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.address.startsWith("192.168.") && !alias.internal) return alias.address;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return '127.0.0.1';
|
|
66
|
+
}
|
|
67
|
+
function getVersion() {
|
|
68
|
+
try {
|
|
69
|
+
const date = new Date((0, _child_process.execSync)('git show -s --format=%ci HEAD').toString().trim());
|
|
70
|
+
const formatDatePart = value => value.toString().padStart(2, '0');
|
|
71
|
+
const year = date.getFullYear().toString().slice(-2);
|
|
72
|
+
const month = formatDatePart(date.getMonth() + 1);
|
|
73
|
+
const day = formatDatePart(date.getDate());
|
|
74
|
+
const hour = formatDatePart(date.getHours());
|
|
75
|
+
const minute = formatDatePart(date.getMinutes());
|
|
76
|
+
return parseFloat(`${year}${month}.${day}${hour}${minute}`);
|
|
77
|
+
} catch {
|
|
78
|
+
return 1.0;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function createNumDir(mainDirectory) {
|
|
82
|
+
_fs.default.mkdirSync(mainDirectory, {
|
|
83
|
+
recursive: true
|
|
84
|
+
});
|
|
85
|
+
for (let i = 0; i <= 9; i++) {
|
|
86
|
+
try {
|
|
87
|
+
_fs.default.mkdirSync(_path.default.join(mainDirectory, i.toString()));
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.error(`createNumDir:${i}`, e.message);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function md5(data) {
|
|
94
|
+
return _crypto.default.createHash('md5').update(data).digest("hex");
|
|
95
|
+
}
|
|
96
|
+
function hashBcrypt(plainText) {
|
|
97
|
+
return _bcrypt.default.hashSync(plainText, _bcrypt.default.genSaltSync(10));
|
|
98
|
+
}
|
|
99
|
+
function verifyBcrypt(plainText, hash) {
|
|
100
|
+
return _bcrypt.default.compareSync(plainText, hash);
|
|
101
|
+
}
|
|
102
|
+
function formatProxy(proxy, protocol = "http") {
|
|
103
|
+
proxy = proxy.trim();
|
|
104
|
+
const splitByProtocol = proxy.split("://");
|
|
105
|
+
if (1 < splitByProtocol.length) protocol = splitByProtocol[0];
|
|
106
|
+
proxy = splitByProtocol[splitByProtocol.length - 1];
|
|
107
|
+
if (!proxy.includes("@")) {
|
|
108
|
+
const proxyParts = proxy.split(":");
|
|
109
|
+
if (4 <= proxyParts.length) {
|
|
110
|
+
proxy = `${proxyParts[proxyParts.length - 2]}:${proxyParts[proxyParts.length - 1]}@`;
|
|
111
|
+
proxyParts.pop();
|
|
112
|
+
proxyParts.pop();
|
|
113
|
+
proxy += proxyParts.join(":");
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const proxyParts = proxy.split(':');
|
|
117
|
+
const proxyEnd = parseInt(proxyParts[proxyParts.length - 1]);
|
|
118
|
+
const proxyStart = proxyParts[proxyParts.length - 2];
|
|
119
|
+
if (!proxyStart.includes(".")) {
|
|
120
|
+
proxyParts.pop();
|
|
121
|
+
proxyParts[proxyParts.length - 1] = _crypto.default.randomInt(parseInt(proxyStart), proxyEnd + 1).toString();
|
|
122
|
+
}
|
|
123
|
+
return protocol + "://" + proxyParts.join(':');
|
|
124
|
+
}
|
|
125
|
+
function proxyObject(...args) {
|
|
126
|
+
let proxy = formatProxy(...args);
|
|
127
|
+
const splitByProtocol = proxy.split('://');
|
|
128
|
+
const splitById = splitByProtocol[splitByProtocol.length - 1].split('@');
|
|
129
|
+
const splitByConn = splitById[splitById.length - 1].split(':');
|
|
130
|
+
proxy = {
|
|
131
|
+
protocol: splitByProtocol[0],
|
|
132
|
+
host: splitByConn[0],
|
|
133
|
+
port: parseInt(splitByConn[1])
|
|
134
|
+
};
|
|
135
|
+
if (1 < splitById.length) {
|
|
136
|
+
const splitByAuth = splitById[0].split(':');
|
|
137
|
+
proxy.auth = {
|
|
138
|
+
username: splitByAuth[0],
|
|
139
|
+
password: splitByAuth[1]
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return proxy;
|
|
143
|
+
}
|
|
144
|
+
async function proxify(proxyConfig, callback = formatProxy) {
|
|
145
|
+
proxyConfig = proxyConfig || {};
|
|
146
|
+
const timeout = 7000;
|
|
147
|
+
if (proxyConfig.mode === 1) {
|
|
148
|
+
return callback(proxyConfig.proxy);
|
|
149
|
+
} else if (proxyConfig.mode === 2) {
|
|
150
|
+
const proxy = callback(proxyConfig.proxy);
|
|
151
|
+
try {
|
|
152
|
+
await _axios.default.get(proxyConfig.resetApi, {
|
|
153
|
+
timeout
|
|
154
|
+
});
|
|
155
|
+
} catch {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
await (0, _index.sleep)(5);
|
|
159
|
+
for (let i = 0; i < 5; i++) {
|
|
160
|
+
try {
|
|
161
|
+
const res = await _axios.default.get("https://api64.ipify.org", {
|
|
162
|
+
timeout,
|
|
163
|
+
httpsAgent: new _hpagent.HttpsProxyAgent({
|
|
164
|
+
proxy,
|
|
165
|
+
timeout: 7000
|
|
166
|
+
})
|
|
167
|
+
});
|
|
168
|
+
if (res.status === 200) return proxy;
|
|
169
|
+
} catch {
|
|
170
|
+
await (0, _index.sleep)(3);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
} else if (proxyConfig.mode === 3) {
|
|
174
|
+
try {
|
|
175
|
+
const res = await _axios.default.get(proxyConfig.resetApi, {
|
|
176
|
+
timeout
|
|
177
|
+
});
|
|
178
|
+
if (res.status === 200) return callback(proxyConfig.proxy);
|
|
179
|
+
} catch {
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
} else if (proxyConfig.mode === 4) {
|
|
183
|
+
return callback(proxyConfig.proxy).replace("{SESSION}", tokenHex(8));
|
|
184
|
+
} else if (proxyConfig.mode === 5) {
|
|
185
|
+
try {
|
|
186
|
+
const lines = proxyConfig.proxy.split("\n");
|
|
187
|
+
const line = lines[_crypto.default.randomInt(0, lines.length)];
|
|
188
|
+
return callback(line);
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
195
|
//# sourceMappingURL=node.js.map
|