changes for reduction of nodemodules

This commit is contained in:
Expand-sys 2021-06-24 12:39:27 +10:00
parent 6a8c4f9331
commit a66f6f2be8
3 changed files with 73 additions and 68 deletions

View file

@ -29,6 +29,7 @@ fastify.register(require("fastify-secure-session"), {
// options for setCookie, see https://github.com/fastify/fastify-cookie
secure: false,
httpOnly: true,
overwrite: true,
},
});
fastify.register(fastifyFlash);
@ -125,6 +126,10 @@ fastify.get(
console.log(err);
}
let balance = 0;
let graphdata = "";
let logsent = [];
let logrec = [];
if (admin != 1) {
balance = await client.balance(req.session.get("user"));
console.log(balance);
let logsent;
@ -137,21 +142,23 @@ fastify.get(
console.log(e);
}
console.log(logsent);
let logrec = logsent;
let graphlog = logsent;
logrec = logsent;
graphlog = logsent;
if (graphlog != null) {
graphlog = graphlog.reverse();
}
let graphdata = "";
graphdata = "";
let currentbal = balance;
if (graphlog) {
for (i = graphlog.length - 1; i > -1; i--) {
if (graphlog[i].from == req.session.get("user")) {
currentbal = parseInt(currentbal) + parseInt(graphlog[i].amount);
graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
graphdata =
graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
} else {
currentbal = parseInt(currentbal) - parseInt(graphlog[i].amount);
graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
graphdata =
graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
}
}
} else {
@ -172,7 +179,9 @@ fastify.get(
if (logrec == null) {
logrec = undefined;
} else {
logrec = await logrec.filter(({ to }) => to === req.session.get("user"));
logrec = await logrec.filter(
({ to }) => to === req.session.get("user")
);
}
if (logsent) {
for (i in logrec) {
@ -190,11 +199,13 @@ fastify.get(
if (logsent != null) {
logsent.reverse();
}
}
let maxgraph = balance + 1000;
console.log("begin render " + Date.now());
res.view("bankf", {
maxgraph: maxgraph,
graphdata: graphdata,
graphdata: graphdata || null,
logrec: logrec,
logsent: logsent,
user: req.session.get("user"),
@ -343,7 +354,7 @@ process.on("SIGINT", function () {
process.exit();
});
fastify.listen(process.env.PORT || 3000, function (err, address) {
fastify.listen(process.env.PORT || 3000, "0.0.0.0", function (err, address) {
if (err) {
fastify.log.error(err);
process.exit(1);

View file

@ -1,13 +1,10 @@
const root = process.env.PWD;
const path = require("path");
const pug = require("pug");
const flash = require("connect-flash");
const expressValidator = require("express-validator");
const { postUser } = require(`${root}/helpers/functions.js`);
const got = require("got");
const fs = require("fs");
const mongoose = require("mongoose");
const { CCashClient } = require("ccash-client-js");

View file

@ -1,9 +1,6 @@
const root = process.env.PWD;
const path = require("path");
var pug = require("pug");
const flash = require("connect-flash");
const expressValidator = require("express-validator");
const session = require("express-session");
const { postUser } = require(`${root}/helpers/functions.js`);
const { CCashClient } = require("ccash-client-js");