From 605541d2d099024e8b674a2464b73162230ffc82 Mon Sep 17 00:00:00 2001 From: Karl Date: Sat, 5 Jul 2025 10:36:14 +0100 Subject: [PATCH] fix account add logic --- DNSArray.json | 1 - DNSArray_old.json | 6 ++++- lib/checker.js | 5 ++-- lib/gotRequest.js | 27 --------------------- lib/makeRequest.js | 56 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- routes/getStreams.js | 11 ++++++--- 7 files changed, 73 insertions(+), 35 deletions(-) delete mode 100644 lib/gotRequest.js create mode 100644 lib/makeRequest.js diff --git a/DNSArray.json b/DNSArray.json index 42df233..a545ec5 100644 --- a/DNSArray.json +++ b/DNSArray.json @@ -1,5 +1,4 @@ [ "http://apppanel.co.uk/panel/capo/smarters/api//home.php?action=dns", - "http://panelhost.xyz/cli3nts/Funky/Smarters/api/home.php?action=dns", "https://shadowappz.win/1/kuga/smarters405/api/dns.php" ] \ No newline at end of file diff --git a/DNSArray_old.json b/DNSArray_old.json index 4e5df71..bf286bc 100644 --- a/DNSArray_old.json +++ b/DNSArray_old.json @@ -1,5 +1,9 @@ [ "http://webservgroup.xyz/smarters4567891/api/home.php?action=dns", "http://panelhost.xyz/cli3nts/Funky/Smarters/api/home.php?action=dns", - "http://panelhost.xyz/cli3nts/smartersv3/funky/api/home.php?action=dns" + "http://panelhost.xyz/cli3nts/smartersv3/funky/api/home.php?action=dns", + "http://panelhost.xyz/cli3nts/Funky/Smarters/api/home.php?action=dns", + "http://apppanel.co.uk/panel/capo/smarters/api//home.php?action=dns" + + ] \ No newline at end of file diff --git a/lib/checker.js b/lib/checker.js index 95feb4a..d2411d5 100644 --- a/lib/checker.js +++ b/lib/checker.js @@ -183,7 +183,7 @@ async function accountChecker(accountData, urlList) { try { let response = await inst.get(url, axiosOptions) if (response.data.user_info.auth) { - addNewAccount(accountData, data, url) + addNewAccount(accountData, response.data, url) console.log('New Account Added') syncApache() return true @@ -233,4 +233,5 @@ module.exports = { singleAccountCheck, } -// singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" }) \ No newline at end of file +// singleAccountCheck({ "username": "Karl0ss01", "password": "YqQjYH9Nzw", "userId": 1, "stream": "Badger" }) +// singleAccountCheck({ "username": "Chris0207B", "password": "nfAf53tR4w", "userId": 1, "stream": "Bonsai" }) \ No newline at end of file diff --git a/lib/gotRequest.js b/lib/gotRequest.js deleted file mode 100644 index 5fab48e..0000000 --- a/lib/gotRequest.js +++ /dev/null @@ -1,27 +0,0 @@ -const got = require('got') - -const gotRequest = async (url) => { - let returnResponse = {}; - let options = { - timeout: 2000 - } - return new Promise(async (resolve, reject) => { - 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); - } - }); - - resolve(returnResponse); - }) -}; - -module.exports = { - gotRequest -} \ No newline at end of file diff --git a/lib/makeRequest.js b/lib/makeRequest.js new file mode 100644 index 0000000..bd8bf48 --- /dev/null +++ b/lib/makeRequest.js @@ -0,0 +1,56 @@ +const http = require('http'); +const https = require('https'); + +const makeRequest = async (url) => { + return new Promise((resolve) => { + const client = url.startsWith('https://') ? https : http; + + const req = client.get(url, (res) => { + let data = ''; + + res.on('data', (chunk) => { + data += chunk; + }); + + res.on('end', () => { + let parsed = data; + + try { + if (typeof data === 'string' && data.trim().startsWith('{')) { + parsed = JSON.parse(data); + } + } catch (e) { + console.warn('Warning: JSON parse failed'); + } + + resolve({ + statusCode: res.statusCode, + headers: res.headers, + body: parsed + }); + }); + }); + + req.on('error', (err) => { + console.error('Request failed:', err.message); + resolve({ + statusCode: 500, + body: null, + error: err.message + }); + }); + + req.setTimeout(2000, () => { + req.abort(); + resolve({ + statusCode: 408, + body: null, + error: 'Request timeout' + }); + }); + }); +}; + +module.exports = { + makeRequest +}; diff --git a/package.json b/package.json index 7f52800..3cf5083 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-backend", - "version": "1.0.0", + "version": "1.0.1", "private": true, "scripts": { "start": "node ./bin/www" diff --git a/routes/getStreams.js b/routes/getStreams.js index ed75129..f2bdb89 100644 --- a/routes/getStreams.js +++ b/routes/getStreams.js @@ -5,7 +5,7 @@ const fs = require('fs'); let DNSArray = require('../DNSArray.json') const otherURLs = require('../otherURLs.json') -const { gotRequest } = require('../lib/gotRequest') +const { makeRequest } = require('../lib/makeRequest') function splitToArray(DNS) { @@ -18,7 +18,7 @@ async function getStreamsNew() { let jointArray = [] for (let index = 0; index < DNSArray.length; index++) { const url = DNSArray[index]; - requestData = await gotRequest(url) + requestData = await makeRequest(url) let DNSList = requestData.body if (typeof DNSList === 'string' || DNSList instanceof String) { try { @@ -29,7 +29,12 @@ async function getStreamsNew() { return jointArray } } - DNSList = splitToArray(DNSList.su) + try { + DNSList = splitToArray(DNSList.su) + } catch (error) { + DNSList = splitToArray(DNSList.fu) + } + DNSList.forEach(url => { jointArray.push(url) });