1
0
mirror of https://github.com/GOSTSec/gostexplr synced 2025-01-30 00:14:22 +00:00
gostexplr/routes/address.js

44 lines
943 B
JavaScript
Raw Normal View History

2018-02-03 21:14:56 +05:00
var models = require('../models');
var express = require('express');
var router = express.Router();
/* GET home page. */
2018-02-06 23:24:20 +05:00
router.get('/:address/:offset*?', async function(req, res, next) {
2018-02-03 21:14:56 +05:00
const safe_address = encodeURI(req.params.address);
const address = await models.Address.findOne({
where: {
address: safe_address,
},
include: {
model: models.Vout,
include: {
model: models.Transaction,
2018-08-16 01:49:00 +05:00
},
},
});
2018-02-03 21:14:56 +05:00
if (address === null) {
2018-02-03 23:54:25 +05:00
res.status(404).render('404');
return;
}
2018-02-11 14:26:23 +05:00
const limit = 30;
const paramPage = parseInt(req.params.offset);
const page = isNaN(paramPage) || paramPage < 1 ? 1 : paramPage;
const offset = 30 * (page - 1);
2018-02-06 23:24:20 +05:00
const nextpage = address.Vouts.length === 30 ? page + 1 : null;
2018-02-06 23:24:20 +05:00
const prevpage = page > 1 ? page - 1 : null;
2018-02-03 23:54:25 +05:00
res.render('address', {
address: address.toJSON(),
2018-02-06 23:24:20 +05:00
nextpage,
prevpage,
2018-02-03 21:14:56 +05:00
});
});
module.exports = router;