var express = require('express'); var router = express.Router(); const fs = require('fs'); let DNSArray = require('../lib/DNSArray.json') const otherURLs = require('../lib/otherURLs.json') const { gotRequest } = require('../lib/gotRequest') function splitToArray(DNS) { DNS = DNS.split(',') return DNS } async function getStreamsNew() { let requestData let jointArray = [] for (let index = 0; index < DNSArray.length; index++) { const url = DNSArray[index]; requestData = await gotRequest(url) let DNSList = requestData.body if (typeof DNSList === 'string' || DNSList instanceof String) { try { DNSList = JSON.parse(DNSList) } catch (error) { jointArray.unshift(...otherURLs.using) jointArray = [...new Set(jointArray)] return jointArray } } DNSList = splitToArray(DNSList.su) DNSList.forEach(url => { jointArray.push(url) }); } jointArray.unshift(...otherURLs) jointArray = [...new Set(jointArray)] return jointArray } /* GET users listing. */ router.get('/', async function (req, res, next) { let fullStreamArray = await main() res.send(fullStreamArray) }); module.exports = { router, getStreamsNew }