From e97e8d4462d26fd8273e2daaee28bdf31e2b8ddd Mon Sep 17 00:00:00 2001 From: Karl Date: Fri, 19 Nov 2021 13:12:48 +0000 Subject: [PATCH] working but slow new way --- lib/checker.js | 117 ++++++++++++++++++++++++++++++++++++++++--------- lib/getUser.js | 14 ++++++ 2 files changed, 110 insertions(+), 21 deletions(-) diff --git a/lib/checker.js b/lib/checker.js index 3df0917..a38b2d2 100644 --- a/lib/checker.js +++ b/lib/checker.js @@ -1,7 +1,7 @@ const { getStreamsNew } = require('../routes/getStreams') const { updateStreamData } = require('./updateStreams') const { decryptPassword } = require('./password') -const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts } = require('./getUser') +const { getUserAccountsCheck, getAllUniqueAccounts, getAllUserAccounts, getUserUniqueAccounts } = require('./getUser') const { storeAccountToDB } = require('../lib/Accounts') const { syncApache } = require('./apache_functions') @@ -93,30 +93,104 @@ async function addNewAccount(userAccount, data, url) { async function urlChecker(userAccounts, urlList) { let ip = await inst.get('http://api.ipify.org') console.log(ip.data); - await Promise.all(urlList.map(async (url) => { + + // for (let index = 0; index < userAccounts.length; index++) { + // const userAccount = userAccounts[index]; + // console.log('account ' + index+1 + ' of ' + userAccounts.length) + // for (let index2 = 0; index2 < userAccount.urls.length; index2++) { + // const url = userAccount.urls[index2]; + // console.log('url ' + index2+1 + ' of ' + userAccount.urls.length) + // // console.log(url) + // try { + // let response = await inst.get(url, axiosOptions) + // if (response.data.user_info.auth) { + // updateAccounts(userAccounts, response.data, url) + // console.log(url) + // console.log('New Account Added') + // // syncApache() + // // return true + // continue + // } + // } catch (error) { + // try { + // if (error.response.status == 403) { + // let response2 = await axios.get(url, axiosOptions) + // if (response2.data.user_info.auth) { + // try { + // await updateAccounts(userAccounts, response2.data, url) + // console.log('URL updated') + // continue + // } catch (error) { + // continue + // } + // } + // } + // } catch (error) { + // continue + // } + // } + // } + // } + // } + + for (let index = 0; index < urlList.length; index++) { + const url = urlList[index]; + console.log(index + 1 + ' of ' + urlList.length + ' urls checked') try { - let response - url - response = await inst.get(url, axiosOptions) - if (response.status == 200 && response.data !== "") { - try { - let data = response.data - if (data.user_info.auth) { - console.log('.') - updateAccounts(userAccounts, data, url) - return true - } - } catch { - } + let response = await inst.get(url, axiosOptions) + if (response.data.user_info.auth) { + updateAccounts(userAccounts, response.data, url) + console.log('URL updated') + // syncApache() + // return true + continue + } + } catch (error) { + try { + if (error.response.status == 403) { + let response2 = await axios.get(url, axiosOptions) + if (response2.data.user_info.auth) { + try { + await updateAccounts(userAccounts, response2.data, url) + console.log('URL updated') + continue + } catch (error) { + continue + } + } + } + } catch (error) { + continue } - } catch { } - })).then((values) => { - endresponse = values - }); - return endresponse + } + return false } +// await Promise.all(urlList.map(async (url) => { +// try { +// let response +// url +// response = await inst.get(url, axiosOptions) +// if (response.status == 200 && response.data !== "") { +// try { +// let data = response.data +// if (data.user_info.auth) { +// console.log('.') +// updateAccounts(userAccounts, data, url) +// return true +// } +// } catch { +// } +// } +// } catch { +// } +// })).then((values) => { +// endresponse = values +// }); +// return endresponse +// } + // async function allUserCheck() { // let start = Date.now() @@ -205,7 +279,7 @@ async function userCheck(accountData) { let start = Date.now() console.log(start) streamURLS = await getStreamsNew() - let userAccounts = await getUserAccountsCheck(accountData.userId) + let userAccounts = await getUserUniqueAccounts(accountData.userId) userAccounts = userAccounts.map(user => { user.userId = accountData.userId @@ -223,6 +297,7 @@ async function userCheck(accountData) { urlList.push(await buildURL(streamURL, userAccount.username, userAccount.passwordDecryped)) } } + urlList = urlList.filter(function (e) { return !e.includes('stormtv') && !e.includes('megaott') }) values = await urlChecker(userAccounts, urlList) diff --git a/lib/getUser.js b/lib/getUser.js index 201a19c..a07edab 100644 --- a/lib/getUser.js +++ b/lib/getUser.js @@ -67,6 +67,19 @@ function getAllUniqueAccounts() { } } +function getUserUniqueAccounts(userid) { + let data = sql.query(`SELECT DISTINCT(userAccounts.stream), userAccounts.username, userAccounts.password, userAccounts.stream , userAccounts.streamURL FROM userAccounts + WHERE userAccounts.expiaryDate != '0' AND + userAccounts.userId = ${userid} + GROUP BY userAccounts.stream +ORDER BY userAccounts.stream ASC;`) + if (data.length == 0) { + return 'User Not Found' + } else { + return data + } +} + function getUserId(user) { let data = sql.query(`SELECT id FROM users WHERE userName = '${user}'`) // console.log(data) @@ -83,6 +96,7 @@ module.exports = { getAllUserAccounts, getUserId, getUserAccountsCheck, + getUserUniqueAccounts, getAllUniqueAccounts }