-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutils.js
44 lines (39 loc) · 895 Bytes
/
utils.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
/*
* Module dependencies
*/
var crypto = require('crypto');
/*
* Generate a short url
*/
exports.shorten_url = function(){
var shasum = crypto.createHash('sha1');
shasum.update(Date.now().toString());
return shasum.digest('hex').substr(0,6);
};
exports.async_queries = function (queue, callback) {
var to_go = queue.length;
var results = {};
queue.forEach(function(query){
var collection = query.collection;
switch(query.type) {
case 'find':
qr = collection.find(query.query);
break;
case 'findOne':
qr = collection.findOne(query.query)
break;
default:
qr = false;
}
if(qr) {
if(query.desc) { qr.sort('-' + query.desc); }
if(query.limit) { qr.limit(query.limit); }
qr.exec(function(err, res) {
results[query.name] = res;
if (--to_go == 0) callback(results);
});
} else {
--to_go
}
});
};