This commit is contained in:
Expand-sys 2021-06-24 12:18:55 +10:00
parent 6ba054de60
commit 70cd9f59a1
5 changed files with 78 additions and 2458 deletions

133
index.js
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,76 +126,86 @@ fastify.get(
console.log(err);
}
let balance = 0;
balance = await client.balance(req.session.get("user"));
console.log(balance);
let logsent;
console.log("start " + Date.now());
try {
const user = req.session.get("user");
const password = req.session.get("password");
logsent = await client.log(user, password);
} catch (e) {
console.log(e);
}
console.log(logsent);
let logrec = logsent;
let graphlog = logsent;
if (graphlog != null) {
graphlog = graphlog.reverse();
}
let 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 + "]";
} else {
currentbal = parseInt(currentbal) - parseInt(graphlog[i].amount);
graphdata = graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
let logsent = [];
let logrec = [];
if (admin != 1) {
balance = await client.balance(req.session.get("user"));
console.log(balance);
let logsent;
console.log("start " + Date.now());
try {
const user = req.session.get("user");
const password = req.session.get("password");
logsent = await client.log(user, password);
} catch (e) {
console.log(e);
}
console.log(logsent);
logrec = logsent;
graphlog = logsent;
if (graphlog != null) {
graphlog = graphlog.reverse();
}
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 + "]";
} else {
currentbal = parseInt(currentbal) - parseInt(graphlog[i].amount);
graphdata =
graphdata + ", [" + parseInt(i) + "," + currentbal + "]";
}
}
} else {
graphlog = undefined;
}
if (graphdata != "") {
graphdata =
", [" + parseInt(graphlog.length) + "," + balance + "]" + graphdata;
graphdata = '["transaction", "balance"]' + graphdata;
}
if (logsent == null) {
logsent = undefined;
} else {
logsent = await logsent.filter(
({ from }) => from === req.session.get("user")
);
}
if (logrec == null) {
logrec = undefined;
} else {
logrec = await logrec.filter(
({ to }) => to === req.session.get("user")
);
}
if (logsent) {
for (i in logrec) {
logrec[i].time = new Date(logrec[i].time);
}
}
} else {
graphlog = undefined;
}
if (graphdata != "") {
graphdata =
", [" + parseInt(graphlog.length) + "," + balance + "]" + graphdata;
graphdata = '["transaction", "balance"]' + graphdata;
}
if (logsent == null) {
logsent = undefined;
} else {
logsent = await logsent.filter(
({ from }) => from === req.session.get("user")
);
}
if (logrec == null) {
logrec = undefined;
} else {
logrec = await logrec.filter(({ to }) => to === req.session.get("user"));
}
if (logsent) {
for (i in logrec) {
logrec[i].time = new Date(logrec[i].time);
if (logrec) {
for (i in logsent) {
logsent[i].time = new Date(logsent[i].time);
}
}
if (logrec != null) {
logrec.reverse();
}
if (logsent != null) {
logsent.reverse();
}
}
if (logrec) {
for (i in logsent) {
logsent[i].time = new Date(logsent[i].time);
}
}
if (logrec != null) {
logrec.reverse();
}
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"),

2388
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -2,23 +2,13 @@
"dependencies": {
"@mgcrea/fastify-session": "^0.14.1",
"ccash-client-js": "^1.8.1",
"connect-flash": "^0.1.1",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"express-messages": "^1.0.1",
"express-session": "^1.17.1",
"express-validator": "5.3.1",
"fastify": "^3.18.0",
"fastify-auth": "^1.1.0",
"fastify-basic-auth": "^2.0.0",
"fastify-cookie": "^5.3.1",
"fastify-flash": "^2.0.2",
"fastify-formbody": "^5.0.0",
"fastify-jwt": "^3.0.0",
"fastify-jwt-webapp": "^0.11.1",
"fastify-plugin": "^3.0.0",
"fastify-secure-session": "^2.3.1",
"fastify-session": "^5.2.1",
"fastify-static": "^4.2.2",
"fastify-tls-keygen": "^1.1.0",
"got": "^11.8.2",

View file

@ -1,8 +1,6 @@
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");

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");