Commit 6e31bbf9 authored by Cédric Moreau's avatar Cédric Moreau

[feat] add old js files Baptiste Lemoine 02/05/2020 19:03

parent 24a8d2e6
Pipeline #9009 passed with stage
in 41 seconds
node_modules
yarn.lock
.idea
routes/*.js
routes/*.js.map
routes/*.d.ts
routes/*.js*
lib/*.js
lib/*.js.map
lib/*.d.ts
lib/*.js*
modules/*.js
modules/*.js.map
modules/*.d.ts
modules/*.js*
/**/*.map
#!/usr/bin/bash
echo "===== remove generated typescript files"
rm -rf modules/{*.js,*.js.map,*.d.ts}
rm -rf lib/{*.js,*.js.map,*.d.ts}
rm -rf routes/{*.js,*.js.map,*.d.ts}
rm -rf modules/{*.js.map,*.d.ts}
rm -rf lib/{*.js.map,*.d.ts}
rm -rf routes/{*.js.map,*.d.ts}
rm -rf test/{*.js,*.js.map,*.d.ts}
echo "===== clean done"
......
"use strict";
const co = require('co');
const fs = require('fs');
const path = require('path');
const main = require(__dirname + '/lib/main.js');
const indexing = require(__dirname + '/lib/indexing.js');
const initMonitDB = require('./lib/DataFinder').initMonitDB;
/****************************************
* TECHNICAL CONFIGURATION
***************************************/
// Default Duniter node's database
//const DEFAULT_DUNITER_DATA_FOLDER = 'currency-monit-dev';
// host on which UI is available
const DEFAULT_ACTION = 'start';
// host on which UI is available
const DEFAULT_HOST = 'localhost';
// port on which UI is available
const DEFAULT_PORT = 10500;
/****************************************
* SPECIALIZATION
***************************************/
/*const stack = duniter.statics.autoStack([{
name: 'currency-monit',
required: {*/
module.exports = {
duniter: {
config: {
onLoading: (conf:any, program:any) => co(function*() {
// Define duniter-currency-monit parameters namespace
const obj = conf['duniter-currency-monit'] = conf['duniter-currency-monit'] || {}
})
},
cliOptions: [
{ value: '--monitor', desc: 'Enable performance monitoring of DB access'},
{ value: '--reset-data', desc: 'Forces Monit to reset its indexed data on startup'},
],
cli: [{
name: 'currency-monit [start|indexing] [host] [port]',
desc: 'Start duniter with module currency-monit or Indexing blockchain history',
preventIfRunning: true,
logs: false,
onDatabaseExecute: (server:any, conf:any, program:any, params:any, startServices:any) => co(function*() {
// currency-monit parameters
const ACTION = params[0] || DEFAULT_ACTION;
const SERVER_HOST = params[1] || DEFAULT_HOST;
const SERVER_PORT = parseInt(params[2]) || DEFAULT_PORT;
if (ACTION == "start")
{
// IMPORTANT: release Duniter services from "sleep" mode
yield startServices();
// Main Loop
yield main(server, SERVER_HOST, SERVER_PORT, null, program);
// Wait forever, this is a permanent program
yield new Promise(() => null);
}
else if (ACTION == "indexing")
{
try {
indexing(server, conf, program, params);
} catch (err) {
console.error('Error during blockchain indexing ', err);
}
// Close the DB connection properly
return server && server.disconnect()
}
else
{
console.error('Error unknow action "%s" !', ACTION);
// Close the DB connection properly
return server && server.disconnect()
}
})
}, {
name: 'reindex',
desc: 'Reset indexed Monit data and rebuild index',
preventIfRunning: true,
logs: false,
async onDatabaseExecute(server:any, conf:any, program:any, params:any, startServices:any) {
await initMonitDB(server, true);
}
}]
},
duniterUI: {
inject: {
menu: fs.readFileSync(path.join(__dirname, 'injection/menu.js'), 'utf8')
},
route: (app:any, server:any, conf:any, program:any, params:any) => {
// Main Loop
//main(server, SERVER_HOST, SERVER_PORT);
main(server, null, null, app, program); // `app` est un serveur HTTP Express
// Wait forever, this is a permanent program
new Promise(() => null);
}
}
}
{
"name": "duniter-currency-monit",
"version": "0.4.15",
"main": "index.js",
"main": "index.ts",
"license": "AGPLv3",
"scripts": {
"installation": "yarn --pure-lockfile && npm start",
"start": "node run.js currency-monit",
"start": "nodemon run.js currency-monit",
"clean": "bash clean_generated_typescript.sh",
"sync": "node run.js sync g1.duniter.org 1000",
"sync-full": "node run.js sync g1.duniter.org",
......@@ -22,6 +22,7 @@
"jquery": "^3.5.0",
"morgan": "1.8.1",
"node-pre-gyp": "0.6.34",
"nodemon": "^2.0.3",
"q": "1.5.0",
"request": "^2.81.0",
"request-promise": "4.2.0",
......@@ -29,13 +30,13 @@
"underscore": "^1.9.1"
},
"devDependencies": {
"@types/node": "^11.9.3",
"@types/mocha": "^2.2.41",
"@types/node": "^11.9.3",
"duniter": "1.7.x",
"typescript": "^3.3.3",
"mocha": "^3.4.2",
"should": "*",
"ts-node": "^3.3.0"
"ts-node": "^3.3.0",
"typescript": "^3.3.3"
},
"peerDependencies": {
"duniter": "1.7.x"
......
This diff is collapsed.
html {
overflow-y: scroll;
}
main {
min-height: 80vh;
padding: 0 4rem;
margin-bottom:5rem;
}
footer {
margin-top: 2em;
text-align: center;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #333;
}
.menu li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover:not(.active) {
background-color: #111;
}
.active {
background-color: #4CAF50;
}
span[data-tip] {
border-bottom: 1px dotted #000;
}
[data-tip] {
display: inline-block;
position: relative;
}
[data-tip]:hover:before {
content: attr(data-tip);
position: absolute;
padding: 0 8px;
height: 28px;
line-height: 28px;
background-color: rgba(0, 0, 0, 0.8);
left: -10px;
top: -38px;
border-radius: 3px;
white-space: nowrap;
color: #fff;
font-size: 11px;
}
[data-tip]:hover:after {
content: "";
position: absolute;
border-top: 8px solid rgba(0, 0, 0, 0.8);
border-left: 8px solid transparent;
border-right: 8px solid transparent;
left: 0;
top: -10px;
}
.sentry {
float: left;
width: 200px;
height: 21px;
overflow: hidden;
}
.arrow {
width: 50px;
}
.isMax {
border-right: 1px dashed gray;
}
.isSentry, .isSentry a {
text-decoration: none;
color: #6f93ff;
}
.isSentry, .isSentry a:visited {
text-decoration: none;
color: #6f93ff;
}
.isPending, .isPending a {
text-decoration: none;
color: #ffc55a !important;
font-weight: bold;
}
.isMember, .isMember a {
text-decoration: none;
color: black !important;
}
.isNonMember, .isNonMember a {
text-decoration: none;
color: #FF596A !important;
}
.isPendingCert, .isPendingCert a {
text-decoration: none;
color: #ffc55a;
font-weight: bold;
}
.isPending, .isPending a:visited {
text-decoration: none;
color: #ffc55a !important;
font-weight: bold;
}
.isMember, .isMember a:visited {
text-decoration: none;
color: black !important;
}
.isNonMember, .isNonMember a:visited {
text-decoration: none;
color: #ff596a !important;
}
.isPendingCert, .isPendingCert a:visited {
text-decoration: none;
color: #ffc55a;
font-weight: bold;
}
.members-page input[type=number]{
max-width: 15em;
display:inline-block;
margin-right: 1em;
}
.dataTables_wrapper thead tr td,
thead thead tr td
{
background: #ecf0f3;
}
td {
text-align: center;
}
td.bordering-element{
width: 3px !important;
background: #000;
padding: 0 !important;
}
.x-scroll{
max-width: 100%;
display: block;
overflow-x: scroll;
}
input {
margin-bottom: 0.5em;
margin-top: 0.5em;
}
input[type=number],
input[type=text]
{
min-width: 15em;
}
input[type=checkbox],
input[type=radio]
{
margin: 0 1ch;
width: 1em;
height: 1em;
}
.sentry a {
display: block;
}
.sentry a:hover {
background: #dedede;
}
const fs = require('fs')
const express = require('express')
const constants = require(__dirname + '/../lib/constants2').MonitConstants
const getLang = require(__dirname + '/../lib/getLang')
const printMenu = require(__dirname + '/../views/printMenu')
var app = express.Router()
app.use(express.static(__dirname + '/public'));
function jsonFormat( req:any, res:any, next:any )
{
var format = req.query.format || 'HTML'
if (format == 'JSON' && res.locals.json )
res.status(200).jsonp( res.locals.json )
else
next()
}
/*
Les routes sont en 2 ou 3 parties:
app.VERB( chemin, rendu )
app.VERB( chemin, controleur, rendu )
Par exemple, home et about n'ont pas besoin de controleur
*/
/***************************************
* Home Page
***************************************/
app.get('/', // chemin (endpoint)
(req:any , res:any)=> res.render('about.html', { // rendu (template)
host: req.headers.host.toString(),
printMenu,
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/about_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* About Page
***************************************/
app.get('/about', // chemin (endpoint)
(req:any , res:any)=> res.render('about.html', { // rendu (template)
host: req.headers.host.toString(),
printMenu,
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/about_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* Lister les futurs membres
***************************************/
app.get('/willMembers', // chemin (endpoint)
require(__dirname + '/willMembers2.js'), // controleur (route)
(req:any , res:any)=> res.render('willMembers.html', { // rendu (template)
printMenu,
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/willMembers_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* Lister les membres
***************************************/
app.get('/members',
require(__dirname + '/members2.js'),
(req:any , res:any)=> res.render('members.html', {
printMenu,
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/members_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* Lister les anciens membres
***************************************/
/*app.get('/wasMembers',
require(__dirname + '/wasMembers.js'),
(req:any , res:any)=> res.render('wasMembers.html', {
printMenu,
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/wasMembers_${lg}.txt`)
})
)*/
/***************************************
* Évolution du nombre de membres
***************************************/
app.get('/membersCount',
require(__dirname + '/../lib/updateCache2.js'), require(__dirname + '/membersCount2.js'),
(req:any , res:any)=> res.render('Chart.html', {
printMenu,
pageName: 'MEMBERS_COUNT',
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/membersCount_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* Wotex
***************************************/
app.get('/wotex',
require(__dirname + '/wotex2.js'),
(req:any , res:any)=> res.render('wotex.html', {
printMenu,
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/wotex_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/*******************************************
* Graphe gaussien de la qualité des membres
********************************************/
app.get('/gaussianWotQuality',
require(__dirname + '/gaussianWotQuality2.js'),
(req:any , res:any)=> res.render('Chart.html', {
printMenu,
pageName: 'GAUSSIAN_WOT_QUALITY',
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/gaussianWotQuality_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* Lister les block en graphe
***************************************/
app.get('/blockCount',
require(__dirname + '/blockCount2.js'),
(req:any , res:any)=> res.render('Chart.html', {
printMenu,
pageName: 'BLOCK_COUNT',
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/blockCount_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
/***************************************
* Évolution de la masse monétaire totale
***************************************/
app.get('/monetaryMass',
require(__dirname + '/monetaryMass2.js'),
(req:any , res:any)=> res.render('Chart.html', {
printMenu,
pageName: 'MONETARY_MASS',
help: req.query.help,
MENU_LANG: getLang(`${__dirname}/../lg/menu_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`),
LANG: getLang(`${__dirname}/../lg/monetaryMass_${req.query.lg||constants.DEFAULT_LANGUAGE}.txt`)
})
)
module.exports = app
......@@ -42,11 +42,11 @@ var nbShortestsPath = 0;
module.exports = async (req: any, res: any, next: any) => {
var { duniterServer } = req.app.locals
var { duniterServer } = req.app.locals;
const dataFinder = await DataFinder.getInstanceReindexedIfNecessary();
const dataFinder = await DataFinder.getInstanceReindexedIfNecessary()
try {
// Initaliser les constantes
const conf = duniterServer.conf;
......@@ -54,7 +54,7 @@ module.exports = async (req: any, res: any, next: any) => {
const currentBlockchainTimestamp = head ? head.medianTime : 0;
const membersCount = head ? head.membersCount : 0;
var dSen = Math.ceil(Math.pow(membersCount, 1 / conf.stepMax));
// Initaliser les variables
let membersListOrdered = [];
let membersCertifsListSorted = [];
......@@ -101,10 +101,10 @@ module.exports = async (req: any, res: any, next: any) => {
}
// Alimenter wotb avec la toile actuelle
const wotbInstance = duniterServer.dal.wotb;
// Vérifier si le cache doit être Réinitialiser
let reinitCache = (Math.floor(Date.now() / 1000) > (membersLastUptime + MonitConstants.MIN_MEMBERS_UPDATE_FREQ));
// Si changement de conditions, alors forcer le rechargement du cache s'il n'est pas vérouillé, sinon forcer les conditions à celles en mémoire
// Si recherche par UID ou pubkey => recharger systématiquement
if (uidOrPubList || previousMode != mode || previousCentrality != centrality || previousNextYn != nextYn || previousRandomList != randomList || numberOfRandomMembers != previousRandomCounts)
......@@ -133,7 +133,7 @@ module.exports = async (req: any, res: any, next: any) => {
{
reinitCache = false;
}
if (reinitCache)
{
// Réinitialiser le cache
......@@ -168,7 +168,7 @@ module.exports = async (req: any, res: any, next: any) => {
// réinitialiser le cache des données de qualité
membersQuality(MonitConstants.QUALITY_CACHE_ACTION.INIT, 0, dSen, conf.stepMax, conf.xpercent, wotbInstance.memCopy());
// Réinitialiser le cache des données de centralité
if (centrality=='yes')
{
......@@ -178,10 +178,10 @@ module.exports = async (req: any, res: any, next: any) => {
meanShortestsPathLength = 0;
nbShortestsPath = 0;
}
// Récupérer la liste des membres référents
sentries = wotbInstance.getSentries(dSen);
// Récupérer la liste des identités ayant actuellement le statut de membre
membersList = await dataFinder.getMembers()
......@@ -203,7 +203,7 @@ module.exports = async (req: any, res: any, next: any) => {
return m.uid.toLocaleLowerCase().includes(uidOrPubValue) || m.pub.toLocaleLowerCase().includes(uidOrPubValue)
})
}
// Récupérer pour chaque identité, le numéro du block d'écriture du dernier membership
// Ainsi que la première ou dernière certification
for (let m=0;m<membersList.length;m++)
......@@ -211,17 +211,17 @@ module.exports = async (req: any, res: any, next: any) => {
// Récupérer les blockstamp d'écriture et date d'expiration du membership courant du membre m
let tmpQueryResult = [await dataFinder.membershipWrittenOnExpiresOn(membersList[m].pub)];
membershipsExpireTimeList.push(tmpQueryResult[0].expires_on);