-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (43 loc) · 1.37 KB
/
index.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
const { XMLParser } = require('fast-xml-parser');
const { promisify } = require('util');
const fs = require('fs');
const redis = require('redis');
var args = process.argv.slice(2);
//read xml
let path = args.includes('-v') ? args[1] : args[0];
let xmlDataStr = fs.readFileSync(path, "utf8");
const options = {
ignoreAttributes: false,
attributeNamePrefix : "@_"
};
//parse xml
const jObj = new XMLParser(options).parse(xmlDataStr);
const { subdomains, cookies } = jObj?.config;
const runApplication = async () => {
//connect to redis
const client = redis.createClient({
host: 'redis-server',
port: 6379
});
client.on('connect',()=>{
console.log("redis connected")
});
client.on('error', err => {
console.log('Error ' + err);
});
const setAsync = promisify(client.set).bind(client);
const getAsync = promisify(client.get).bind(client);
//set cache
await setAsync('subdomains', JSON.stringify(subdomains?.subdomain));
cookies.cookie.forEach(async (element, index) => {
await setAsync(`cookie:${element['@_name']}:${element['@_host']}`, element['#text']);
});
if(args.includes('-v')){
client.keys("*", function(err, replies) {
replies.forEach(function(reply, index) {
console.log(reply.toString());
});
});
}
};
runApplication();