Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathutils.js
More file actions
Latest commit
94 lines (88 loc) · 2.48 KB
/
Copy pathutils.js
File metadata and controls
94 lines (88 loc) · 2.48 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
constmoment=require('moment');
const_=require('lodash');
constfs=require('fs');
constredis=require('redis').createClient();
constsettings=require('./settings.json');
conststripe=require("stripe")(settings.stripe.secretKey);
redis.config('SET','maxmemory',settings.general.redisMaxMemory);
redis.on('error',err=>module.exports.logger(err)&&module.exports.syslog(err));
letdbOnline=true;
module.exports={
pad(n,width,z){
z=z||'0';
n=n+'';
returnn.length>=width ? n : newArray(width-n.length+1).join(z)+n;
},
logger(msg){
if(typeoflog==='undefined'){
log={
log: console.log
};
}
// Clear log
if(msg===true){
for(leti=0;i<10;i++){
log.log('');
}
log.logLines=[];
}else{
log.log(moment().format('LTS')+' - '+msg);
}
},
syslog(msg,req={session: null}){
try{
thrownewError();
}catch(e){
fs.appendFileSync('./RandomAPI.log',"["+moment().format()+"] "+msg+"\n"+e.stack.toString()+"\n"+JSON.stringify(req.session)+"\n");
}
},
random(mode,length){
letresult='';
letchars;
if(mode===1){
chars='abcdef1234567890';
}elseif(mode===2){
chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
}elseif(mode===3){
chars='0123456789';
}elseif(mode===4){
chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ';
}elseif(mode===5){
chars='abcdefghijklmnopqrstuvwxyz1234567890';
}elseif(mode===6){
chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
}
for(leti=0;i<length;i++){
result+=chars[module.exports.range(0,chars.length-1)];
}
returnresult;
},
range(min,max){
returnMath.floor(Math.random()*(max-min+1))+min;
},
andify(cond){
constdb=require('./models/db').connection;
varformatted="";
if(Object.keys(cond).length>1){
_.each(cond,function(value,key){
formatted+="`"+key+"` = "+db.escape(value)+" AND ";
});
return{query: formatted.slice(0,-5)};
}else{
returncond;
}
},
missingProps(obj,expected){
return!expected.every(prop=>propinobj&&obj[prop]!==undefined);
},
dbStatus(status){
if(status===undefined){
returndbOnline;
}else{
dbOnline=status;
}
},
redis,
stripe,
settings
};