forked from PrivateSky/swarmutils
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
71 lines (60 loc) · 2.02 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
let cachedUIDGenerator = undefined;
let cachedSafeUid = undefined;
function initCache() {
if (cachedUIDGenerator === undefined) {
cachedUIDGenerator = require("./lib/uidGenerator").createUidGenerator(200, 32);
let sfuid = require("./lib/safe-uuid");
sfuid.init(cachedUIDGenerator);
cachedSafeUid = sfuid.safe_uuid;
}
}
module.exports = {
get generateUid() {
initCache();
return cachedUIDGenerator.generateUid;
},
safe_uuid: function () {
initCache();
return cachedSafeUid();
}
};
module.exports.OwM = require("./lib/OwM");
module.exports.beesHealer = require("./lib/beesHealer");
module.exports.Queue = require("./lib/Queue");
module.exports.combos = require("./lib/Combos");
module.exports.TaskCounter = require("./lib/TaskCounter");
module.exports.SwarmPacker = require("./lib/SwarmPacker");
module.exports.path = require("./lib/path");
module.exports.createPskConsole = function () {
return require('./lib/pskconsole');
};
module.exports.pingPongFork = require('./lib/pingpongFork');
module.exports.ensureIsBuffer = function (data) {
if ($$.Buffer.isBuffer(data)) {
return data;
}
let buffer;
if (ArrayBuffer.isView(data)) {
buffer = $$.Buffer.from(data.buffer)
} else {
buffer = $$.Buffer.from(data);
}
return buffer;
}
module.exports.removeDir = require("./lib/removeDir").removeDir;
module.exports.removeDirSync = require("./lib/removeDir").removeDirSync;
module.exports.isValidDomain = function(domain){
const urlParamRegex = /^[a-zA-Z0-9\-_.\/]+$/;
return urlParamRegex.test(domain);
}
module.exports.validatePath = function(user_input) {
if (user_input.indexOf('\0') !== -1) {
throw 'Access denied';
}
if (!/^(?:(?:\.\/|\/)(?!.*(?:^|\/)\.\.(?:\/|$))(?:[^\/\s]+\/)*[^\/\s]*|\/)$/.test(user_input)) {
throw 'Access denied';
}
let path = require('path');
let safe_input = path.normalize(user_input).replace(/^(\.\.(\/|\\|$))+/, '');
return safe_input;
}