forked from Bastian/bStats
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathglobal.js
55 lines (51 loc) · 1.72 KB
/
global.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
const express = require('express');
const router = express.Router();
const dataManager = require('../util/dataManager');
const waterfall = require('async-waterfall');
/* GET global page. */
router.get('/:software', function(req, res, next) {
waterfall([
function (callback) {
dataManager.getGlobalPluginBySoftwareUrl(req.params.software, ['name', 'software', 'owner'], function (err, plugin) {
if (err) {
callback(err);
return;
}
if (plugin === null) { // TODO render proper page
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify({
error: 'Unknown software'
}));
res.end();
return;
}
callback(null, plugin);
});
},
function (plugin, callback) {
dataManager.getSoftwareById(plugin.software, ['name'], function (err, res) {
if (err) {
callback(err);
return;
}
callback(null, plugin, res);
});
}
], function (err, plugin, software) {
if (err) {
console.log(err);
res.writeHead(200, {'Content-Type': 'application/json'});
res.write(JSON.stringify({
error: 'Unknown error'
}));
res.end();
return;
}
res.render('global', {
plugin: plugin,
software: software
});
}
);
});
module.exports = router;