80 lines
2.0 KiB
JavaScript
80 lines
2.0 KiB
JavaScript
const got = require('got')
|
|
fs = require('fs');
|
|
var tableify = require('tableify');
|
|
const express = require('express')
|
|
const app = express()
|
|
const port = 6969
|
|
|
|
const url = "http://webservgroup.xyz/smarters4567891/api/home.php?action=dns"
|
|
|
|
var streamArrays = require('./streamArray.json')
|
|
|
|
const gotRequest = async (url) => {
|
|
|
|
let returnResponse = {};
|
|
let options = {}
|
|
await got(url, options)
|
|
.then((response) => {
|
|
returnResponse = response;
|
|
})
|
|
.catch((error) => {
|
|
returnResponse = typeof error.response !== 'undefined' ? error.response : error;
|
|
|
|
if (typeof returnResponse.body === 'string' && returnResponse.body.substring(0, 1) === '{') {
|
|
returnResponse.body = JSON.parse(returnResponse.body);
|
|
}
|
|
});
|
|
|
|
return returnResponse;
|
|
};
|
|
|
|
function writeFile(streamArrays) {
|
|
fs.writeFileSync('streamArray.json', JSON.stringify(streamArrays), function (err) {
|
|
if (err) return console.log(err);
|
|
});
|
|
}
|
|
|
|
function splitToArray(DNS) {
|
|
DNS = DNS.split(',')
|
|
return DNS
|
|
}
|
|
|
|
function mapToStream(DNSList) {
|
|
console.log('---Updated URLS---')
|
|
for (let index = 0; index < streamArrays.length; index++) {
|
|
let element = streamArrays[index];
|
|
element.StreamURL = DNSList[index]
|
|
console.log(element.StreamName + ' ' + element.StreamURL)
|
|
}
|
|
writeFile(streamArrays)
|
|
console.log('---Updated URLS---')
|
|
return streamArrays
|
|
}
|
|
|
|
async function main(url) {
|
|
const t = await gotRequest(url)
|
|
let DNSList = JSON.parse(t.body)
|
|
DNSList = splitToArray(DNSList.su)
|
|
await mapToStream(DNSList)
|
|
return streamArrays
|
|
}
|
|
|
|
function arrayToTable(array) {
|
|
return tableify(array)
|
|
}
|
|
|
|
async function server() {
|
|
|
|
app.get('/', async (req, res) => {
|
|
let t = await main(url)
|
|
let html = await arrayToTable(t)
|
|
res.send(html)
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`DNS Logger listening at http://localhost:${port}`)
|
|
})
|
|
}
|
|
|
|
|
|
server() |