-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
65 lines (58 loc) · 1.9 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const app_config = require('./config.json');
const Bni = require('./bni');
const http = require('http');
const { io } = require("socket.io-client");
const arguments = process.argv;
let env = 'dev';
if (arguments[2]) env = arguments[2];
const config = ((env.toString().toLowerCase() == 'prod') ? app_config.prod : app_config.dev);
const server = http.createServer();
const socket = io(config.socket);
socket.on("reciveData", (data) => {
data.transaction.forEach(e => {
browser(config, e, data.server);
});
})
const browser = async (cnf, data, server) => {
const ress = {
status : false,
}
const AppBni = new Bni(cnf, data.account);
try {
const login = await AppBni.login();
if (!login.informasi_login) {
ress.errors = "Failed Login [not have informasi-login]";
ress.response = login;
} else {
ress.status = true;
ress.data = login.informasi_login;
ress.user = login.informasi_login.user.trim();
if (data.type == "saldo") {
ress.html = await AppBni.infoSaldo();
}else if (data.type == "mutasi") {
ress.html = await AppBni.mutasiRekening(data.account);
}
await AppBni.logout();
}
data.data = JSON.stringify(ress);
socket.emit("updateData", {
transaction: data,
server: server
});
} catch (error) {
ress.errors = error.message;
data.data = JSON.stringify(ress);
socket.emit("updateData", {
transaction: data,
server: server
});
await AppBni.closeWindows();
console.log("error dari sini => ", error);
}
}
server.listen(config.server_params.port, config.server_params.host, (Errors) => {
if (Errors) {
throw Errors;
}
console.log("App BNI Scraper Running on Port:", config.server_params.port);
});