mirror of
https://github.com/jwinterm/node-tip-bot.git
synced 2026-10-25 05:58:35 +01:00
extended web interface
This commit is contained in:
+52
-10
@@ -5,8 +5,9 @@ var express = require('express')
|
||||
module.exports.app = function(port, coin, settings, winston) {
|
||||
var app = express();
|
||||
|
||||
app.use(express.static(path.join(__dirname, '/static')));
|
||||
app.use(express.basicAuth(function(user, password) {
|
||||
var success = settings.users[user] == password;
|
||||
var success = settings.webadmin.users[user] == password;
|
||||
if(success)
|
||||
winston.info('%s logged into webadmin', user);
|
||||
else
|
||||
@@ -18,26 +19,67 @@ module.exports.app = function(port, coin, settings, winston) {
|
||||
var tpl = swig.compileFile(path.join(__dirname, '/views/index.html'));
|
||||
app.get('/', function(req, res) {
|
||||
var accounts = [];
|
||||
coin.listAccounts(5, function(err, reply) {
|
||||
coin.listAccounts(5, function(err, balances) {
|
||||
if(err) {
|
||||
winston.error('Tried to get account listing but failed.', err);
|
||||
res.send(500, 'Could not get account list');
|
||||
return;
|
||||
}
|
||||
for(var user in reply) {
|
||||
if(user !== "")
|
||||
accounts.push({nick: user, balance: reply[user]});
|
||||
};
|
||||
coin.listAccounts(0, function(err, unconfirmed_balances) {
|
||||
if(err) {
|
||||
winston.error('Tried to get account listing but failed.', err);
|
||||
res.send(500, 'Could not get account list');
|
||||
return;
|
||||
}
|
||||
var total = 0;
|
||||
var total_unconfirmed = 0;
|
||||
for(var user in balances) {
|
||||
if(user !== "")
|
||||
accounts.push({
|
||||
nick: user
|
||||
, balance: balances[user]
|
||||
, unconfirmed_balance: unconfirmed_balances[user] - balances[user]
|
||||
});
|
||||
total += balances[user];
|
||||
total_unconfirmed += unconfirmed_balances[user];
|
||||
};
|
||||
|
||||
accounts.sort(function(a, b) {
|
||||
return b.balance - a.balance
|
||||
accounts.sort(function(a, b) {
|
||||
return b.balance - a.balance
|
||||
});
|
||||
|
||||
var body = tpl({
|
||||
accounts: accounts
|
||||
, coin: settings.coin
|
||||
, total: total
|
||||
, total_unconfirmed: total_unconfirmed
|
||||
});
|
||||
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.setHeader('Content-Length', Buffer.byteLength(body));
|
||||
res.end(body);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/user/:user', function(req, res) {
|
||||
var user = req.params.user;
|
||||
coin.getAddressesByAccount(user.toLowerCase(), function(err, addresses) {
|
||||
if(err) {
|
||||
winston.error('Tried to get address listing but failed.', err);
|
||||
res.send(500, 'Could not get address list');
|
||||
return;
|
||||
}
|
||||
|
||||
var body = JSON.stringify({
|
||||
addresses: addresses
|
||||
});
|
||||
|
||||
var body = tpl({accounts: accounts});
|
||||
res.setHeader('Content-Type', 'text/html');
|
||||
res.setHeader('Content-Type', 'text/json');
|
||||
res.setHeader('Content-Length', Buffer.byteLength(body));
|
||||
res.end(body);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
app.listen(port);
|
||||
|
||||
Reference in New Issue
Block a user